Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 1 | #ifndef Y2020_CONTROL_LOOPS_SHOOTER_SHOOTER_H_ |
| 2 | #define Y2020_CONTROL_LOOPS_SHOOTER_SHOOTER_H_ |
| 3 | |
James Kuszmaul | 6175066 | 2021-06-21 21:32:33 -0700 | [diff] [blame] | 4 | #include "frc971/control_loops/control_loop.h" |
Maxwell Henderson | 3424299 | 2024-01-07 12:39:11 -0800 | [diff] [blame] | 5 | #include "frc971/control_loops/flywheel/flywheel_controller.h" |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 6 | #include "frc971/control_loops/state_feedback_loop.h" |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 7 | #include "y2020/control_loops/superstructure/superstructure_goal_generated.h" |
| 8 | #include "y2020/control_loops/superstructure/superstructure_output_generated.h" |
| 9 | #include "y2020/control_loops/superstructure/superstructure_position_generated.h" |
| 10 | #include "y2020/control_loops/superstructure/superstructure_status_generated.h" |
| 11 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 12 | namespace y2020::control_loops::superstructure::shooter { |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 13 | |
| 14 | // Handles all flywheels together. |
| 15 | class Shooter { |
| 16 | public: |
milind-u | 78f21b7 | 2021-10-10 13:47:28 -0700 | [diff] [blame] | 17 | static constexpr double kVelocityToleranceFinisher = 3.0; |
| 18 | static constexpr double kVelocityToleranceAccelerator = 4.0; |
| 19 | |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 20 | Shooter(); |
| 21 | |
| 22 | flatbuffers::Offset<ShooterStatus> RunIteration( |
| 23 | const ShooterGoal *goal, const ShooterPosition *position, |
Sabina Davis | 0f31d3f | 2020-02-20 20:41:00 -0800 | [diff] [blame] | 24 | flatbuffers::FlatBufferBuilder *fbb, OutputT *output, |
| 25 | const aos::monotonic_clock::time_point position_timestamp); |
| 26 | |
Austin Schuh | 01d81c3 | 2021-11-06 22:59:56 -0700 | [diff] [blame] | 27 | bool ready() const { return finisher_ready() && accelerator_ready(); } |
milind-u | 0beb7dc | 2021-10-16 19:31:33 -0700 | [diff] [blame] | 28 | bool finisher_ready() const { return finisher_ready_; } |
| 29 | bool accelerator_ready() const { return accelerator_ready_; } |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 30 | |
Austin Schuh | 263dead | 2021-04-04 21:19:19 -0700 | [diff] [blame] | 31 | float finisher_goal() const { return finisher_.goal(); } |
| 32 | float accelerator_goal() const { return accelerator_left_.goal(); } |
| 33 | |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 34 | private: |
milind-u | 7baf734 | 2021-08-25 18:31:26 -0700 | [diff] [blame] | 35 | // Minumum difference between the last local maximum finisher angular velocity |
| 36 | // and the current finisher angular velocity when we have a ball in the |
| 37 | // flywheel, in radians/s. This arises because the flywheel slows down when |
| 38 | // there is a ball in it. We can use this to determine when a ball is in the |
| 39 | // flywheel and when it gets shot. |
| 40 | static constexpr double kMinFinisherVelocityDipWithBall = 5.0; |
| 41 | |
Maxwell Henderson | 3424299 | 2024-01-07 12:39:11 -0800 | [diff] [blame] | 42 | frc971::control_loops::flywheel::FlywheelController finisher_, |
| 43 | accelerator_left_, accelerator_right_; |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 44 | |
Austin Schuh | 01d81c3 | 2021-11-06 22:59:56 -0700 | [diff] [blame] | 45 | void UpToSpeed(const ShooterGoal *goal); |
milind-u | 0beb7dc | 2021-10-16 19:31:33 -0700 | [diff] [blame] | 46 | bool finisher_ready_ = false; |
| 47 | bool accelerator_ready_ = false; |
Sabina Davis | 0f31d3f | 2020-02-20 20:41:00 -0800 | [diff] [blame] | 48 | |
milind-u | 7baf734 | 2021-08-25 18:31:26 -0700 | [diff] [blame] | 49 | int balls_shot_ = 0; |
| 50 | bool finisher_goal_changed_ = false; |
| 51 | bool ball_in_finisher_ = false; |
| 52 | // Last local maximum in the finisher angular velocity |
| 53 | double last_finisher_velocity_max_ = 0.0; |
| 54 | // True if the finisher's average acceleration over the last dt is positive |
| 55 | bool finisher_accelerating_ = false; |
| 56 | |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 57 | DISALLOW_COPY_AND_ASSIGN(Shooter); |
| 58 | }; |
| 59 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 60 | } // namespace y2020::control_loops::superstructure::shooter |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 61 | |
| 62 | #endif // Y2020_CONTROL_LOOPS_SHOOTER_SHOOTER_H_ |