blob: 98ebb2fba3bf87db32c19d98c6d2995e62eac9b9 [file] [log] [blame]
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -08001#ifndef y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_
2#define y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_
3
4#include "aos/flatbuffers.h"
Philipp Schrader790cb542023-07-05 21:06:52 -07005#include "frc971/control_loops/aiming/aiming.h"
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -08006#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
James Kuszmaula53c3ac2020-02-22 19:36:01 -08007#include "frc971/control_loops/pose.h"
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -08008#include "frc971/control_loops/profiled_subsystem_generated.h"
James Kuszmaul7077d342021-06-09 20:23:58 -07009#include "frc971/input/joystick_state_generated.h"
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080010#include "y2020/control_loops/superstructure/superstructure_status_generated.h"
11
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080012namespace y2020::control_loops::superstructure::turret {
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080013
James Kuszmaula53c3ac2020-02-22 19:36:01 -080014// Returns the port that we want to score on given our current alliance. The yaw
15// of the port will be such that the positive x axis points out the back of the
16// target.
17frc971::control_loops::Pose InnerPortPose(aos::Alliance alliance);
18frc971::control_loops::Pose OuterPortPose(aos::Alliance alliance);
19
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080020// This class manages taking in drivetrain status messages and generating turret
21// goals so that it gets aimed at the goal.
22class Aimer {
23 public:
24 typedef frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal
25 Goal;
26 typedef frc971::control_loops::drivetrain::Status Status;
James Kuszmaulb83d6e12020-02-22 20:44:48 -080027 // Mode to run the aimer in, to control how we manage wrapping the turret
28 // angle.
James Kuszmaul3b393d72020-02-26 19:43:51 -080029 enum class WrapMode {
James Kuszmaulb83d6e12020-02-22 20:44:48 -080030 // Keep the turret as far away from the edges of the range of motion as
31 // reasonable, to minimize the odds that we will hit the hardstops once we
32 // start shooting.
33 kAvoidEdges,
34 // Do everything reasonable to avoid having to wrap the shooter--set this
35 // while shooting so that we don't randomly spin the shooter 360 while
36 // shooting.
37 kAvoidWrapping,
38 };
James Kuszmaul3b393d72020-02-26 19:43:51 -080039
James Kuszmaul851b3962022-02-27 16:42:15 -080040 typedef frc971::control_loops::aiming::ShotMode ShotMode;
James Kuszmaul3b393d72020-02-26 19:43:51 -080041
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080042 Aimer();
James Kuszmaul3b393d72020-02-26 19:43:51 -080043
44 void Update(const Status *status, aos::Alliance alliance, WrapMode wrap_mode,
45 ShotMode shot_mode);
46
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080047 const Goal *TurretGoal() const { return &goal_.message(); }
James Kuszmaul3b393d72020-02-26 19:43:51 -080048
James Kuszmaula53c3ac2020-02-22 19:36:01 -080049 // Returns the distance to the goal, in meters.
James Kuszmaul519585d2020-03-08 22:32:48 -070050 double DistanceToGoal() const { return shot_distance_; }
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080051
52 flatbuffers::Offset<AimerStatus> PopulateStatus(
53 flatbuffers::FlatBufferBuilder *fbb) const;
54
55 private:
56 aos::FlatbufferDetachedBuffer<Goal> goal_;
James Kuszmaula53c3ac2020-02-22 19:36:01 -080057 bool aiming_for_inner_port_ = false;
James Kuszmaul519585d2020-03-08 22:32:48 -070058 // Distance of the shot to the virtual target, used for calculating hood
59 // position and shooter speed.
James Kuszmaul7077d342021-06-09 20:23:58 -070060 double shot_distance_ = 0.0; // meters
James Kuszmaul519585d2020-03-08 22:32:48 -070061 // Real-world distance to the target.
Philipp Schrader790cb542023-07-05 21:06:52 -070062 double target_distance_ = 0.0; // meters
James Kuszmaul88c5cef2021-10-23 13:17:36 -070063 double inner_port_angle_ = 0.0; // radians
Austin Schuh9b2c3342023-02-05 11:31:25 -080064
65 Eigen::Matrix<double, 2, 2> Tlr_to_la_;
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080066};
67
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080068} // namespace y2020::control_loops::superstructure::turret
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080069#endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_