Brian Silverman | c71537c | 2016-01-01 13:43:14 -0800 | [diff] [blame] | 1 | #ifndef Y2014_CONTROL_LOOPS_DRIVETRAIN_H_ |
| 2 | #define Y2014_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 "y2012/control_loops/drivetrain/drivetrain.q.h" |
| 10 | #include "y2012/control_loops/drivetrain/polydrivetrain.h" |
| 11 | #include "y2012/control_loops/drivetrain/ssdrivetrain.h" |
| 12 | #include "aos/common/util/log_interval.h" |
| 13 | |
| 14 | namespace y2012 { |
| 15 | namespace control_loops { |
| 16 | namespace drivetrain { |
| 17 | |
| 18 | class DrivetrainLoop : public aos::controls::ControlLoop< |
| 19 | ::y2012::control_loops::DrivetrainQueue> { |
| 20 | public: |
| 21 | // Constructs a control loop which can take a Drivetrain or defaults to the |
| 22 | // drivetrain at y2012::control_loops::drivetrain |
| 23 | explicit DrivetrainLoop( |
| 24 | ::y2012::control_loops::DrivetrainQueue *my_drivetrain = |
| 25 | &::y2012::control_loops::drivetrain_queue); |
| 26 | |
| 27 | protected: |
| 28 | // Executes one cycle of the control loop. |
| 29 | virtual void RunIteration( |
| 30 | const ::y2012::control_loops::DrivetrainQueue::Goal *goal, |
| 31 | const ::y2012::control_loops::DrivetrainQueue::Position *position, |
| 32 | ::y2012::control_loops::DrivetrainQueue::Output *output, |
| 33 | ::y2012::control_loops::DrivetrainQueue::Status *status); |
| 34 | |
| 35 | typedef ::aos::util::SimpleLogInterval SimpleLogInterval; |
| 36 | SimpleLogInterval no_position_ = SimpleLogInterval( |
| 37 | ::aos::time::Time::InSeconds(0.25), WARNING, "no position"); |
| 38 | double last_gyro_heading_ = 0.0; |
| 39 | double last_gyro_rate_ = 0.0; |
| 40 | |
| 41 | PolyDrivetrain dt_openloop_; |
| 42 | DrivetrainMotorsSS dt_closedloop_; |
| 43 | StateFeedbackLoop<7, 2, 3> kf_; |
| 44 | |
| 45 | double last_left_voltage_ = 0; |
| 46 | double last_right_voltage_ = 0; |
| 47 | |
| 48 | double integrated_kf_heading_ = 0; |
| 49 | }; |
| 50 | |
| 51 | } // namespace drivetrain |
| 52 | } // namespace control_loops |
| 53 | } // namespace y2012 |
| 54 | |
| 55 | #endif // Y2014_CONTROL_LOOPS_DRIVETRAIN_H_ |