Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 1 | #ifndef Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 2 | #define Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 6 | #include "aos/controls/control_loop.h" |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 7 | #include "frc971/control_loops/state_feedback_loop.h" |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 8 | #include "y2018/control_loops/superstructure/arm/arm.h" |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 9 | #include "y2018/control_loops/superstructure/intake/intake.h" |
| 10 | #include "y2018/control_loops/superstructure/superstructure.q.h" |
| 11 | |
| 12 | namespace y2018 { |
| 13 | namespace control_loops { |
| 14 | namespace superstructure { |
| 15 | |
| 16 | class Superstructure |
| 17 | : public ::aos::controls::ControlLoop<control_loops::SuperstructureQueue> { |
| 18 | public: |
| 19 | explicit Superstructure( |
Austin Schuh | 55a13dc | 2019-01-27 22:39:03 -0800 | [diff] [blame] | 20 | ::aos::EventLoop *event_loop, |
| 21 | const ::std::string &name = ".y2018.control_loops.superstructure_queue"); |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 22 | |
| 23 | const intake::IntakeSide &intake_left() const { return intake_left_; } |
| 24 | const intake::IntakeSide &intake_right() const { return intake_right_; } |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 25 | const arm::Arm &arm() const { return arm_; } |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 26 | |
| 27 | protected: |
| 28 | virtual void RunIteration( |
| 29 | const control_loops::SuperstructureQueue::Goal *unsafe_goal, |
| 30 | const control_loops::SuperstructureQueue::Position *position, |
| 31 | control_loops::SuperstructureQueue::Output *output, |
| 32 | control_loops::SuperstructureQueue::Status *status) override; |
| 33 | |
| 34 | private: |
| 35 | intake::IntakeSide intake_left_; |
| 36 | intake::IntakeSide intake_right_; |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 37 | arm::Arm arm_; |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 38 | |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 39 | // The last centering error. This is the distance that the center of the two |
| 40 | // intakes is away from 0. |
| 41 | double last_intake_center_error_ = 0.0; |
| 42 | // The last distance that the box distance lidar measured. |
| 43 | double last_box_distance_ = 0.0; |
| 44 | // State variable for the box velocity low pass filter. |
| 45 | double filtered_box_velocity_ = 0.0; |
| 46 | |
Austin Schuh | 17dd089 | 2018-03-02 20:06:31 -0800 | [diff] [blame] | 47 | enum class RotationState { |
| 48 | NOT_ROTATING = 0, |
| 49 | ROTATING_LEFT = 1, |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 50 | ROTATING_RIGHT = 2, |
| 51 | STUCK = 3 |
Austin Schuh | 17dd089 | 2018-03-02 20:06:31 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | RotationState rotation_state_ = RotationState::NOT_ROTATING; |
| 55 | int rotation_count_ = 0; |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 56 | int stuck_count_ = 0; |
| 57 | ::aos::monotonic_clock::time_point last_stuck_time_ = |
| 58 | ::aos::monotonic_clock::min_time; |
| 59 | ::aos::monotonic_clock::time_point last_unstuck_time_ = |
| 60 | ::aos::monotonic_clock::min_time; |
Austin Schuh | 17dd089 | 2018-03-02 20:06:31 -0800 | [diff] [blame] | 61 | |
Sabina Davis | 8d20ca8 | 2018-02-19 13:17:45 -0800 | [diff] [blame] | 62 | DISALLOW_COPY_AND_ASSIGN(Superstructure); |
| 63 | }; |
| 64 | |
| 65 | } // namespace superstructure |
| 66 | } // namespace control_loops |
| 67 | } // namespace y2018 |
| 68 | |
| 69 | #endif // Y2018_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |