Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_DRIVETRAIN_SPLINEDRIVETRAIN_H_ |
| 2 | #define FRC971_CONTROL_LOOPS_DRIVETRAIN_SPLINEDRIVETRAIN_H_ |
| 3 | |
Alex Perry | a71badb | 2019-02-06 19:40:41 -0800 | [diff] [blame] | 4 | #include "Eigen/Dense" |
| 5 | |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 6 | #include "frc971/control_loops/drivetrain/distance_spline.h" |
| 7 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 8 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
| 9 | #include "frc971/control_loops/drivetrain/spline.h" |
| 10 | #include "frc971/control_loops/drivetrain/trajectory.h" |
| 11 | |
| 12 | namespace frc971 { |
| 13 | namespace control_loops { |
| 14 | namespace drivetrain { |
| 15 | |
| 16 | class SplineDrivetrain { |
| 17 | public: |
| 18 | SplineDrivetrain(const DrivetrainConfig<double> &dt_config); |
| 19 | |
| 20 | void SetGoal(const ::frc971::control_loops::DrivetrainQueue::Goal &goal); |
| 21 | |
Alex Perry | e32eabc | 2019-02-08 19:51:19 -0800 | [diff] [blame^] | 22 | void Update(bool enabled, const ::Eigen::Matrix<double, 5, 1> &state); |
Alex Perry | a71badb | 2019-02-06 19:40:41 -0800 | [diff] [blame] | 23 | |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 24 | void SetOutput( |
| 25 | ::frc971::control_loops::DrivetrainQueue::Output *output); |
| 26 | // TODO(alex): What status do we need? |
| 27 | void PopulateStatus( |
| 28 | ::frc971::control_loops::DrivetrainQueue::Status *status) const; |
| 29 | private: |
Alex Perry | e32eabc | 2019-02-08 19:51:19 -0800 | [diff] [blame^] | 30 | void ScaleCapU(Eigen::Matrix<double, 2, 1> *U); |
| 31 | |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 32 | const DrivetrainConfig<double> dt_config_; |
| 33 | |
| 34 | uint32_t current_spline_handle_; // Current spline told to excecute. |
| 35 | uint32_t current_spline_idx_; // Current excecuting spline. |
| 36 | ::std::unique_ptr<DistanceSpline> distance_spline_; |
| 37 | ::std::unique_ptr<Trajectory> current_trajectory_; |
Alex Perry | a71badb | 2019-02-06 19:40:41 -0800 | [diff] [blame] | 38 | ::Eigen::Matrix<double, 3, 1> current_xva_, next_xva_; |
| 39 | ::Eigen::Matrix<double, 2, 1> current_state_; |
Alex Perry | e32eabc | 2019-02-08 19:51:19 -0800 | [diff] [blame^] | 40 | ::Eigen::Matrix<double, 2, 1> next_U_; |
| 41 | ::Eigen::Matrix<double, 2, 1> uncapped_U_; |
| 42 | |
| 43 | bool enable_; |
| 44 | |
| 45 | // TODO(alex): pull this out of dt_config. |
| 46 | const ::Eigen::DiagonalMatrix<double, 5> Q = |
| 47 | (::Eigen::DiagonalMatrix<double, 5>().diagonal() |
| 48 | << 1.0 / ::std::pow(0.05, 2), |
| 49 | 1.0 / ::std::pow(0.05, 2), 1.0 / ::std::pow(0.2, 2), |
| 50 | 1.0 / ::std::pow(0.5, 2), 1.0 / ::std::pow(0.5, 2)) |
| 51 | .finished() |
| 52 | .asDiagonal(); |
| 53 | const ::Eigen::DiagonalMatrix<double, 2> R = |
| 54 | (::Eigen::DiagonalMatrix<double, 2>().diagonal() |
| 55 | << 1.0 / ::std::pow(12.0, 2), |
| 56 | 1.0 / ::std::pow(12.0, 2)) |
| 57 | .finished() |
| 58 | .asDiagonal(); |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | } // namespace drivetrain |
| 62 | } // namespace control_loops |
| 63 | } // namespace frc971 |
| 64 | |
| 65 | #endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_SPLINEDRIVETRAIN_H_ |