blob: 959f5b731193bc42904ba7a469babdf4221fb206 [file] [log] [blame]
Parker Schuhe9a549a2019-02-24 16:29:22 -08001#ifndef _Y2019_VISION_CONSTANTS_H_
2#define _Y2019_VISION_CONSTANTS_H_
3
Parker Schuhe9a549a2019-02-24 16:29:22 -08004#include <array>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07005#include <cmath>
James Kuszmaulef420da2023-12-27 12:02:15 -08006#include <cstdint>
Parker Schuhe9a549a2019-02-24 16:29:22 -08007#include <string>
8
9namespace y2019 {
10namespace vision {
11
12// Position of the idealized camera in 3d space.
13struct CameraGeometry {
Parker Schuha4e52fb2019-02-24 18:18:15 -080014 static constexpr size_t kNumParams = 4;
Parker Schuhe9a549a2019-02-24 16:29:22 -080015 // In Meters from floor under imu center.
Austin Schuha2464b22019-03-08 19:42:11 -080016 ::std::array<double, 3> location{{0.0, 0.0, 0.0}};
Parker Schuhe9a549a2019-02-24 16:29:22 -080017 double heading = 0.0;
18
19 void set(double *data) {
Austin Schuha2464b22019-03-08 19:42:11 -080020 data[0] = location[0];
21 data[1] = location[1];
22 data[2] = location[2];
23 data[3] = heading;
Parker Schuhe9a549a2019-02-24 16:29:22 -080024 }
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 Schuha4e52fb2019-02-24 18:18:15 -080033
Austin Schuh813d8d72019-03-03 21:11:53 -080034 void Dump(std::basic_ostream<char> *o) const;
Parker Schuhe9a549a2019-02-24 16:29:22 -080035};
36
37struct 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 Schuh813d8d72019-03-03 21:11:53 -080057 void Dump(std::basic_ostream<char> *o) const;
Parker Schuhe9a549a2019-02-24 16:29:22 -080058};
59
60// Metadata about the calibration results (Should be good enough to reproduce).
61struct DatasetInfo {
62 int camera_id;
63 // In meters from IMU start.
Austin Schuh4d6e9bd2019-03-08 19:54:17 -080064 ::std::array<double, 2> to_tape_measure_start;
Parker Schuhe9a549a2019-02-24 16:29:22 -080065 // In meters,
Austin Schuh4d6e9bd2019-03-08 19:54:17 -080066 ::std::array<double, 2> tape_measure_direction;
Parker Schuhe9a549a2019-02-24 16:29:22 -080067 // This will multiply tape_measure_direction and thus has no units.
68 double beginning_tape_measure_reading;
69 const char *filename_prefix;
Parker Schuha4e52fb2019-02-24 18:18:15 -080070 int num_images;
71
Austin Schuh813d8d72019-03-03 21:11:53 -080072 void Dump(std::basic_ostream<char> *o) const;
Parker Schuhe9a549a2019-02-24 16:29:22 -080073};
74
75struct CameraCalibration {
76 IntrinsicParams intrinsics;
77 CameraGeometry geometry;
78 DatasetInfo dataset;
79};
80
81const CameraCalibration *GetCamera(int camera_id);
82
James Kuszmaule2c71ea2019-03-04 08:14:21 -080083// Serial number of the teensy for each robot.
84constexpr uint32_t CodeBotTeensyId() { return 0xffff322e; }
Austin Schuhc06c80c2019-03-09 13:57:49 -080085constexpr uint32_t PracticeBotTeensyId() { return 0xffff3215; }
Austin Schuh48d3a962019-03-17 18:12:32 -070086constexpr uint32_t CompBotTeensyId() { return 0xffff3210; }
James Kuszmaule2c71ea2019-03-04 08:14:21 -080087
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 Schuh4d6e9bd2019-03-08 19:54:17 -080091inline ::std::array<int, 5> CameraSerialNumbers(uint32_t processor_id) {
James Kuszmaule2c71ea2019-03-04 08:14:21 -080092 switch (processor_id) {
93 case CodeBotTeensyId():
94 return {{0, 0, 0, 16, 19}};
Austin Schuhc06c80c2019-03-09 13:57:49 -080095 case PracticeBotTeensyId():
96 return {{14, 15, 18, 17, 1}};
Austin Schuh48d3a962019-03-17 18:12:32 -070097 case CompBotTeensyId():
98 return {{6, 7, 8, 9, 10}};
James Kuszmaule2c71ea2019-03-04 08:14:21 -080099 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.
107void DumpCameraConstants(const char *fname, int camera_id,
108 const CameraCalibration &value);
Parker Schuha4e52fb2019-02-24 18:18:15 -0800109
Parker Schuhe9a549a2019-02-24 16:29:22 -0800110} // namespace vision
111} // namespace y2019
112
113#endif // _Y2019_VISION_CONSTANTS_H_