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 | |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 9 | #include "y2016/control_loops/shooter/shooter_integral_plant.h" |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 10 | #include "y2016/control_loops/shooter/shooter.q.h" |
| 11 | |
| 12 | namespace y2016 { |
| 13 | namespace control_loops { |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 14 | namespace shooter { |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 15 | |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 16 | namespace { |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 17 | constexpr double kTolerance = 10.0; |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 18 | } // namespace |
| 19 | |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 20 | class ShooterSide { |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 21 | public: |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 22 | ShooterSide(); |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 23 | |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 24 | // Sets the velocity goal in radians/sec |
| 25 | void set_goal(double angular_velocity_goal); |
| 26 | // Sets the current encoder position in radians |
| 27 | void set_position(double current_position); |
| 28 | |
| 29 | // Populates the status structure. |
| 30 | void SetStatus(ShooterSideStatus *status); |
| 31 | |
| 32 | // Returns the control loop calculated voltage. |
| 33 | double voltage() const; |
| 34 | |
| 35 | // Executes the control loop for a cycle. |
| 36 | void Update(bool disabled); |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 37 | |
| 38 | private: |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 39 | // The current sensor measurement. |
| 40 | Eigen::Matrix<double, 1, 1> Y_; |
| 41 | // The control loop. |
| 42 | ::std::unique_ptr<StateFeedbackLoop<3, 1, 1>> loop_; |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 43 | |
| 44 | // History array for calculating a filtered angular velocity. |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 45 | static constexpr int kHistoryLength = 10; |
| 46 | ::std::array<double, kHistoryLength> history_; |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 47 | ptrdiff_t history_position_; |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 48 | |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 49 | DISALLOW_COPY_AND_ASSIGN(ShooterSide); |
| 50 | }; |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 51 | |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 52 | class Shooter : public ::aos::controls::ControlLoop<ShooterQueue> { |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 53 | public: |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 54 | explicit Shooter( |
| 55 | ShooterQueue *shooter_queue = &control_loops::shooter::shooter_queue); |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 56 | |
| 57 | protected: |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 58 | void RunIteration(const ShooterQueue::Goal *goal, |
| 59 | const ShooterQueue::Position *position, |
| 60 | ShooterQueue::Output *output, |
| 61 | ShooterQueue::Status *status) override; |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | ShooterSide left_, right_; |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 65 | |
| 66 | DISALLOW_COPY_AND_ASSIGN(Shooter); |
| 67 | }; |
| 68 | |
Austin Schuh | 09c2b0b | 2016-02-13 15:53:16 -0800 | [diff] [blame] | 69 | } // namespace shooter |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 70 | } // namespace control_loops |
| 71 | } // namespace y2016 |
| 72 | |
| 73 | #endif // Y2016_CONTROL_LOOPS_SHOOTER_SHOOTER_H_ |