Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame^] | 1 | #ifndef Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_SHOOTER_H_ |
| 2 | #define Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_SHOOTER_H_ |
| 3 | |
| 4 | #include "frc971/control_loops/catapult/catapult.h" |
| 5 | #include "frc971/control_loops/catapult/catapult_goal_static.h" |
| 6 | #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h" |
| 7 | #include "frc971/shooter_interpolation/interpolation.h" |
| 8 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
| 9 | #include "y2024/constants.h" |
| 10 | #include "y2024/constants/constants_generated.h" |
| 11 | #include "y2024/control_loops/superstructure/aiming.h" |
| 12 | #include "y2024/control_loops/superstructure/superstructure_can_position_generated.h" |
| 13 | #include "y2024/control_loops/superstructure/superstructure_goal_generated.h" |
| 14 | #include "y2024/control_loops/superstructure/superstructure_position_generated.h" |
| 15 | #include "y2024/control_loops/superstructure/superstructure_status_generated.h" |
| 16 | |
| 17 | namespace y2024::control_loops::superstructure { |
| 18 | |
| 19 | // The shooter class will control the various subsystems involved in the |
| 20 | // shooter- the turret, altitude, and catapult. |
| 21 | class Shooter { |
| 22 | public: |
| 23 | using PotAndAbsoluteEncoderSubsystem = |
| 24 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 25 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator, |
| 26 | ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus>; |
| 27 | |
| 28 | using CatapultSubsystem = |
| 29 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystem< |
| 30 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator, |
| 31 | ::frc971::control_loops::PotAndAbsoluteEncoderProfiledJointStatus, |
| 32 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator, |
| 33 | aos::util::AsymmetricTrapezoidProfile>; |
| 34 | |
| 35 | Shooter(aos::EventLoop *event_loop, const Constants *robot_constants); |
| 36 | |
| 37 | void Reset() { |
| 38 | catapult_.Reset(); |
| 39 | turret_.Reset(); |
| 40 | altitude_.Reset(); |
| 41 | } |
| 42 | |
| 43 | void Estop() { |
| 44 | catapult_.Estop(); |
| 45 | turret_.Estop(); |
| 46 | altitude_.Estop(); |
| 47 | } |
| 48 | |
| 49 | bool zeroed() { |
| 50 | return catapult_.zeroed() && turret_.zeroed() && altitude_.zeroed(); |
| 51 | } |
| 52 | |
| 53 | bool estopped() { |
| 54 | return catapult_.estopped() && turret_.estopped() && altitude_.estopped(); |
| 55 | } |
| 56 | |
| 57 | inline const PotAndAbsoluteEncoderSubsystem &turret() const { |
| 58 | return turret_; |
| 59 | } |
| 60 | |
| 61 | inline const PotAndAbsoluteEncoderSubsystem &altitude() const { |
| 62 | return altitude_; |
| 63 | } |
| 64 | |
| 65 | flatbuffers::Offset<ShooterStatus> Iterate( |
| 66 | const Position *position, const ShooterGoal *shooter_goal, |
| 67 | double *catapult_output, double *altitude_output, double *turret_output, |
| 68 | double *retention_roller_output, double battery_voltage, |
| 69 | aos::monotonic_clock::time_point current_timestamp, |
| 70 | flatbuffers::FlatBufferBuilder *fbb); |
| 71 | |
| 72 | private: |
| 73 | CatapultState state_ = CatapultState::RETRACTING; |
| 74 | |
| 75 | bool CatapultClose() const { |
| 76 | return (std::abs(catapult_.estimated_position() - |
| 77 | catapult_.unprofiled_goal(0, 0)) < 0.05 && |
| 78 | std::abs(catapult_.estimated_velocity()) < 0.5); |
| 79 | } |
| 80 | |
| 81 | aos::Fetcher<frc971::control_loops::drivetrain::Status> |
| 82 | drivetrain_status_fetcher_; |
| 83 | |
| 84 | aos::Fetcher<y2024::control_loops::superstructure::CANPosition> |
| 85 | superstructure_can_position_fetcher_; |
| 86 | |
| 87 | const Constants *robot_constants_; |
| 88 | |
| 89 | CatapultSubsystem catapult_; |
| 90 | |
| 91 | PotAndAbsoluteEncoderSubsystem turret_; |
| 92 | PotAndAbsoluteEncoderSubsystem altitude_; |
| 93 | |
| 94 | Aimer aimer_; |
| 95 | |
| 96 | frc971::shooter_interpolation::InterpolationTable< |
| 97 | y2024::constants::Values::ShotParams> |
| 98 | interpolation_table_; |
| 99 | |
| 100 | double last_retention_position_; |
| 101 | |
| 102 | aos::monotonic_clock::time_point last_timestamp_{ |
| 103 | aos::monotonic_clock::min_time}; |
| 104 | }; |
| 105 | |
| 106 | } // namespace y2024::control_loops::superstructure |
| 107 | |
| 108 | #endif |