Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 1 | #ifndef Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 2 | #define Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "aos/common/controls/control_loop.h" |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 7 | #include "aos/common/util/trapezoid_profile.h" |
Austin Schuh | 10c2d11 | 2016-02-14 13:42:28 -0800 | [diff] [blame] | 8 | #include "frc971/control_loops/state_feedback_loop.h" |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 9 | |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 10 | #include "frc971/zeroing/zeroing.h" |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 11 | #include "y2016/control_loops/superstructure/superstructure.q.h" |
Austin Schuh | 10c2d11 | 2016-02-14 13:42:28 -0800 | [diff] [blame] | 12 | #include "y2016/control_loops/superstructure/superstructure_controls.h" |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 13 | |
| 14 | namespace y2016 { |
| 15 | namespace control_loops { |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 16 | namespace superstructure { |
| 17 | namespace testing { |
| 18 | class SuperstructureTest_DisabledGoalTest_Test; |
| 19 | } // namespace testing |
| 20 | |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 21 | class Superstructure |
| 22 | : public ::aos::controls::ControlLoop<control_loops::SuperstructureQueue> { |
| 23 | public: |
| 24 | explicit Superstructure( |
| 25 | control_loops::SuperstructureQueue *my_superstructure = |
| 26 | &control_loops::superstructure_queue); |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 27 | enum State { |
| 28 | // Waiting to receive data before doing anything. |
| 29 | UNINITIALIZED = 0, |
| 30 | // Estimating the starting location. |
| 31 | INITIALIZING = 1, |
| 32 | // Moving the intake to find an index pulse. |
| 33 | ZEROING_INTAKE = 2, |
| 34 | // Moving the arm to find an index pulse. |
| 35 | ZEROING_ARM = 3, |
| 36 | // All good! |
| 37 | RUNNING = 4, |
| 38 | // Internal error caused the superstructure to abort. |
| 39 | ESTOP = 5, |
| 40 | }; |
| 41 | |
| 42 | State state() const { return state_; } |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 43 | |
| 44 | protected: |
| 45 | virtual void RunIteration( |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 46 | const control_loops::SuperstructureQueue::Goal *unsafe_goal, |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 47 | const control_loops::SuperstructureQueue::Position *position, |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 48 | control_loops::SuperstructureQueue::Output *output, |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 49 | control_loops::SuperstructureQueue::Status *status) override; |
| 50 | |
| 51 | private: |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 52 | friend class testing::SuperstructureTest_DisabledGoalTest_Test; |
| 53 | Intake intake_; |
| 54 | Arm arm_; |
| 55 | |
| 56 | State state_ = UNINITIALIZED; |
| 57 | State last_state_ = UNINITIALIZED; |
| 58 | |
| 59 | // Sets state_ to the correct state given the current state of the zeroing |
| 60 | // estimators. |
| 61 | void UpdateZeroingState(); |
| 62 | |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 63 | DISALLOW_COPY_AND_ASSIGN(Superstructure); |
| 64 | }; |
| 65 | |
Austin Schuh | 2fc10fa | 2016-02-08 00:44:34 -0800 | [diff] [blame] | 66 | } // namespace superstructure |
Comran Morshed | 25f81a0 | 2016-01-23 13:40:10 +0000 | [diff] [blame] | 67 | } // namespace control_loops |
| 68 | } // namespace y2016 |
| 69 | |
| 70 | #endif // Y2016_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |