blob: 675eea3e03f7391c7bc72dcfab313e077be82ba8 [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;
29 Aimer();
James Kuszmaula53c3ac2020-02-22 19:36:01 -080030 void Update(const Status *status, aos::Alliance alliance);
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080031 const Goal *TurretGoal() const { return &goal_.message(); }
James Kuszmaula53c3ac2020-02-22 19:36:01 -080032 // Returns the distance to the goal, in meters.
33 double DistanceToGoal() const { return distance_; }
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080034
35 flatbuffers::Offset<AimerStatus> PopulateStatus(
36 flatbuffers::FlatBufferBuilder *fbb) const;
37
38 private:
39 aos::FlatbufferDetachedBuffer<Goal> goal_;
James Kuszmaula53c3ac2020-02-22 19:36:01 -080040 bool aiming_for_inner_port_ = false;
41 double distance_ = 0.0;
James Kuszmaulb1b2d8e2020-02-21 21:11:46 -080042};
43
44} // namespace turret
45} // namespace superstructure
46} // namespace control_loops
47} // namespace y2020
48#endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_