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