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