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