blob: 95e5840b6bed222e376f932e8a0d7bc0ba2e8d5f [file] [log] [blame]
Niko Sohmersc4d2c502024-02-19 19:35:35 -08001#ifndef Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_AIMING_H_
2#define Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_AIMING_H_
3
Filip Kujawa1286c012024-03-31 22:53:27 -07004#include <map>
5
Niko Sohmersc4d2c502024-02-19 19:35:35 -08006#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 Kuszmaul73d68882024-04-07 21:26:17 -070011#include "frc971/zeroing/averager.h"
Niko Sohmersc4d2c502024-02-19 19:35:35 -080012#include "y2024/constants.h"
13#include "y2024/constants/constants_generated.h"
14#include "y2024/control_loops/drivetrain/drivetrain_base.h"
James Kuszmaul73d68882024-04-07 21:26:17 -070015#include "y2024/control_loops/superstructure/superstructure_can_position_static.h"
Filip Kujawa1286c012024-03-31 22:53:27 -070016#include "y2024/control_loops/superstructure/superstructure_goal_generated.h"
Niko Sohmersc4d2c502024-02-19 19:35:35 -080017#include "y2024/control_loops/superstructure/superstructure_status_generated.h"
Niko Sohmersc4d2c502024-02-19 19:35:35 -080018using y2024::control_loops::superstructure::AimerStatus;
19
20namespace y2024::control_loops::superstructure {
21
22class 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 Kujawa1286c012024-03-31 22:53:27 -070030 *turret_goal,
31 AutoAimMode auto_aim_mode);
Niko Sohmersc4d2c502024-02-19 19:35:35 -080032
33 double DistanceToGoal() const { return current_goal_.virtual_shot_distance; }
34
James Kuszmaul73d68882024-04-07 21:26:17 -070035 // 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 Sohmersc4d2c502024-02-19 19:35:35 -080041 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 Kuszmaul73d68882024-04-07 21:26:17 -070049 bool latch_current_ = false;
50
Niko Sohmersc4d2c502024-02-19 19:35:35 -080051 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 Kujawa1286c012024-03-31 22:53:27 -070058 frc971::shooter_interpolation::InterpolationTable<
59 y2024::constants::Values::ShotParams>
60 interpolation_table_shuttle_;
61
James Kuszmaul73d68882024-04-07 21:26:17 -070062 frc971::shooter_interpolation::InterpolationTable<
63 y2024::constants::Values::NoteParams>
64 note_interpolation_table_;
65
Filip Kujawa1286c012024-03-31 22:53:27 -070066 std::map<AutoAimMode, frc971::shooter_interpolation::InterpolationTable<
67 y2024::constants::Values::ShotParams> *>
68 interpolation_tables_ = {
69 {AutoAimMode::SPEAKER, &interpolation_table_},
Austin Schuh79903e82024-04-07 23:12:00 -070070 {AutoAimMode::SHUTTLE, &interpolation_table_shuttle_},
71 {AutoAimMode::TURRET_SHUTTLE, &interpolation_table_shuttle_}};
Filip Kujawa1286c012024-03-31 22:53:27 -070072
73 std::map<AutoAimMode, frc971::control_loops::Pose> red_alliance_goals_ = {
74 {AutoAimMode::SPEAKER,
75 frc971::control_loops::Pose(
76 frc971::ToEigenOrDie<3, 1>(*robot_constants_->common()
77 ->shooter_targets()
78 ->red_alliance()
79 ->pos()),
80 robot_constants_->common()
81 ->shooter_targets()
82 ->red_alliance()
83 ->theta())},
84 {
85 AutoAimMode::SHUTTLE,
86 frc971::control_loops::Pose(
87 frc971::ToEigenOrDie<3, 1>(*robot_constants_->common()
88 ->shooter_shuttle_targets()
89 ->red_alliance()
90 ->pos()),
91 robot_constants_->common()
92 ->shooter_shuttle_targets()
93 ->red_alliance()
94 ->theta()),
Austin Schuh79903e82024-04-07 23:12:00 -070095 },
96 {
97 AutoAimMode::TURRET_SHUTTLE,
98 frc971::control_loops::Pose(
99 frc971::ToEigenOrDie<3, 1>(*robot_constants_->common()
100 ->shooter_shuttle_targets()
101 ->red_alliance()
102 ->pos()),
103 robot_constants_->common()
104 ->shooter_shuttle_targets()
105 ->red_alliance()
106 ->theta()),
Filip Kujawa1286c012024-03-31 22:53:27 -0700107 }};
108
109 std::map<AutoAimMode, frc971::control_loops::Pose> blue_alliance_goals_ = {
110 {AutoAimMode::SPEAKER,
111 frc971::control_loops::Pose(
112 frc971::ToEigenOrDie<3, 1>(*robot_constants_->common()
113 ->shooter_targets()
114 ->blue_alliance()
115 ->pos()),
116 robot_constants_->common()
117 ->shooter_targets()
118 ->blue_alliance()
119 ->theta())},
120 {
121 AutoAimMode::SHUTTLE,
122 frc971::control_loops::Pose(
123 frc971::ToEigenOrDie<3, 1>(*robot_constants_->common()
124 ->shooter_shuttle_targets()
125 ->blue_alliance()
126 ->pos()),
127 robot_constants_->common()
128 ->shooter_shuttle_targets()
129 ->blue_alliance()
130 ->theta()),
Austin Schuh79903e82024-04-07 23:12:00 -0700131 },
132 {
133 AutoAimMode::TURRET_SHUTTLE,
134 frc971::control_loops::Pose(
135 frc971::ToEigenOrDie<3, 1>(*robot_constants_->common()
136 ->shooter_shuttle_targets()
137 ->blue_alliance()
138 ->pos()),
139 robot_constants_->common()
140 ->shooter_shuttle_targets()
141 ->blue_alliance()
142 ->theta()),
Filip Kujawa1286c012024-03-31 22:53:27 -0700143 }};
144
Niko Sohmersc4d2c502024-02-19 19:35:35 -0800145 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
146
James Kuszmaul73d68882024-04-07 21:26:17 -0700147 frc971::zeroing::Averager<double, 50> note_current_average_;
148
Niko Sohmersc4d2c502024-02-19 19:35:35 -0800149 frc971::control_loops::aiming::TurretGoal current_goal_;
James Kuszmaul4bd2b4b2024-03-16 11:51:55 -0700150
151 bool received_joystick_state_ = false;
Niko Sohmersc4d2c502024-02-19 19:35:35 -0800152};
153
154} // namespace y2024::control_loops::superstructure
155#endif // Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_