blob: 808a17536a7bdb844419595a27da3e2a09991302 [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_},
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 Sohmersc4d2c502024-02-19 19:35:35 -0800120 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
121
James Kuszmaul73d68882024-04-07 21:26:17 -0700122 frc971::zeroing::Averager<double, 50> note_current_average_;
123
Niko Sohmersc4d2c502024-02-19 19:35:35 -0800124 frc971::control_loops::aiming::TurretGoal current_goal_;
James Kuszmaul4bd2b4b2024-03-16 11:51:55 -0700125
126 bool received_joystick_state_ = false;
Niko Sohmersc4d2c502024-02-19 19:35:35 -0800127};
128
129} // namespace y2024::control_loops::superstructure
130#endif // Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_