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 |
| 24 | explicit DrivetrainLoop(const DrivetrainConfig &dt_config, |
| 25 | ::frc971::control_loops::DrivetrainQueue *my_drivetrain = |
| 26 | &::frc971::control_loops::drivetrain_queue); |
| 27 | |
| 28 | protected: |
| 29 | // Executes one cycle of the control loop. |
| 30 | virtual void RunIteration( |
| 31 | const ::frc971::control_loops::DrivetrainQueue::Goal *goal, |
| 32 | const ::frc971::control_loops::DrivetrainQueue::Position *position, |
| 33 | ::frc971::control_loops::DrivetrainQueue::Output *output, |
| 34 | ::frc971::control_loops::DrivetrainQueue::Status *status); |
| 35 | |
| 36 | typedef ::aos::util::SimpleLogInterval SimpleLogInterval; |
| 37 | SimpleLogInterval no_position_ = SimpleLogInterval( |
| 38 | ::aos::time::Time::InSeconds(0.25), WARNING, "no position"); |
| 39 | double last_gyro_heading_ = 0.0; |
| 40 | double last_gyro_rate_ = 0.0; |
| 41 | |
| 42 | const DrivetrainConfig dt_config_; |
| 43 | |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 44 | StateFeedbackLoop<7, 2, 3> kf_; |
Austin Schuh | 4156560 | 2016-02-28 20:10:49 -0800 | [diff] [blame] | 45 | PolyDrivetrain dt_openloop_; |
| 46 | DrivetrainMotorsSS dt_closedloop_; |
Comran Morshed | 5323ecb | 2015-12-26 20:50:55 +0000 | [diff] [blame] | 47 | |
| 48 | double last_left_voltage_ = 0; |
| 49 | double last_right_voltage_ = 0; |
| 50 | |
| 51 | double integrated_kf_heading_ = 0; |
| 52 | }; |
| 53 | |
| 54 | } // namespace drivetrain |
| 55 | } // namespace control_loops |
| 56 | } // namespace frc971 |
| 57 | |
| 58 | #endif // FRC971_CONTROL_LOOPS_DRIVETRAIN_H_ |