blob: de4c117ef1f14369f6995c4c36e3d701700d756a [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"
11#include "y2024/constants.h"
12#include "y2024/constants/constants_generated.h"
13#include "y2024/control_loops/drivetrain/drivetrain_base.h"
Filip Kujawa1286c012024-03-31 22:53:27 -070014#include "y2024/control_loops/superstructure/superstructure_goal_generated.h"
Niko Sohmersc4d2c502024-02-19 19:35:35 -080015#include "y2024/control_loops/superstructure/superstructure_status_generated.h"
Niko Sohmersc4d2c502024-02-19 19:35:35 -080016using y2024::control_loops::superstructure::AimerStatus;
17
18namespace y2024::control_loops::superstructure {
19
20class Aimer {
21 public:
Austin Schuh7cea29d2024-03-17 18:20:14 -070022 // When the turret is at 0 the note will be leaving the robot at PI.
23 static constexpr double kTurretZeroOffset = 0.13;
24
Niko Sohmersc4d2c502024-02-19 19:35:35 -080025 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 Kujawa1286c012024-03-31 22:53:27 -070031 *turret_goal,
32 AutoAimMode auto_aim_mode);
Niko Sohmersc4d2c502024-02-19 19:35:35 -080033
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 Kujawa1286c012024-03-31 22:53:27 -070051 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 Sohmersc4d2c502024-02-19 19:35:35 -0800109 aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
110
111 frc971::control_loops::aiming::TurretGoal current_goal_;
James Kuszmaul4bd2b4b2024-03-16 11:51:55 -0700112
113 bool received_joystick_state_ = false;
Niko Sohmersc4d2c502024-02-19 19:35:35 -0800114};
115
116} // namespace y2024::control_loops::superstructure
117#endif // Y2024_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_