Yash Maheshwari | e0b25c5 | 2024-05-22 20:23:36 -0700 | [diff] [blame^] | 1 | #include "y2024_swerve/vision/vision_util.h" |
| 2 | |
| 3 | #include "glog/logging.h" |
| 4 | |
| 5 | namespace y2024_swerve::vision { |
| 6 | |
| 7 | // Store a list of ordered cameras as you progress around the robot/box of orins |
| 8 | std::vector<CameraNode> CreateNodeList() { |
| 9 | std::vector<CameraNode> list; |
| 10 | |
| 11 | list.push_back({.node_name = "imu", .camera_number = 0}); |
| 12 | list.push_back({.node_name = "imu", .camera_number = 1}); |
| 13 | list.push_back({.node_name = "orin1", .camera_number = 1}); |
| 14 | list.push_back({.node_name = "orin1", .camera_number = 0}); |
| 15 | |
| 16 | return list; |
| 17 | } |
| 18 | |
| 19 | // From the node_list, create a numbering scheme from 0 to 3 |
| 20 | std::map<std::string, int> CreateOrderingMap( |
| 21 | std::vector<CameraNode> &node_list) { |
| 22 | std::map<std::string, int> map; |
| 23 | |
| 24 | for (uint i = 0; i < node_list.size(); i++) { |
| 25 | map.insert({node_list.at(i).camera_name(), i}); |
| 26 | } |
| 27 | |
| 28 | return map; |
| 29 | } |
| 30 | |
| 31 | const frc971::vision::calibration::CameraCalibration *FindCameraCalibration( |
| 32 | const y2024_swerve::Constants &calibration_data, std::string_view node_name, |
| 33 | int camera_number) { |
| 34 | CHECK(calibration_data.robot()->has_cameras()); |
| 35 | for (const y2024_swerve::CameraConfiguration *candidate : |
| 36 | *calibration_data.robot()->cameras()) { |
| 37 | CHECK(candidate->has_calibration()); |
| 38 | if (candidate->calibration()->node_name()->string_view() != node_name || |
| 39 | candidate->calibration()->camera_number() != camera_number) { |
| 40 | continue; |
| 41 | } |
| 42 | return candidate->calibration(); |
| 43 | } |
| 44 | LOG(FATAL) << ": Failed to find camera calibration for " << node_name |
| 45 | << " and camera number " << camera_number; |
| 46 | } |
| 47 | |
| 48 | } // namespace y2024_swerve::vision |