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/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()));
}