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