Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 1 | #ifndef Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 2 | #define Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |
| 3 | |
| 4 | #include "aos/events/event_loop.h" |
| 5 | #include "aos/json_to_flatbuffer.h" |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 6 | #include "aos/time/time.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 7 | #include "frc971/constants/constants_sender_lib.h" |
| 8 | #include "frc971/control_loops/control_loop.h" |
| 9 | #include "frc971/control_loops/drivetrain/drivetrain_can_position_generated.h" |
| 10 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
| 11 | #include "frc971/zeroing/absolute_encoder.h" |
| 12 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
| 13 | #include "y2024/constants.h" |
| 14 | #include "y2024/constants/constants_generated.h" |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 15 | #include "y2024/control_loops/superstructure/shooter.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 16 | #include "y2024/control_loops/superstructure/superstructure_goal_generated.h" |
| 17 | #include "y2024/control_loops/superstructure/superstructure_output_generated.h" |
| 18 | #include "y2024/control_loops/superstructure/superstructure_position_generated.h" |
| 19 | #include "y2024/control_loops/superstructure/superstructure_status_generated.h" |
| 20 | |
Maxwell Henderson | 09a4b02 | 2024-01-19 21:39:51 -0800 | [diff] [blame] | 21 | namespace y2024::control_loops::superstructure { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 22 | |
| 23 | class Superstructure |
| 24 | : public ::frc971::controls::ControlLoop<Goal, Position, Status, Output> { |
| 25 | public: |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 26 | using AbsoluteEncoderSubsystem = |
| 27 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 28 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator, |
| 29 | ::frc971::control_loops::AbsoluteEncoderProfiledJointStatus>; |
| 30 | |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 31 | using PotAndAbsoluteEncoderSubsystem = |
| 32 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 33 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator, |
| 34 | ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>; |
| 35 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 36 | explicit Superstructure(::aos::EventLoop *event_loop, |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 37 | const ::std::string &name = "/superstructure"); |
| 38 | |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 39 | inline const AbsoluteEncoderSubsystem &intake_pivot() const { |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 40 | return intake_pivot_; |
| 41 | } |
| 42 | |
Filip Kujawa | 6d71763 | 2024-02-01 11:40:55 -0800 | [diff] [blame] | 43 | inline const PotAndAbsoluteEncoderSubsystem &climber() const { |
| 44 | return climber_; |
| 45 | } |
| 46 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 47 | inline const Shooter &shooter() const { return shooter_; } |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 48 | inline const PotAndAbsoluteEncoderSubsystem &extend() const { |
| 49 | return extend_; |
| 50 | } |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 51 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 52 | double robot_velocity() const; |
| 53 | |
| 54 | protected: |
| 55 | virtual void RunIteration(const Goal *unsafe_goal, const Position *position, |
| 56 | aos::Sender<Output>::Builder *output, |
| 57 | aos::Sender<Status>::Builder *status) override; |
| 58 | |
| 59 | private: |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 60 | frc971::constants::ConstantsFetcher<Constants> constants_fetcher_; |
Niko Sohmers | afc51fe | 2024-01-29 17:48:35 -0800 | [diff] [blame] | 61 | const Constants *robot_constants_; |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 62 | aos::Fetcher<frc971::control_loops::drivetrain::Status> |
| 63 | drivetrain_status_fetcher_; |
| 64 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
| 65 | |
Niko Sohmers | ac4d887 | 2024-02-23 13:55:47 -0800 | [diff] [blame] | 66 | CollisionAvoidance collision_avoidance_; |
| 67 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 68 | aos::Alliance alliance_ = aos::Alliance::kInvalid; |
| 69 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 70 | SuperstructureState state_ = SuperstructureState::IDLE; |
| 71 | |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame^] | 72 | bool trap_override_ = false; |
| 73 | |
Niko Sohmers | 5006fc4 | 2024-03-01 17:14:22 -0800 | [diff] [blame] | 74 | NoteGoal requested_note_goal_ = NoteGoal::NONE; |
| 75 | |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame^] | 76 | aos::monotonic_clock::time_point transfer_start_time_ = |
| 77 | aos::monotonic_clock::time_point::min(); |
| 78 | |
Filip Kujawa | 77e3d8a | 2024-03-02 11:34:56 -0800 | [diff] [blame] | 79 | aos::monotonic_clock::time_point intake_end_time_ = |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 80 | aos::monotonic_clock::time_point::min(); |
| 81 | |
Filip Kujawa | 77e3d8a | 2024-03-02 11:34:56 -0800 | [diff] [blame] | 82 | aos::monotonic_clock::time_point loading_catapult_start_time_ = |
Maxwell Henderson | f0d2262 | 2024-02-26 21:02:11 -0800 | [diff] [blame] | 83 | aos::monotonic_clock::time_point::min(); |
| 84 | |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 85 | AbsoluteEncoderSubsystem intake_pivot_; |
Filip Kujawa | 6d71763 | 2024-02-01 11:40:55 -0800 | [diff] [blame] | 86 | PotAndAbsoluteEncoderSubsystem climber_; |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 87 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 88 | Shooter shooter_; |
| 89 | |
Filip Kujawa | 7a79960 | 2024-02-23 12:27:47 -0800 | [diff] [blame] | 90 | PotAndAbsoluteEncoderSubsystem extend_; |
Niko Sohmers | 6adb5b9 | 2024-03-16 17:47:54 -0700 | [diff] [blame^] | 91 | |
| 92 | Debouncer extend_debouncer_; |
| 93 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 94 | DISALLOW_COPY_AND_ASSIGN(Superstructure); |
| 95 | }; |
| 96 | |
Maxwell Henderson | 09a4b02 | 2024-01-19 21:39:51 -0800 | [diff] [blame] | 97 | } // namespace y2024::control_loops::superstructure |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 98 | |
| 99 | #endif // Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_SUPERSTRUCTURE_H_ |