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