Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 1 | #ifndef FRC971_VISION_EXTRINSICS_CALIBRATION_H_ |
| 2 | #define FRC971_VISION_EXTRINSICS_CALIBRATION_H_ |
| 3 | |
| 4 | #include "Eigen/Dense" |
| 5 | #include "Eigen/Geometry" |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame^] | 6 | |
Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 7 | #include "frc971/vision/calibration_accumulator.h" |
| 8 | |
| 9 | namespace frc971 { |
| 10 | namespace vision { |
| 11 | |
| 12 | struct CalibrationParameters { |
| 13 | Eigen::Quaternion<double> initial_orientation = |
| 14 | Eigen::Quaternion<double>::Identity(); |
Austin Schuh | 2895f4c | 2022-02-26 16:38:46 -0800 | [diff] [blame] | 15 | Eigen::Quaternion<double> pivot_to_camera = |
| 16 | Eigen::Quaternion<double>::Identity(); |
| 17 | Eigen::Quaternion<double> pivot_to_imu = |
Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 18 | Eigen::Quaternion<double>::Identity(); |
| 19 | Eigen::Quaternion<double> board_to_world = |
| 20 | Eigen::Quaternion<double>::Identity(); |
| 21 | |
| 22 | Eigen::Vector3d gyro_bias = Eigen::Vector3d::Zero(); |
| 23 | Eigen::Matrix<double, 6, 1> initial_state = |
| 24 | Eigen::Matrix<double, 6, 1>::Zero(); |
Austin Schuh | 2895f4c | 2022-02-26 16:38:46 -0800 | [diff] [blame] | 25 | Eigen::Matrix<double, 3, 1> pivot_to_camera_translation = |
| 26 | Eigen::Matrix<double, 3, 1>::Zero(); |
| 27 | Eigen::Matrix<double, 3, 1> pivot_to_imu_translation = |
Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 28 | Eigen::Matrix<double, 3, 1>::Zero(); |
| 29 | |
| 30 | double gravity_scalar = 1.0; |
| 31 | Eigen::Matrix<double, 3, 1> accelerometer_bias = |
| 32 | Eigen::Matrix<double, 3, 1>::Zero(); |
Austin Schuh | 2895f4c | 2022-02-26 16:38:46 -0800 | [diff] [blame] | 33 | |
| 34 | bool has_pivot = false; |
Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
James Kuszmaul | 086d019 | 2023-02-11 15:35:03 -0800 | [diff] [blame] | 37 | // Copies an Eigen matrix into a row-major vector of the data. Used for |
| 38 | // converting into the flatbuffer TransformationMatrix type. |
| 39 | std::vector<float> MatrixToVector(const Eigen::Matrix<double, 4, 4> &H); |
| 40 | |
Austin Schuh | 2895f4c | 2022-02-26 16:38:46 -0800 | [diff] [blame] | 41 | // Solves the mounting problem given the calibration data and parameters. The |
| 42 | // parameters are used as the seed to the solver. |
James Kuszmaul | 086d019 | 2023-02-11 15:35:03 -0800 | [diff] [blame] | 43 | // Produces a CameraCalibration flatbuffer which will have the relevant |
| 44 | // extrinsics fields populated, so that it can subsequently be merged with the |
| 45 | // intrinsics portion of the calibration. |
| 46 | aos::FlatbufferDetachedBuffer<calibration::CameraCalibration> Solve( |
| 47 | const CalibrationData &data, CalibrationParameters *calibration_parameters); |
Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 48 | |
Austin Schuh | 2895f4c | 2022-02-26 16:38:46 -0800 | [diff] [blame] | 49 | // Plots the calibrated results to help visualize the fit. |
Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 50 | void Plot(const CalibrationData &data, |
| 51 | const CalibrationParameters &calibration_parameters); |
| 52 | |
Jim Ostrowski | ba2edd1 | 2022-12-03 15:44:37 -0800 | [diff] [blame] | 53 | // Shows the evolution of the calibration over time by visualizing relevant |
| 54 | // coordinate frames in a virtual camera view |
| 55 | void Visualize(const CalibrationData &data, |
| 56 | const CalibrationParameters &calibration_parameters); |
| 57 | |
Austin Schuh | dcb6b36 | 2022-02-25 18:06:21 -0800 | [diff] [blame] | 58 | } // namespace vision |
| 59 | } // namespace frc971 |
| 60 | |
| 61 | #endif // FRC971_VISION_EXTRINSICS_CALIBRATION_H_ |