Adapt game piece detector for new task
The new task is to detect cones in the end defector, this change
adds the new model for this task and changes what we do with
the output of the model. It also adds a script so that game piece
detector starts correctly.
Signed-off-by: Filip Kujawa <filip.j.kujawa@gmail.com>
Change-Id: I53b8d057398472e680e49b2f55b3438c370d00eb
diff --git a/WORKSPACE b/WORKSPACE
index 67c23a9..376b91d 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -583,8 +583,8 @@
http_file(
name = "game_pieces_edgetpu_model",
downloaded_file_path = "edgetpu_model.tflite",
- sha256 = "af1cf86515d03690389845d015895aff734ab890141ca792813c1b5754900b4d",
- urls = ["https://www.frc971.org/Build-Dependencies/models/2023/model_edgetpu_2023.04.09.tflite"],
+ sha256 = "3d37f34805d017153064076519aaf4b532658a3b8f2518bce8787f27a5c3064c",
+ urls = ["https://www.frc971.org/Build-Dependencies/models/2023/model_edgetpu_2023.04.09_3.tflite"],
)
# Recompressed from libusb-1.0.21.7z.
diff --git a/y2023/BUILD b/y2023/BUILD
index 5448f4c..c3f7c33 100644
--- a/y2023/BUILD
+++ b/y2023/BUILD
@@ -70,6 +70,7 @@
":aos_config",
"//frc971/rockpi:rockpi_config.json",
"//y2023/constants:constants.json",
+ "//y2023/vision:game_pieces_detector_starter",
"//y2023/vision:image_streamer_start",
"//y2023/www:www_files",
"@game_pieces_edgetpu_model//file",
diff --git a/y2023/vision/BUILD b/y2023/vision/BUILD
index 1a0b399..eda123e 100644
--- a/y2023/vision/BUILD
+++ b/y2023/vision/BUILD
@@ -292,3 +292,9 @@
],
}),
)
+
+filegroup(
+ name = "game_pieces_detector_starter",
+ srcs = ["game_pieces_detector_starter.sh"],
+ visibility = ["//visibility:public"],
+)
diff --git a/y2023/vision/game_pieces.cc b/y2023/vision/game_pieces.cc
index bf6a855..8a0621d 100644
--- a/y2023/vision/game_pieces.cc
+++ b/y2023/vision/game_pieces.cc
@@ -7,20 +7,6 @@
#include "frc971/vision/vision_generated.h"
#include "y2023/vision/yolov5.h"
-// The best_x and best_y are pixel (x, y) cordinates. The 'best'
-// game piece is picked on proximity to the specified cordinates.
-// The cordinate should represent where we want to intake a game piece.
-// (0, 360) was chosen without any testing, just a cordinate that
-// seemed reasonable.
-
-DEFINE_uint32(
- best_x, 0,
- "The 'best' game piece is picked based on how close it is to this x value");
-
-DEFINE_uint32(
- best_y, 360,
- "The 'best' game piece is picked based on how close it is to this y value");
-
namespace y2023 {
namespace vision {
using aos::monotonic_clock;
@@ -56,9 +42,6 @@
std::vector<flatbuffers::Offset<GamePiece>> game_pieces_offsets;
- float lowest_distance = std::numeric_limits<float>::max();
- int best_distance_index = 0;
-
for (size_t i = 0; i < detections.size(); i++) {
auto box_builder = builder.MakeBuilder<Box>();
box_builder.add_h(detections[i].box.height);
@@ -70,47 +53,22 @@
auto game_piece_builder = builder.MakeBuilder<GamePiece>();
switch (detections[i].class_id) {
case 0:
- game_piece_builder.add_piece_class(Class::CONE_DOWN);
- break;
- case 1:
- game_piece_builder.add_piece_class(Class::CONE_UP);
- break;
- case 2:
- game_piece_builder.add_piece_class(Class::CUBE);
+ game_piece_builder.add_piece_class(ConeClass::CONE);
break;
default:
- game_piece_builder.add_piece_class(Class::CONE_DOWN);
+ // Should never happen.
+ game_piece_builder.add_piece_class(ConeClass::NONE);
}
game_piece_builder.add_box(box_offset);
game_piece_builder.add_confidence(detections[i].confidence);
auto game_piece = game_piece_builder.Finish();
game_pieces_offsets.push_back(game_piece);
-
- // Center x and y values.
- // Inference returns the top left corner of the bounding box
- // but we want the center of the box for this.
-
- const int center_x = detections[i].box.x + detections[i].box.width / 2;
- const int center_y = detections[i].box.y + detections[i].box.height / 2;
-
- // Find difference between target x, y and the x, y
- // of the bounding box using Euclidean distance.
-
- const int dx = FLAGS_best_x - center_x;
- const int dy = FLAGS_best_y - center_y;
- const float distance = std::sqrt(dx * dx + dy * dy);
-
- if (distance < lowest_distance) {
- lowest_distance = distance;
- best_distance_index = i;
- }
};
auto game_pieces_vector = builder.fbb()->CreateVector(game_pieces_offsets);
auto game_pieces_builder = builder.MakeBuilder<GamePieces>();
game_pieces_builder.add_game_pieces(game_pieces_vector);
- game_pieces_builder.add_best_piece(best_distance_index);
builder.CheckOk(builder.Send(game_pieces_builder.Finish()));
}
diff --git a/y2023/vision/game_pieces.fbs b/y2023/vision/game_pieces.fbs
index 89f7505..1792ece 100644
--- a/y2023/vision/game_pieces.fbs
+++ b/y2023/vision/game_pieces.fbs
@@ -1,6 +1,6 @@
namespace y2023.vision;
-// Object class.
+// Not used by ml anymore.
enum Class : byte {
NONE = 0,
CONE_UP = 1,
@@ -8,6 +8,11 @@
CONE_DOWN = 3,
}
+enum ConeClass : byte {
+ NONE = 0,
+ CONE = 1,
+}
+
// Bounding box dimensions and position.
// X and Y represent the top left of the bounding box.
table Box {
@@ -18,14 +23,13 @@
}
table GamePiece {
- piece_class:Class (id: 0);
+ piece_class:ConeClass (id: 0);
box:Box (id:1);
confidence:float (id:2);
}
table GamePieces {
game_pieces:[GamePiece] (id: 0);
- best_piece:uint (id: 1); // Index of the "best piece".
}
root_type GamePieces;
diff --git a/y2023/vision/game_pieces_detector_starter.sh b/y2023/vision/game_pieces_detector_starter.sh
new file mode 100755
index 0000000..36dca97
--- /dev/null
+++ b/y2023/vision/game_pieces_detector_starter.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/pi/bin game_pieces_detector
diff --git a/y2023/y2023_logger.json b/y2023/y2023_logger.json
index 44eb7d0..b0ece47 100644
--- a/y2023/y2023_logger.json
+++ b/y2023/y2023_logger.json
@@ -447,8 +447,9 @@
]
},
{
- "name": "game_piece_detector",
- "executable_name": "game_piece_detector",
+ "name": "game_pieces_detector_starter",
+ "executable_name": "game_pieces_detector_starter.sh",
+ "autostart": true,
"user": "pi",
"nodes": [
"logger"