James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 1 | #ifndef y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |
| 2 | #define y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |
| 3 | |
| 4 | #include "aos/flatbuffers.h" |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame^] | 5 | #include "aos/robot_state/joystick_state_generated.h" |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 6 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame^] | 7 | #include "frc971/control_loops/pose.h" |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 8 | #include "frc971/control_loops/profiled_subsystem_generated.h" |
| 9 | #include "y2020/control_loops/superstructure/superstructure_status_generated.h" |
| 10 | |
| 11 | namespace y2020 { |
| 12 | namespace control_loops { |
| 13 | namespace superstructure { |
| 14 | namespace turret { |
| 15 | |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame^] | 16 | // 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. |
| 19 | frc971::control_loops::Pose InnerPortPose(aos::Alliance alliance); |
| 20 | frc971::control_loops::Pose OuterPortPose(aos::Alliance alliance); |
| 21 | |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 22 | // This class manages taking in drivetrain status messages and generating turret |
| 23 | // goals so that it gets aimed at the goal. |
| 24 | class Aimer { |
| 25 | public: |
| 26 | typedef frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal |
| 27 | Goal; |
| 28 | typedef frc971::control_loops::drivetrain::Status Status; |
| 29 | Aimer(); |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame^] | 30 | void Update(const Status *status, aos::Alliance alliance); |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 31 | const Goal *TurretGoal() const { return &goal_.message(); } |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame^] | 32 | // Returns the distance to the goal, in meters. |
| 33 | double DistanceToGoal() const { return distance_; } |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 34 | |
| 35 | flatbuffers::Offset<AimerStatus> PopulateStatus( |
| 36 | flatbuffers::FlatBufferBuilder *fbb) const; |
| 37 | |
| 38 | private: |
| 39 | aos::FlatbufferDetachedBuffer<Goal> goal_; |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame^] | 40 | bool aiming_for_inner_port_ = false; |
| 41 | double distance_ = 0.0; |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | } // namespace turret |
| 45 | } // namespace superstructure |
| 46 | } // namespace control_loops |
| 47 | } // namespace y2020 |
| 48 | #endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |