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