Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 1 | #ifndef _Y2019_VISION_CONSTANTS_H_ |
| 2 | #define _Y2019_VISION_CONSTANTS_H_ |
| 3 | |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 4 | #include <array> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 5 | #include <cmath> |
James Kuszmaul | ef420da | 2023-12-27 12:02:15 -0800 | [diff] [blame^] | 6 | #include <cstdint> |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 7 | #include <string> |
| 8 | |
| 9 | namespace y2019 { |
| 10 | namespace vision { |
| 11 | |
| 12 | // Position of the idealized camera in 3d space. |
| 13 | struct CameraGeometry { |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 14 | static constexpr size_t kNumParams = 4; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 15 | // In Meters from floor under imu center. |
Austin Schuh | a2464b2 | 2019-03-08 19:42:11 -0800 | [diff] [blame] | 16 | ::std::array<double, 3> location{{0.0, 0.0, 0.0}}; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 17 | double heading = 0.0; |
| 18 | |
| 19 | void set(double *data) { |
Austin Schuh | a2464b2 | 2019-03-08 19:42:11 -0800 | [diff] [blame] | 20 | data[0] = location[0]; |
| 21 | data[1] = location[1]; |
| 22 | data[2] = location[2]; |
| 23 | data[3] = heading; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 24 | } |
| 25 | static CameraGeometry get(const double *data) { |
| 26 | CameraGeometry out; |
| 27 | out.location[0] = data[0]; |
| 28 | out.location[1] = data[1]; |
| 29 | out.location[2] = data[2]; |
| 30 | out.heading = data[3]; |
| 31 | return out; |
| 32 | } |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 33 | |
Austin Schuh | 813d8d7 | 2019-03-03 21:11:53 -0800 | [diff] [blame] | 34 | void Dump(std::basic_ostream<char> *o) const; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | struct IntrinsicParams { |
| 38 | static constexpr size_t kNumParams = 3; |
| 39 | |
| 40 | double mount_angle = 0.819433 / 180.0 * M_PI; // 9.32615 / 180.0 * M_PI; |
| 41 | double focal_length = 666.763; // 734.328; |
| 42 | // This is a final rotation where the camera isn't straight. |
| 43 | double barrel_mount = 2.72086 / 180.0 * M_PI; |
| 44 | |
| 45 | void set(double *data) { |
| 46 | data[0] = mount_angle; |
| 47 | data[1] = focal_length; |
| 48 | data[2] = barrel_mount; |
| 49 | } |
| 50 | static IntrinsicParams get(const double *data) { |
| 51 | IntrinsicParams out; |
| 52 | out.mount_angle = data[0]; |
| 53 | out.focal_length = data[1]; |
| 54 | out.barrel_mount = data[2]; |
| 55 | return out; |
| 56 | } |
Austin Schuh | 813d8d7 | 2019-03-03 21:11:53 -0800 | [diff] [blame] | 57 | void Dump(std::basic_ostream<char> *o) const; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | // Metadata about the calibration results (Should be good enough to reproduce). |
| 61 | struct DatasetInfo { |
| 62 | int camera_id; |
| 63 | // In meters from IMU start. |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 64 | ::std::array<double, 2> to_tape_measure_start; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 65 | // In meters, |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 66 | ::std::array<double, 2> tape_measure_direction; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 67 | // This will multiply tape_measure_direction and thus has no units. |
| 68 | double beginning_tape_measure_reading; |
| 69 | const char *filename_prefix; |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 70 | int num_images; |
| 71 | |
Austin Schuh | 813d8d7 | 2019-03-03 21:11:53 -0800 | [diff] [blame] | 72 | void Dump(std::basic_ostream<char> *o) const; |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct CameraCalibration { |
| 76 | IntrinsicParams intrinsics; |
| 77 | CameraGeometry geometry; |
| 78 | DatasetInfo dataset; |
| 79 | }; |
| 80 | |
| 81 | const CameraCalibration *GetCamera(int camera_id); |
| 82 | |
James Kuszmaul | e2c71ea | 2019-03-04 08:14:21 -0800 | [diff] [blame] | 83 | // Serial number of the teensy for each robot. |
| 84 | constexpr uint32_t CodeBotTeensyId() { return 0xffff322e; } |
Austin Schuh | c06c80c | 2019-03-09 13:57:49 -0800 | [diff] [blame] | 85 | constexpr uint32_t PracticeBotTeensyId() { return 0xffff3215; } |
Austin Schuh | 48d3a96 | 2019-03-17 18:12:32 -0700 | [diff] [blame] | 86 | constexpr uint32_t CompBotTeensyId() { return 0xffff3210; } |
James Kuszmaul | e2c71ea | 2019-03-04 08:14:21 -0800 | [diff] [blame] | 87 | |
| 88 | // Get the IDs of the cameras in each port for a particular teensy board. |
| 89 | // inlined so that we don't have to deal with including it in the autogenerated |
| 90 | // constants.cc. |
Austin Schuh | 4d6e9bd | 2019-03-08 19:54:17 -0800 | [diff] [blame] | 91 | inline ::std::array<int, 5> CameraSerialNumbers(uint32_t processor_id) { |
James Kuszmaul | e2c71ea | 2019-03-04 08:14:21 -0800 | [diff] [blame] | 92 | switch (processor_id) { |
| 93 | case CodeBotTeensyId(): |
| 94 | return {{0, 0, 0, 16, 19}}; |
Austin Schuh | c06c80c | 2019-03-09 13:57:49 -0800 | [diff] [blame] | 95 | case PracticeBotTeensyId(): |
| 96 | return {{14, 15, 18, 17, 1}}; |
Austin Schuh | 48d3a96 | 2019-03-17 18:12:32 -0700 | [diff] [blame] | 97 | case CompBotTeensyId(): |
| 98 | return {{6, 7, 8, 9, 10}}; |
James Kuszmaul | e2c71ea | 2019-03-04 08:14:21 -0800 | [diff] [blame] | 99 | default: |
| 100 | return {{0, 0, 0, 0, 0}}; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Rewrites constants.cc, adding camera calibration constants for the camera_id |
| 105 | // specified. If camera_id is less than zero, just rewrites the file without |
| 106 | // changing anything. |
| 107 | void DumpCameraConstants(const char *fname, int camera_id, |
| 108 | const CameraCalibration &value); |
Parker Schuh | a4e52fb | 2019-02-24 18:18:15 -0800 | [diff] [blame] | 109 | |
Parker Schuh | e9a549a | 2019-02-24 16:29:22 -0800 | [diff] [blame] | 110 | } // namespace vision |
| 111 | } // namespace y2019 |
| 112 | |
| 113 | #endif // _Y2019_VISION_CONSTANTS_H_ |