Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_DRIVETRAIN_H_ |
| 2 | #define FRC971_CONTROL_LOOPS_DRIVETRAIN_H_ |
| 3 | |
| 4 | #include "Eigen/Dense" |
| 5 | |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 6 | #include "aos/common/controls/control_loop.h" |
| 7 | #include "aos/common/controls/polytope.h" |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 8 | #include "aos/common/controls/polytope.h" |
| 9 | #include "aos/common/util/log_interval.h" |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 10 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 11 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
| 12 | #include "frc971/control_loops/drivetrain/gear.h" |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 13 | #include "frc971/control_loops/drivetrain/polydrivetrain.h" |
| 14 | #include "frc971/control_loops/drivetrain/ssdrivetrain.h" |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 15 | |
| 16 | namespace frc971 { |
| 17 | namespace control_loops { |
| 18 | namespace drivetrain { |
| 19 | |
| 20 | class DrivetrainLoop : public aos::controls::ControlLoop< |
| 21 | ::frc971::control_loops::DrivetrainQueue> { |
| 22 | public: |
| 23 | // Constructs a control loop which can take a Drivetrain or defaults to the |
| 24 | // drivetrain at frc971::control_loops::drivetrain |
Adam Snaider | bc918b6 | 2016-02-27 21:03:39 -0800 | [diff] [blame] | 25 | explicit DrivetrainLoop( |
| 26 | const DrivetrainConfig &dt_config, |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 27 | ::frc971::control_loops::DrivetrainQueue *my_drivetrain = |
| 28 | &::frc971::control_loops::drivetrain_queue); |
| 29 | |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 30 | int ControllerIndexFromGears(); |
| 31 | |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 32 | protected: |
| 33 | // Executes one cycle of the control loop. |
Adam Snaider | bc918b6 | 2016-02-27 21:03:39 -0800 | [diff] [blame] | 34 | void RunIteration( |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 35 | const ::frc971::control_loops::DrivetrainQueue::Goal *goal, |
| 36 | const ::frc971::control_loops::DrivetrainQueue::Position *position, |
| 37 | ::frc971::control_loops::DrivetrainQueue::Output *output, |
Adam Snaider | bc918b6 | 2016-02-27 21:03:39 -0800 | [diff] [blame] | 38 | ::frc971::control_loops::DrivetrainQueue::Status *status) override; |
| 39 | |
| 40 | void Zero(::frc971::control_loops::DrivetrainQueue::Output *output) override; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 41 | |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 42 | double last_gyro_rate_ = 0.0; |
| 43 | |
| 44 | const DrivetrainConfig dt_config_; |
| 45 | |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 46 | StateFeedbackLoop<7, 2, 3> kf_; |
Austin Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame] | 47 | PolyDrivetrain dt_openloop_; |
| 48 | DrivetrainMotorsSS dt_closedloop_; |
Austin Schuh | 9993fb3 | 2017-03-15 20:17:46 -0700 | [diff] [blame^] | 49 | ::aos::monotonic_clock::time_point last_gyro_time_ = |
| 50 | ::aos::monotonic_clock::min_time; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 51 | |
Austin Schuh | 05c5a61 | 2016-04-02 15:10:25 -0700 | [diff] [blame] | 52 | StateFeedbackLoop<2, 1, 1> down_estimator_; |
| 53 | Eigen::Matrix<double, 1, 1> down_U_; |
| 54 | |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 55 | // Current gears for each drive side. |
| 56 | Gear left_gear_; |
| 57 | Gear right_gear_; |
| 58 | |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 59 | double last_left_voltage_ = 0; |
| 60 | double last_right_voltage_ = 0; |
| 61 | |
| 62 | double integrated_kf_heading_ = 0; |
Austin Schuh | 093535c | 2016-03-05 23:21:00 -0800 | [diff] [blame] | 63 | |
| 64 | bool left_high_requested_; |
| 65 | bool right_high_requested_; |
Austin Schuh | 5900d14 | 2016-04-03 21:35:12 -0700 | [diff] [blame] | 66 | |
| 67 | bool has_been_enabled_ = false; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // namespace drivetrain |
| 71 | } // namespace control_loops |
| 72 | } // namespace frc971 |
| 73 | |
| 74 | #endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_H_ |