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 | |
| 6 | #include "aos/common/controls/polytope.h" |
| 7 | #include "aos/common/controls/control_loop.h" |
| 8 | #include "aos/common/controls/polytope.h" |
| 9 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 10 | #include "frc971/control_loops/drivetrain/polydrivetrain.h" |
| 11 | #include "frc971/control_loops/drivetrain/ssdrivetrain.h" |
| 12 | #include "frc971/control_loops/drivetrain/drivetrain_config.h" |
| 13 | #include "aos/common/util/log_interval.h" |
| 14 | |
| 15 | namespace frc971 { |
| 16 | namespace control_loops { |
| 17 | namespace drivetrain { |
| 18 | |
| 19 | class DrivetrainLoop : public aos::controls::ControlLoop< |
| 20 | ::frc971::control_loops::DrivetrainQueue> { |
| 21 | public: |
| 22 | // Constructs a control loop which can take a Drivetrain or defaults to the |
| 23 | // drivetrain at frc971::control_loops::drivetrain |
Adam Snaider | bc918b6 | 2016-02-27 21:03:39 -0800 | [diff] [blame^] | 24 | explicit DrivetrainLoop( |
| 25 | const DrivetrainConfig &dt_config, |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 26 | ::frc971::control_loops::DrivetrainQueue *my_drivetrain = |
| 27 | &::frc971::control_loops::drivetrain_queue); |
| 28 | |
| 29 | protected: |
| 30 | // Executes one cycle of the control loop. |
Adam Snaider | bc918b6 | 2016-02-27 21:03:39 -0800 | [diff] [blame^] | 31 | void RunIteration( |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 32 | const ::frc971::control_loops::DrivetrainQueue::Goal *goal, |
| 33 | const ::frc971::control_loops::DrivetrainQueue::Position *position, |
| 34 | ::frc971::control_loops::DrivetrainQueue::Output *output, |
Adam Snaider | bc918b6 | 2016-02-27 21:03:39 -0800 | [diff] [blame^] | 35 | ::frc971::control_loops::DrivetrainQueue::Status *status) override; |
| 36 | |
| 37 | void Zero(::frc971::control_loops::DrivetrainQueue::Output *output) override; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 38 | |
| 39 | typedef ::aos::util::SimpleLogInterval SimpleLogInterval; |
| 40 | SimpleLogInterval no_position_ = SimpleLogInterval( |
| 41 | ::aos::time::Time::InSeconds(0.25), WARNING, "no position"); |
| 42 | double last_gyro_heading_ = 0.0; |
| 43 | double last_gyro_rate_ = 0.0; |
| 44 | |
| 45 | const DrivetrainConfig dt_config_; |
| 46 | |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 47 | StateFeedbackLoop<7, 2, 3> kf_; |
Austin Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame] | 48 | PolyDrivetrain dt_openloop_; |
| 49 | DrivetrainMotorsSS dt_closedloop_; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 50 | |
| 51 | double last_left_voltage_ = 0; |
| 52 | double last_right_voltage_ = 0; |
| 53 | |
| 54 | double integrated_kf_heading_ = 0; |
| 55 | }; |
| 56 | |
| 57 | } // namespace drivetrain |
| 58 | } // namespace control_loops |
| 59 | } // namespace frc971 |
| 60 | |
| 61 | #endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_H_ |