blob: 3f07f877567a485f30d73b94180e1a57a0175966 [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.
15 std::array<double, 3> location{{0, 0, 0}};
16 double heading = 0.0;
17
18 void set(double *data) {
19 location[0] = data[0];
20 location[1] = data[1];
21 location[2] = data[2];
22 heading = data[3];
23 }
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.
63 std::array<double, 2> to_tape_measure_start;
64 // In meters,
65 std::array<double, 2> tape_measure_direction;
66 // 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; }
84
85// Get the IDs of the cameras in each port for a particular teensy board.
86// inlined so that we don't have to deal with including it in the autogenerated
87// constants.cc.
88inline std::array<int, 5> CameraSerialNumbers(uint32_t processor_id) {
89 switch (processor_id) {
90 case CodeBotTeensyId():
91 return {{0, 0, 0, 16, 19}};
92 default:
93 return {{0, 0, 0, 0, 0}};
94 }
95}
96
97// Rewrites constants.cc, adding camera calibration constants for the camera_id
98// specified. If camera_id is less than zero, just rewrites the file without
99// changing anything.
100void DumpCameraConstants(const char *fname, int camera_id,
101 const CameraCalibration &value);
Parker Schuha4e52fb2019-02-24 18:18:15 -0800102
Parker Schuhe9a549a2019-02-24 16:29:22 -0800103} // namespace vision
104} // namespace y2019
105
106#endif // _Y2019_VISION_CONSTANTS_H_