blob: f38113d516f6f0eb52180342e4f48687f49f35a2 [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"
5#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
James Kuszmaula53c3ac2020-02-22 19:36:01 -08006#include "frc971/control_loops/pose.h"
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -08007#include "frc971/control_loops/profiled_subsystem_generated.h"
James Kuszmaul7077d342021-06-09 20:23:58 -07008#include "frc971/input/joystick_state_generated.h"
James Kuszmaul851b3962022-02-27 16:42:15 -08009#include "frc971/control_loops/aiming/aiming.h"
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080010#include "y2020/control_loops/superstructure/superstructure_status_generated.h"
11
12namespace y2020 {
13namespace control_loops {
14namespace superstructure {
15namespace turret {
16
James Kuszmaula53c3ac2020-02-22 19:36:01 -080017// Returns the port that we want to score on given our current alliance. The yaw
18// of the port will be such that the positive x axis points out the back of the
19// target.
20frc971::control_loops::Pose InnerPortPose(aos::Alliance alliance);
21frc971::control_loops::Pose OuterPortPose(aos::Alliance alliance);
22
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080023// This class manages taking in drivetrain status messages and generating turret
24// goals so that it gets aimed at the goal.
25class Aimer {
26 public:
27 typedef frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal
28 Goal;
29 typedef frc971::control_loops::drivetrain::Status Status;
James Kuszmaulb83d6e12020-02-22 20:44:48 -080030 // Mode to run the aimer in, to control how we manage wrapping the turret
31 // angle.
James Kuszmaul3b393d72020-02-26 19:43:51 -080032 enum class WrapMode {
James Kuszmaulb83d6e12020-02-22 20:44:48 -080033 // Keep the turret as far away from the edges of the range of motion as
34 // reasonable, to minimize the odds that we will hit the hardstops once we
35 // start shooting.
36 kAvoidEdges,
37 // Do everything reasonable to avoid having to wrap the shooter--set this
38 // while shooting so that we don't randomly spin the shooter 360 while
39 // shooting.
40 kAvoidWrapping,
41 };
James Kuszmaul3b393d72020-02-26 19:43:51 -080042
James Kuszmaul851b3962022-02-27 16:42:15 -080043 typedef frc971::control_loops::aiming::ShotMode ShotMode;
James Kuszmaul3b393d72020-02-26 19:43:51 -080044
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080045 Aimer();
James Kuszmaul3b393d72020-02-26 19:43:51 -080046
47 void Update(const Status *status, aos::Alliance alliance, WrapMode wrap_mode,
48 ShotMode shot_mode);
49
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080050 const Goal *TurretGoal() const { return &goal_.message(); }
James Kuszmaul3b393d72020-02-26 19:43:51 -080051
James Kuszmaula53c3ac2020-02-22 19:36:01 -080052 // Returns the distance to the goal, in meters.
James Kuszmaul519585d2020-03-08 22:32:48 -070053 double DistanceToGoal() const { return shot_distance_; }
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080054
55 flatbuffers::Offset<AimerStatus> PopulateStatus(
56 flatbuffers::FlatBufferBuilder *fbb) const;
57
58 private:
59 aos::FlatbufferDetachedBuffer<Goal> goal_;
James Kuszmaula53c3ac2020-02-22 19:36:01 -080060 bool aiming_for_inner_port_ = false;
James Kuszmaul519585d2020-03-08 22:32:48 -070061 // Distance of the shot to the virtual target, used for calculating hood
62 // position and shooter speed.
James Kuszmaul7077d342021-06-09 20:23:58 -070063 double shot_distance_ = 0.0; // meters
James Kuszmaul519585d2020-03-08 22:32:48 -070064 // Real-world distance to the target.
65 double target_distance_ = 0.0; // meters
James Kuszmaul88c5cef2021-10-23 13:17:36 -070066 double inner_port_angle_ = 0.0; // radians
Austin Schuh9b2c3342023-02-05 11:31:25 -080067
68 Eigen::Matrix<double, 2, 2> Tlr_to_la_;
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080069};
70
71} // namespace turret
72} // namespace superstructure
73} // namespace control_loops
74} // namespace y2020
75#endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_