blob: 3b3071e112909ba844f2728d5c9b0dbf97330d9a [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"
James Kuszmaula53c3ac2020-02-22 19:36:01 -08005#include "aos/robot_state/joystick_state_generated.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"
9#include "y2020/control_loops/superstructure/superstructure_status_generated.h"
10
11namespace y2020 {
12namespace control_loops {
13namespace superstructure {
14namespace turret {
15
James Kuszmaula53c3ac2020-02-22 19:36:01 -080016// Returns the port that we want to score on given our current alliance. The yaw
17// of the port will be such that the positive x axis points out the back of the
18// target.
19frc971::control_loops::Pose InnerPortPose(aos::Alliance alliance);
20frc971::control_loops::Pose OuterPortPose(aos::Alliance alliance);
21
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080022// This class manages taking in drivetrain status messages and generating turret
23// goals so that it gets aimed at the goal.
24class Aimer {
25 public:
26 typedef frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal
27 Goal;
28 typedef frc971::control_loops::drivetrain::Status Status;
James Kuszmaulb83d6e12020-02-22 20:44:48 -080029 // Mode to run the aimer in, to control how we manage wrapping the turret
30 // angle.
James Kuszmaul3b393d72020-02-26 19:43:51 -080031 enum class WrapMode {
James Kuszmaulb83d6e12020-02-22 20:44:48 -080032 // Keep the turret as far away from the edges of the range of motion as
33 // reasonable, to minimize the odds that we will hit the hardstops once we
34 // start shooting.
35 kAvoidEdges,
36 // Do everything reasonable to avoid having to wrap the shooter--set this
37 // while shooting so that we don't randomly spin the shooter 360 while
38 // shooting.
39 kAvoidWrapping,
40 };
James Kuszmaul3b393d72020-02-26 19:43:51 -080041
42 // Control modes for managing how we manage shooting on the fly.
43 enum class ShotMode {
44 // Don't do any shooting-on-the-fly compensation--just point straight at the
45 // target. Primarily used in tests.
46 kStatic,
47 // Do do shooting-on-the-fly compensation.
48 kShootOnTheFly,
49 };
50
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080051 Aimer();
James Kuszmaul3b393d72020-02-26 19:43:51 -080052
53 void Update(const Status *status, aos::Alliance alliance, WrapMode wrap_mode,
54 ShotMode shot_mode);
55
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080056 const Goal *TurretGoal() const { return &goal_.message(); }
James Kuszmaul3b393d72020-02-26 19:43:51 -080057
James Kuszmaula53c3ac2020-02-22 19:36:01 -080058 // Returns the distance to the goal, in meters.
59 double DistanceToGoal() const { return distance_; }
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080060
61 flatbuffers::Offset<AimerStatus> PopulateStatus(
62 flatbuffers::FlatBufferBuilder *fbb) const;
63
64 private:
65 aos::FlatbufferDetachedBuffer<Goal> goal_;
James Kuszmaula53c3ac2020-02-22 19:36:01 -080066 bool aiming_for_inner_port_ = false;
67 double distance_ = 0.0;
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080068};
69
70} // namespace turret
71} // namespace superstructure
72} // namespace control_loops
73} // namespace y2020
74#endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_