James Kuszmaul | f7f5ec1 | 2013-11-01 17:58:58 -0700 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_SHOOTER_H_ |
| 2 | #define FRC971_CONTROL_LOOPS_SHOOTER_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "aos/common/control_loop/ControlLoop.h" |
| 7 | #include "frc971/control_loops/state_feedback_loop.h" |
| 8 | #include "bot3/control_loops/shooter/shooter_motor.q.h" |
| 9 | #include "bot3/control_loops/shooter/shooter_motor_plant.h" |
| 10 | |
| 11 | namespace bot3 { |
| 12 | namespace control_loops { |
| 13 | |
| 14 | class ShooterMotor |
| 15 | : public aos::control_loops::ControlLoop<control_loops::ShooterLoop> { |
| 16 | public: |
| 17 | explicit ShooterMotor( |
| 18 | control_loops::ShooterLoop *my_shooter = &control_loops::shooter); |
| 19 | |
| 20 | // Control loop time step. |
| 21 | static const double dt; |
| 22 | |
| 23 | // Maximum speed of the shooter wheel which the encoder is rated for in |
| 24 | // rad/sec. |
| 25 | static const double kMaxSpeed; |
| 26 | |
| 27 | protected: |
| 28 | virtual void RunIteration( |
| 29 | const control_loops::ShooterLoop::Goal *goal, |
| 30 | const control_loops::ShooterLoop::Position *position, |
| 31 | ::aos::control_loops::Output *output, |
| 32 | control_loops::ShooterLoop::Status *status); |
| 33 | |
| 34 | private: |
| 35 | // The state feedback control loop to talk to. |
| 36 | ::std::unique_ptr<StateFeedbackLoop<2, 1, 1>> loop_; |
| 37 | |
| 38 | // History array and stuff for determining average velocity and whether |
| 39 | // we are ready to shoot. |
| 40 | static const int kHistoryLength = 5; |
| 41 | double history_[kHistoryLength]; |
| 42 | ptrdiff_t history_position_; |
| 43 | double average_velocity_; |
| 44 | |
| 45 | double position_goal_; |
| 46 | double last_position_; |
| 47 | |
| 48 | // For making sure it keeps spinning if we're shooting. |
| 49 | double last_velocity_goal_; |
| 50 | |
| 51 | DISALLOW_COPY_AND_ASSIGN(ShooterMotor); |
| 52 | }; |
| 53 | |
| 54 | } // namespace control_loops |
| 55 | } // namespace bot3 |
| 56 | |
| 57 | #endif // FRC971_CONTROL_LOOPS_SHOOTER_H_ |