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