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