milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 1 | #ifndef Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 2 | #define Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 3 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 4 | #include "aos/events/event_loop.h" |
Nathan Leong | dd72800 | 2024-02-03 15:26:53 -0800 | [diff] [blame^] | 5 | #include "frc971/control_loops/catapult/catapult.h" |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 6 | #include "frc971/control_loops/control_loop.h" |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 7 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
James Kuszmaul | ec635d2 | 2023-08-12 18:39:24 -0700 | [diff] [blame] | 8 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 9 | #include "y2022/constants.h" |
Nathan Leong | dd72800 | 2024-02-03 15:26:53 -0800 | [diff] [blame^] | 10 | #include "y2022/control_loops/superstructure/catapult/catapult_plant.h" |
| 11 | #include "y2022/control_loops/superstructure/catapult/integral_catapult_plant.h" |
Milind Upadhyay | 225156b | 2022-02-25 22:42:12 -0800 | [diff] [blame] | 12 | #include "y2022/control_loops/superstructure/collision_avoidance.h" |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 13 | #include "y2022/control_loops/superstructure/superstructure_can_position_generated.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 14 | #include "y2022/control_loops/superstructure/superstructure_goal_generated.h" |
| 15 | #include "y2022/control_loops/superstructure/superstructure_output_generated.h" |
| 16 | #include "y2022/control_loops/superstructure/superstructure_position_generated.h" |
| 17 | #include "y2022/control_loops/superstructure/superstructure_status_generated.h" |
James Kuszmaul | 84083f4 | 2022-02-27 17:24:38 -0800 | [diff] [blame] | 18 | #include "y2022/control_loops/superstructure/turret/aiming.h" |
Ravago Jones | d51af7a | 2022-03-26 21:44:20 -0700 | [diff] [blame] | 19 | #include "y2022/vision/ball_color_generated.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 20 | |
| 21 | namespace y2022 { |
| 22 | namespace control_loops { |
| 23 | namespace superstructure { |
| 24 | |
| 25 | class Superstructure |
| 26 | : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> { |
| 27 | public: |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 28 | using RelativeEncoderSubsystem = |
| 29 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 30 | ::frc971::zeroing::RelativeEncoderZeroingEstimator, |
| 31 | ::frc971::control_loops::RelativeEncoderProfiledJointStatus>; |
| 32 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 33 | using PotAndAbsoluteEncoderSubsystem = |
| 34 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 35 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator, |
| 36 | ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>; |
| 37 | |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 38 | static constexpr double kTurretGoalThreshold = 0.05; |
milind-u | c63d094 | 2022-04-15 12:07:42 -0700 | [diff] [blame] | 39 | static constexpr double kTurretGoalLoadingThreshold = 0.70; |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 40 | static constexpr double kCatapultGoalThreshold = 0.05; |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 41 | // potentiometer will be more noisy |
| 42 | static constexpr double kFlipperGoalThreshold = 0.05; |
Ravago Jones | d51af7a | 2022-03-26 21:44:20 -0700 | [diff] [blame] | 43 | static constexpr double kDiscardingPosition = 0.35; |
| 44 | static constexpr double kDiscardingVelocity = 6.0; |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 45 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 46 | explicit Superstructure(::aos::EventLoop *event_loop, |
Milind Upadhyay | 225156b | 2022-02-25 22:42:12 -0800 | [diff] [blame] | 47 | std::shared_ptr<const constants::Values> values, |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 48 | const ::std::string &name = "/superstructure"); |
| 49 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 50 | inline const PotAndAbsoluteEncoderSubsystem &intake_front() const { |
| 51 | return intake_front_; |
| 52 | } |
| 53 | inline const PotAndAbsoluteEncoderSubsystem &intake_back() const { |
| 54 | return intake_back_; |
| 55 | } |
| 56 | inline const PotAndAbsoluteEncoderSubsystem &turret() const { |
| 57 | return turret_; |
| 58 | } |
| 59 | inline const RelativeEncoderSubsystem &climber() const { return climber_; } |
| 60 | |
| 61 | double robot_velocity() const; |
| 62 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 63 | protected: |
| 64 | virtual void RunIteration(const Goal *unsafe_goal, const Position *position, |
| 65 | aos::Sender<Output>::Builder *output, |
| 66 | aos::Sender<Status>::Builder *status) override; |
| 67 | |
| 68 | private: |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 69 | std::shared_ptr<const constants::Values> values_; |
| 70 | |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 71 | RelativeEncoderSubsystem climber_; |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 72 | PotAndAbsoluteEncoderSubsystem intake_front_; |
| 73 | PotAndAbsoluteEncoderSubsystem intake_back_; |
| 74 | PotAndAbsoluteEncoderSubsystem turret_; |
Nathan Leong | dd72800 | 2024-02-03 15:26:53 -0800 | [diff] [blame^] | 75 | ::frc971::control_loops::catapult::Catapult catapult_; |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 76 | |
Milind Upadhyay | 225156b | 2022-02-25 22:42:12 -0800 | [diff] [blame] | 77 | CollisionAvoidance collision_avoidance_; |
| 78 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 79 | aos::Fetcher<frc971::control_loops::drivetrain::Status> |
| 80 | drivetrain_status_fetcher_; |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 81 | aos::Fetcher<CANPosition> can_position_fetcher_; |
Ravago Jones | d51af7a | 2022-03-26 21:44:20 -0700 | [diff] [blame] | 82 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
| 83 | aos::Fetcher<y2022::vision::BallColor> ball_color_fetcher_; |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 84 | |
| 85 | int prev_shot_count_ = 0; |
| 86 | |
James Kuszmaul | 84083f4 | 2022-02-27 17:24:38 -0800 | [diff] [blame] | 87 | turret::Aimer aimer_; |
| 88 | |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 89 | bool flippers_open_ = false; |
| 90 | bool reseating_in_catapult_ = false; |
| 91 | bool fire_ = false; |
Ravago Jones | d51af7a | 2022-03-26 21:44:20 -0700 | [diff] [blame] | 92 | bool discarding_ball_ = false; |
| 93 | aos::Alliance alliance_ = aos::Alliance::kInvalid; |
| 94 | aos::Alliance ball_color_ = aos::Alliance::kInvalid; |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 95 | |
James Kuszmaul | 4052695 | 2022-03-13 15:56:38 -0700 | [diff] [blame] | 96 | aos::monotonic_clock::time_point front_intake_beambreak_timer_ = |
| 97 | aos::monotonic_clock::min_time; |
| 98 | aos::monotonic_clock::time_point back_intake_beambreak_timer_ = |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 99 | aos::monotonic_clock::min_time; |
| 100 | aos::monotonic_clock::time_point transferring_timer_ = |
| 101 | aos::monotonic_clock::min_time; |
| 102 | aos::monotonic_clock::time_point loading_timer_ = |
| 103 | aos::monotonic_clock::min_time; |
| 104 | aos::monotonic_clock::time_point flipper_opening_start_time_ = |
| 105 | aos::monotonic_clock::min_time; |
| 106 | SuperstructureState state_ = SuperstructureState::IDLE; |
James Kuszmaul | 4052695 | 2022-03-13 15:56:38 -0700 | [diff] [blame] | 107 | bool front_intake_has_ball_ = false; |
| 108 | bool back_intake_has_ball_ = false; |
Milind Upadhyay | 1612bbb | 2022-04-16 17:10:32 -0700 | [diff] [blame] | 109 | bool transitioning_second_ball_ = false; |
Austin Schuh | 9290881 | 2022-03-27 14:14:05 -0700 | [diff] [blame] | 110 | std::optional<double> last_shot_angle_ = std::nullopt; |
James Kuszmaul | 4052695 | 2022-03-13 15:56:38 -0700 | [diff] [blame] | 111 | RequestedIntake turret_intake_state_ = RequestedIntake::kFront; |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 112 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 113 | DISALLOW_COPY_AND_ASSIGN(Superstructure); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace superstructure |
| 117 | } // namespace control_loops |
| 118 | } // namespace y2022 |
| 119 | |
| 120 | #endif // Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |