James Kuszmaul | 84083f4 | 2022-02-27 17:24:38 -0800 | [diff] [blame] | 1 | #ifndef Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |
| 2 | #define Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |
| 3 | |
| 4 | #include "aos/flatbuffers.h" |
James Kuszmaul | b9ba9a5 | 2022-03-31 22:16:01 -0700 | [diff] [blame] | 5 | #include "frc971/control_loops/aiming/aiming.h" |
James Kuszmaul | 84083f4 | 2022-02-27 17:24:38 -0800 | [diff] [blame] | 6 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
| 7 | #include "frc971/control_loops/pose.h" |
| 8 | #include "frc971/control_loops/profiled_subsystem_generated.h" |
James Kuszmaul | b9ba9a5 | 2022-03-31 22:16:01 -0700 | [diff] [blame] | 9 | #include "y2022/constants.h" |
James Kuszmaul | 84083f4 | 2022-02-27 17:24:38 -0800 | [diff] [blame] | 10 | #include "y2022/control_loops/superstructure/superstructure_status_generated.h" |
| 11 | |
| 12 | namespace y2022::control_loops::superstructure::turret { |
| 13 | |
| 14 | // This class manages taking in drivetrain status messages and generating turret |
| 15 | // goals so that it gets aimed at the goal. |
| 16 | class Aimer { |
| 17 | public: |
| 18 | typedef frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal |
| 19 | Goal; |
| 20 | typedef frc971::control_loops::drivetrain::Status Status; |
| 21 | typedef frc971::control_loops::aiming::ShotMode ShotMode; |
| 22 | |
James Kuszmaul | b9ba9a5 | 2022-03-31 22:16:01 -0700 | [diff] [blame] | 23 | Aimer(std::shared_ptr<const constants::Values> constants); |
James Kuszmaul | 84083f4 | 2022-02-27 17:24:38 -0800 | [diff] [blame] | 24 | |
| 25 | void Update(const Status *status, ShotMode shot_mode); |
| 26 | |
Milind Upadhyay | 27d16d3 | 2022-04-16 13:41:45 -0700 | [diff] [blame] | 27 | void UpdateTurretGoal(double turret_goal) { |
| 28 | goal_.mutable_message()->mutate_unsafe_goal(turret_goal); |
| 29 | } |
James Kuszmaul | 84083f4 | 2022-02-27 17:24:38 -0800 | [diff] [blame] | 30 | const Goal *TurretGoal() const { return &goal_.message(); } |
| 31 | |
| 32 | // Returns the distance to the goal, in meters. |
| 33 | double DistanceToGoal() const { return current_goal_.virtual_shot_distance; } |
| 34 | |
| 35 | flatbuffers::Offset<AimerStatus> PopulateStatus( |
| 36 | flatbuffers::FlatBufferBuilder *fbb) const; |
| 37 | |
| 38 | private: |
James Kuszmaul | b9ba9a5 | 2022-03-31 22:16:01 -0700 | [diff] [blame] | 39 | std::shared_ptr<const constants::Values> constants_; |
James Kuszmaul | 84083f4 | 2022-02-27 17:24:38 -0800 | [diff] [blame] | 40 | aos::FlatbufferDetachedBuffer<Goal> goal_; |
| 41 | frc971::control_loops::aiming::TurretGoal current_goal_; |
| 42 | }; |
| 43 | |
| 44 | } // namespace y2022::control_loops::superstructure::turret |
| 45 | #endif // Y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |