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 | |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame^] | 15 | namespace { |
| 16 | // TODO(constants): Update. |
| 17 | const double kTolerance = 10.0; |
| 18 | const double kMaxSpeed = 10000.0 * (2.0 * M_PI) / 60.0 * 15.0 / 34.0; |
| 19 | const double kAngularVelocityWeightScalar = 0.35; |
| 20 | } // namespace |
| 21 | |
| 22 | struct ShooterStatus { |
| 23 | double avg_angular_velocity; |
| 24 | bool ready; |
| 25 | }; |
| 26 | |
| 27 | class ShooterSide { |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 28 | public: |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame^] | 29 | ShooterSide(); |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 30 | |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame^] | 31 | void SetGoal(double angular_velocity_goal); |
| 32 | void EstimatePositionTimestep(); |
| 33 | void SetPosition(double current_position); |
| 34 | const ShooterStatus GetStatus(); |
| 35 | double GetOutput(); |
| 36 | void UpdateLoop(bool output_is_null); |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 37 | |
| 38 | private: |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 39 | ::std::unique_ptr<StateFeedbackLoop<2, 1, 1>> loop_; |
| 40 | |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame^] | 41 | double current_position_ = 0.0; |
| 42 | double position_goal_ = 0.0; |
| 43 | double angular_velocity_goal_ = 0.0; |
| 44 | |
| 45 | // History array for calculating a filtered angular velocity. |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 46 | static const int kHistoryLength = 5; |
| 47 | double history_[kHistoryLength]; |
| 48 | ptrdiff_t history_position_; |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 49 | |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame^] | 50 | DISALLOW_COPY_AND_ASSIGN(ShooterSide); |
| 51 | }; |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 52 | |
Comran Morshed | cde5032 | 2016-01-18 15:10:36 +0000 | [diff] [blame^] | 53 | class Shooter |
| 54 | : public ::aos::controls::ControlLoop<control_loops::ShooterQueue> { |
| 55 | public: |
| 56 | explicit Shooter(control_loops::ShooterQueue *shooter_queue = |
| 57 | &control_loops::shooter_queue); |
| 58 | |
| 59 | protected: |
| 60 | void RunIteration(const control_loops::ShooterQueue::Goal *goal, |
| 61 | const control_loops::ShooterQueue::Position *position, |
| 62 | control_loops::ShooterQueue::Output *output, |
| 63 | control_loops::ShooterQueue::Status *status) override; |
| 64 | |
| 65 | private: |
| 66 | ShooterSide left_, right_; |
Comran Morshed | 2a97bc8 | 2016-01-16 17:27:01 +0000 | [diff] [blame] | 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(Shooter); |
| 69 | }; |
| 70 | |
| 71 | } // namespace control_loops |
| 72 | } // namespace y2016 |
| 73 | |
| 74 | #endif // Y2016_CONTROL_LOOPS_SHOOTER_SHOOTER_H_ |