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" |
| 11 | #include "y2024/constants.h" |
| 12 | #include "y2024/constants/constants_generated.h" |
| 13 | #include "y2024/control_loops/drivetrain/drivetrain_base.h" |
Filip Kujawa | 1286c01 | 2024-03-31 22:53:27 -0700 | [diff] [blame] | 14 | #include "y2024/control_loops/superstructure/superstructure_goal_generated.h" |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 15 | #include "y2024/control_loops/superstructure/superstructure_status_generated.h" |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 16 | using y2024::control_loops::superstructure::AimerStatus; |
| 17 | |
| 18 | namespace y2024::control_loops::superstructure { |
| 19 | |
| 20 | class Aimer { |
| 21 | public: |
Austin Schuh | 7cea29d | 2024-03-17 18:20:14 -0700 | [diff] [blame] | 22 | // When the turret is at 0 the note will be leaving the robot at PI. |
James Kuszmaul | b6f3ade | 2024-04-06 16:01:34 -0700 | [diff] [blame^] | 23 | static constexpr double kTurretZeroOffset = 0.11; |
Austin Schuh | 7cea29d | 2024-03-17 18:20:14 -0700 | [diff] [blame] | 24 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 25 | Aimer(aos::EventLoop *event_loop, const Constants *robot_constants); |
| 26 | |
| 27 | void Update( |
| 28 | const frc971::control_loops::drivetrain::Status *status, |
| 29 | frc971::control_loops::aiming::ShotMode shot_mode, |
| 30 | frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoalStatic |
Filip Kujawa | 1286c01 | 2024-03-31 22:53:27 -0700 | [diff] [blame] | 31 | *turret_goal, |
| 32 | AutoAimMode auto_aim_mode); |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 33 | |
| 34 | double DistanceToGoal() const { return current_goal_.virtual_shot_distance; } |
| 35 | |
| 36 | flatbuffers::Offset<AimerStatus> PopulateStatus( |
| 37 | flatbuffers::FlatBufferBuilder *fbb) const; |
| 38 | |
| 39 | private: |
| 40 | aos::EventLoop *event_loop_; |
| 41 | |
| 42 | const Constants *robot_constants_; |
| 43 | |
| 44 | frc971::control_loops::drivetrain::DrivetrainConfig<double> |
| 45 | drivetrain_config_; |
| 46 | |
| 47 | frc971::shooter_interpolation::InterpolationTable< |
| 48 | y2024::constants::Values::ShotParams> |
| 49 | interpolation_table_; |
| 50 | |
Filip Kujawa | 1286c01 | 2024-03-31 22:53:27 -0700 | [diff] [blame] | 51 | frc971::shooter_interpolation::InterpolationTable< |
| 52 | y2024::constants::Values::ShotParams> |
| 53 | interpolation_table_shuttle_; |
| 54 | |
| 55 | std::map<AutoAimMode, frc971::shooter_interpolation::InterpolationTable< |
| 56 | y2024::constants::Values::ShotParams> *> |
| 57 | interpolation_tables_ = { |
| 58 | {AutoAimMode::SPEAKER, &interpolation_table_}, |
| 59 | {AutoAimMode::SHUTTLE, &interpolation_table_shuttle_}}; |
| 60 | |
| 61 | std::map<AutoAimMode, frc971::control_loops::Pose> red_alliance_goals_ = { |
| 62 | {AutoAimMode::SPEAKER, |
| 63 | frc971::control_loops::Pose( |
| 64 | frc971::ToEigenOrDie<3, 1>(*robot_constants_->common() |
| 65 | ->shooter_targets() |
| 66 | ->red_alliance() |
| 67 | ->pos()), |
| 68 | robot_constants_->common() |
| 69 | ->shooter_targets() |
| 70 | ->red_alliance() |
| 71 | ->theta())}, |
| 72 | { |
| 73 | AutoAimMode::SHUTTLE, |
| 74 | frc971::control_loops::Pose( |
| 75 | frc971::ToEigenOrDie<3, 1>(*robot_constants_->common() |
| 76 | ->shooter_shuttle_targets() |
| 77 | ->red_alliance() |
| 78 | ->pos()), |
| 79 | robot_constants_->common() |
| 80 | ->shooter_shuttle_targets() |
| 81 | ->red_alliance() |
| 82 | ->theta()), |
| 83 | }}; |
| 84 | |
| 85 | std::map<AutoAimMode, frc971::control_loops::Pose> blue_alliance_goals_ = { |
| 86 | {AutoAimMode::SPEAKER, |
| 87 | frc971::control_loops::Pose( |
| 88 | frc971::ToEigenOrDie<3, 1>(*robot_constants_->common() |
| 89 | ->shooter_targets() |
| 90 | ->blue_alliance() |
| 91 | ->pos()), |
| 92 | robot_constants_->common() |
| 93 | ->shooter_targets() |
| 94 | ->blue_alliance() |
| 95 | ->theta())}, |
| 96 | { |
| 97 | AutoAimMode::SHUTTLE, |
| 98 | frc971::control_loops::Pose( |
| 99 | frc971::ToEigenOrDie<3, 1>(*robot_constants_->common() |
| 100 | ->shooter_shuttle_targets() |
| 101 | ->blue_alliance() |
| 102 | ->pos()), |
| 103 | robot_constants_->common() |
| 104 | ->shooter_shuttle_targets() |
| 105 | ->blue_alliance() |
| 106 | ->theta()), |
| 107 | }}; |
| 108 | |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 109 | aos::Fetcher<aos::JoystickState> joystick_state_fetcher_; |
| 110 | |
| 111 | frc971::control_loops::aiming::TurretGoal current_goal_; |
James Kuszmaul | 4bd2b4b | 2024-03-16 11:51:55 -0700 | [diff] [blame] | 112 | |
| 113 | bool received_joystick_state_ = false; |
Niko Sohmers | c4d2c50 | 2024-02-19 19:35:35 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace y2024::control_loops::superstructure |
| 117 | #endif // Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |