blob: faa16e15e87d7e7f28d52bf778e0c4ac65d16906 [file] [log] [blame]
Parker Schuhe9a549a2019-02-24 16:29:22 -08001#ifndef _Y2019_VISION_CONSTANTS_H_
2#define _Y2019_VISION_CONSTANTS_H_
3
4#include <math.h>
5#include <array>
6#include <string>
7
8namespace y2019 {
9namespace vision {
10
11// Position of the idealized camera in 3d space.
12struct CameraGeometry {
Parker Schuha4e52fb2019-02-24 18:18:15 -080013 static constexpr size_t kNumParams = 4;
Parker Schuhe9a549a2019-02-24 16:29:22 -080014 // In Meters from floor under imu center.
Austin Schuha2464b22019-03-08 19:42:11 -080015 ::std::array<double, 3> location{{0.0, 0.0, 0.0}};
Parker Schuhe9a549a2019-02-24 16:29:22 -080016 double heading = 0.0;
17
18 void set(double *data) {
Austin Schuha2464b22019-03-08 19:42:11 -080019 data[0] = location[0];
20 data[1] = location[1];
21 data[2] = location[2];
22 data[3] = heading;
Parker Schuhe9a549a2019-02-24 16:29:22 -080023 }
24 static CameraGeometry get(const double *data) {
25 CameraGeometry out;
26 out.location[0] = data[0];
27 out.location[1] = data[1];
28 out.location[2] = data[2];
29 out.heading = data[3];
30 return out;
31 }
Parker Schuha4e52fb2019-02-24 18:18:15 -080032
Austin Schuh813d8d72019-03-03 21:11:53 -080033 void Dump(std::basic_ostream<char> *o) const;
Parker Schuhe9a549a2019-02-24 16:29:22 -080034};
35
36struct IntrinsicParams {
37 static constexpr size_t kNumParams = 3;
38
39 double mount_angle = 0.819433 / 180.0 * M_PI; // 9.32615 / 180.0 * M_PI;
40 double focal_length = 666.763; // 734.328;
41 // This is a final rotation where the camera isn't straight.
42 double barrel_mount = 2.72086 / 180.0 * M_PI;
43
44 void set(double *data) {
45 data[0] = mount_angle;
46 data[1] = focal_length;
47 data[2] = barrel_mount;
48 }
49 static IntrinsicParams get(const double *data) {
50 IntrinsicParams out;
51 out.mount_angle = data[0];
52 out.focal_length = data[1];
53 out.barrel_mount = data[2];
54 return out;
55 }
Austin Schuh813d8d72019-03-03 21:11:53 -080056 void Dump(std::basic_ostream<char> *o) const;
Parker Schuhe9a549a2019-02-24 16:29:22 -080057};
58
59// Metadata about the calibration results (Should be good enough to reproduce).
60struct DatasetInfo {
61 int camera_id;
62 // In meters from IMU start.
Austin Schuh4d6e9bd2019-03-08 19:54:17 -080063 ::std::array<double, 2> to_tape_measure_start;
Parker Schuhe9a549a2019-02-24 16:29:22 -080064 // In meters,
Austin Schuh4d6e9bd2019-03-08 19:54:17 -080065 ::std::array<double, 2> tape_measure_direction;
Parker Schuhe9a549a2019-02-24 16:29:22 -080066 // This will multiply tape_measure_direction and thus has no units.
67 double beginning_tape_measure_reading;
68 const char *filename_prefix;
Parker Schuha4e52fb2019-02-24 18:18:15 -080069 int num_images;
70
Austin Schuh813d8d72019-03-03 21:11:53 -080071 void Dump(std::basic_ostream<char> *o) const;
Parker Schuhe9a549a2019-02-24 16:29:22 -080072};
73
74struct CameraCalibration {
75 IntrinsicParams intrinsics;
76 CameraGeometry geometry;
77 DatasetInfo dataset;
78};
79
80const CameraCalibration *GetCamera(int camera_id);
81
James Kuszmaule2c71ea2019-03-04 08:14:21 -080082// Serial number of the teensy for each robot.
83constexpr uint32_t CodeBotTeensyId() { return 0xffff322e; }
Austin Schuhc06c80c2019-03-09 13:57:49 -080084constexpr uint32_t PracticeBotTeensyId() { return 0xffff3215; }
James Kuszmaule2c71ea2019-03-04 08:14:21 -080085
86// Get the IDs of the cameras in each port for a particular teensy board.
87// inlined so that we don't have to deal with including it in the autogenerated
88// constants.cc.
Austin Schuh4d6e9bd2019-03-08 19:54:17 -080089inline ::std::array<int, 5> CameraSerialNumbers(uint32_t processor_id) {
James Kuszmaule2c71ea2019-03-04 08:14:21 -080090 switch (processor_id) {
91 case CodeBotTeensyId():
92 return {{0, 0, 0, 16, 19}};
Austin Schuhc06c80c2019-03-09 13:57:49 -080093 case PracticeBotTeensyId():
94 return {{14, 15, 18, 17, 1}};
James Kuszmaule2c71ea2019-03-04 08:14:21 -080095 default:
96 return {{0, 0, 0, 0, 0}};
97 }
98}
99
100// Rewrites constants.cc, adding camera calibration constants for the camera_id
101// specified. If camera_id is less than zero, just rewrites the file without
102// changing anything.
103void DumpCameraConstants(const char *fname, int camera_id,
104 const CameraCalibration &value);
Parker Schuha4e52fb2019-02-24 18:18:15 -0800105
Parker Schuhe9a549a2019-02-24 16:29:22 -0800106} // namespace vision
107} // namespace y2019
108
109#endif // _Y2019_VISION_CONSTANTS_H_