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