Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 1 | #ifndef Y2014_BOT3_CONTROL_LOOPS_DRIVETRAIN_H_ |
| 2 | #define Y2014_BOT3_CONTROL_LOOPS_DRIVETRAIN_H_ |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 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 "aos/common/util/log_interval.h" |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 10 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 11 | #include "frc971/shifter_hall_effect.h" |
| 12 | #include "y2014_bot3/control_loops/drivetrain/drivetrain.q.h" |
| 13 | |
| 14 | namespace y2014_bot3 { |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 15 | namespace control_loops { |
| 16 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 17 | // Constants |
| 18 | // TODO(comran): Get actual constants. |
| 19 | constexpr double kDrivetrainTurnWidth = 0.63; |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 20 | constexpr double kDrivetrainEncoderRatio = 18.0 / 44.0; |
| 21 | constexpr double kDrivetrainHighGearRatio = |
| 22 | kDrivetrainEncoderRatio * 18.0 / 60.0; |
| 23 | constexpr double kDrivetrainLowGearRatio = kDrivetrainHighGearRatio; |
| 24 | const ::frc971::constants::ShifterHallEffect kDrivetrainRightShifter{ |
| 25 | 555, 657, 660, 560, 0.2, 0.7}; |
| 26 | const ::frc971::constants::ShifterHallEffect kDrivetrainLeftShifter{ |
| 27 | 555, 660, 644, 552, 0.2, 0.7}; |
| 28 | // End constants |
| 29 | |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 30 | class DrivetrainLoop |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 31 | : public aos::controls::ControlLoop<control_loops::DrivetrainQueue> { |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 32 | public: |
| 33 | // Constructs a control loop which can take a Drivetrain or defaults to the |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 34 | // drivetrain at y2014_bot3::control_loops::drivetrain |
| 35 | explicit DrivetrainLoop(control_loops::DrivetrainQueue *my_drivetrain = |
| 36 | &control_loops::drivetrain_queue) |
| 37 | : aos::controls::ControlLoop<control_loops::DrivetrainQueue>( |
| 38 | my_drivetrain) { |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 39 | ::aos::controls::HPolytope<0>::Init(); |
| 40 | } |
| 41 | |
| 42 | protected: |
| 43 | // Executes one cycle of the control loop. |
| 44 | virtual void RunIteration( |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 45 | const control_loops::DrivetrainQueue::Goal *goal, |
| 46 | const control_loops::DrivetrainQueue::Position *position, |
| 47 | control_loops::DrivetrainQueue::Output *output, |
| 48 | control_loops::DrivetrainQueue::Status *status); |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 49 | |
| 50 | typedef ::aos::util::SimpleLogInterval SimpleLogInterval; |
| 51 | SimpleLogInterval no_position_ = SimpleLogInterval( |
| 52 | ::aos::time::Time::InSeconds(0.25), WARNING, "no position"); |
| 53 | }; |
| 54 | |
| 55 | } // namespace control_loops |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 56 | } // namespace y2014_bot3 |
Comran Morshed | e9b1292 | 2015-11-04 19:46:48 +0000 | [diff] [blame] | 57 | |
Comran Morshed | 41ed7c2 | 2015-11-04 21:03:37 +0000 | [diff] [blame] | 58 | #endif // Y2014_BOT3_CONTROL_LOOPS_DRIVETRAIN_H_ |