blob: 5fbbdc6f66ddf4a16aad6f31cec155d798f1d6e3 [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.
31 enum class Mode {
32 // 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 Kuszmaulb1b2d8e2020-02-21 21:11:46 -080041 Aimer();
James Kuszmaulb83d6e12020-02-22 20:44:48 -080042 void Update(const Status *status, aos::Alliance alliance, Mode mode);
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080043 const Goal *TurretGoal() const { return &goal_.message(); }
James Kuszmaula53c3ac2020-02-22 19:36:01 -080044 // Returns the distance to the goal, in meters.
45 double DistanceToGoal() const { return distance_; }
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080046
47 flatbuffers::Offset<AimerStatus> PopulateStatus(
48 flatbuffers::FlatBufferBuilder *fbb) const;
49
50 private:
51 aos::FlatbufferDetachedBuffer<Goal> goal_;
James Kuszmaula53c3ac2020-02-22 19:36:01 -080052 bool aiming_for_inner_port_ = false;
53 double distance_ = 0.0;
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080054};
55
56} // namespace turret
57} // namespace superstructure
58} // namespace control_loops
59} // namespace y2020
60#endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_