Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 1 | #ifndef Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_AIMING_H_ |
| 2 | #define Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_AIMING_H_ |
| 3 | |
Filip Kujawa | 1286c01 | 2024-03-31 22:53:27 -0700 | [diff] [blame] | 4 | #include <map> |
| 5 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 6 | #include "frc971/control_loops/aiming/aiming.h" |
| 7 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
| 8 | #include "frc971/control_loops/pose.h" |
| 9 | #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h" |
| 10 | #include "frc971/shooter_interpolation/interpolation.h" |
James Kuszmaul | 73d6888 | 2024-04-07 21:26:17 -0700 | [diff] [blame] | 11 | #include "frc971/zeroing/averager.h" |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 12 | #include "y2024/constants.h" |
| 13 | #include "y2024/constants/constants_generated.h" |
| 14 | #include "y2024/control_loops/drivetrain/drivetrain_base.h" |
James Kuszmaul | 73d6888 | 2024-04-07 21:26:17 -0700 | [diff] [blame] | 15 | #include "y2024/control_loops/superstructure/superstructure_can_position_static.h" |
Filip Kujawa | 1286c01 | 2024-03-31 22:53:27 -0700 | [diff] [blame] | 16 | #include "y2024/control_loops/superstructure/superstructure_goal_generated.h" |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 17 | #include "y2024/control_loops/superstructure/superstructure_status_generated.h" |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 18 | using y2024::control_loops::superstructure::AimerStatus; |
| 19 | |
| 20 | namespace y2024::control_loops::superstructure { |
| 21 | |
| 22 | class Aimer { |
| 23 | public: |
| 24 | Aimer(aos::EventLoop *event_loop, const Constants *robot_constants); |
| 25 | |
| 26 | void Update( |
| 27 | const frc971::control_loops::drivetrain::Status *status, |
| 28 | frc971::control_loops::aiming::ShotMode shot_mode, |
| 29 | frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoalStatic |
Filip Kujawa | 1286c01 | 2024-03-31 22:53:27 -0700 | [diff] [blame] | 30 | *turret_goal, |
| 31 | AutoAimMode auto_aim_mode); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 32 | |
| 33 | double DistanceToGoal() const { return current_goal_.virtual_shot_distance; } |
| 34 | |
James Kuszmaul | 73d6888 | 2024-04-07 21:26:17 -0700 | [diff] [blame] | 35 | // Indicate that we are ready so that we can reset the note current filter to |
| 36 | // avoid taking values from when we were still seating the note. |
| 37 | void IndicateReady() { note_current_average_.Reset(); } |
| 38 | |
| 39 | void latch_note_current(bool latch) { latch_current_ = latch; } |
| 40 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 41 | flatbuffers::Offset<AimerStatus> PopulateStatus( |
| 42 | flatbuffers::FlatBufferBuilder *fbb) const; |
| 43 | |
| 44 | private: |
| 45 | aos::EventLoop *event_loop_; |
| 46 | |
| 47 | const Constants *robot_constants_; |
| 48 | |
James Kuszmaul | 73d6888 | 2024-04-07 21:26:17 -0700 | [diff] [blame] | 49 | bool latch_current_ = false; |
| 50 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 51 | frc971::control_loops::drivetrain::DrivetrainConfig<double> |
| 52 | drivetrain_config_; |
| 53 | |
| 54 | frc971::shooter_interpolation::InterpolationTable< |
| 55 | y2024::constants::Values::ShotParams> |
| 56 | interpolation_table_; |
| 57 | |
Filip Kujawa | 1286c01 | 2024-03-31 22:53:27 -0700 | [diff] [blame] | 58 | frc971::shooter_interpolation::InterpolationTable< |
| 59 | y2024::constants::Values::ShotParams> |
| 60 | interpolation_table_shuttle_; |
| 61 | |
James Kuszmaul | 73d6888 | 2024-04-07 21:26:17 -0700 | [diff] [blame] | 62 | frc971::shooter_interpolation::InterpolationTable< |
| 63 | y2024::constants::Values::NoteParams> |
| 64 | note_interpolation_table_; |
| 65 | |
Filip Kujawa | 1286c01 | 2024-03-31 22:53:27 -0700 | [diff] [blame] | 66 | std::map<AutoAimMode, frc971::shooter_interpolation::InterpolationTable< |
| 67 | y2024::constants::Values::ShotParams> *> |
| 68 | interpolation_tables_ = { |
| 69 | {AutoAimMode::SPEAKER, &interpolation_table_}, |
| 70 | {AutoAimMode::SHUTTLE, &interpolation_table_shuttle_}}; |
| 71 | |
| 72 | std::map<AutoAimMode, frc971::control_loops::Pose> red_alliance_goals_ = { |
| 73 | {AutoAimMode::SPEAKER, |
| 74 | frc971::control_loops::Pose( |
| 75 | frc971::ToEigenOrDie<3, 1>(*robot_constants_->common() |
| 76 | ->shooter_targets() |
| 77 | ->red_alliance() |
| 78 | ->pos()), |
| 79 | robot_constants_->common() |
| 80 | ->shooter_targets() |
| 81 | ->red_alliance() |
| 82 | ->theta())}, |
| 83 | { |
| 84 | AutoAimMode::SHUTTLE, |
| 85 | frc971::control_loops::Pose( |
| 86 | frc971::ToEigenOrDie<3, 1>(*robot_constants_->common() |
| 87 | ->shooter_shuttle_targets() |
| 88 | ->red_alliance() |
| 89 | ->pos()), |
| 90 | robot_constants_->common() |
| 91 | ->shooter_shuttle_targets() |
| 92 | ->red_alliance() |
| 93 | ->theta()), |
| 94 | }}; |
| 95 | |
| 96 | std::map<AutoAimMode, frc971::control_loops::Pose> blue_alliance_goals_ = { |
| 97 | {AutoAimMode::SPEAKER, |
| 98 | frc971::control_loops::Pose( |
| 99 | frc971::ToEigenOrDie<3, 1>(*robot_constants_->common() |
| 100 | ->shooter_targets() |
| 101 | ->blue_alliance() |
| 102 | ->pos()), |
| 103 | robot_constants_->common() |
| 104 | ->shooter_targets() |
| 105 | ->blue_alliance() |
| 106 | ->theta())}, |
| 107 | { |
| 108 | AutoAimMode::SHUTTLE, |
| 109 | frc971::control_loops::Pose( |
| 110 | frc971::ToEigenOrDie<3, 1>(*robot_constants_->common() |
| 111 | ->shooter_shuttle_targets() |
| 112 | ->blue_alliance() |
| 113 | ->pos()), |
| 114 | robot_constants_->common() |
| 115 | ->shooter_shuttle_targets() |
| 116 | ->blue_alliance() |
| 117 | ->theta()), |
| 118 | }}; |
| 119 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 120 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
| 121 | |
James Kuszmaul | 73d6888 | 2024-04-07 21:26:17 -0700 | [diff] [blame] | 122 | frc971::zeroing::Averager<double, 50> note_current_average_; |
| 123 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 124 | frc971::control_loops::aiming::TurretGoal current_goal_; |
James Kuszmaul | 4bd2b4b | 2024-03-16 11:51:55 -0700 | [diff] [blame] | 125 | |
| 126 | bool received_joystick_state_ = false; |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | } // namespace y2024::control_loops::superstructure |
| 130 | #endif // Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |