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; |
James Kuszmaul | b83d6e1 | 2020-02-22 20:44:48 -0800 | [diff] [blame] | 29 | // Mode to run the aimer in, to control how we manage wrapping the turret |
| 30 | // angle. |
James Kuszmaul | 3b393d7 | 2020-02-26 19:43:51 -0800 | [diff] [blame] | 31 | enum class WrapMode { |
James Kuszmaul | b83d6e1 | 2020-02-22 20:44:48 -0800 | [diff] [blame] | 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 Kuszmaul | 3b393d7 | 2020-02-26 19:43:51 -0800 | [diff] [blame] | 41 | |
| 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 Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 51 | Aimer(); |
James Kuszmaul | 3b393d7 | 2020-02-26 19:43:51 -0800 | [diff] [blame] | 52 | |
| 53 | void Update(const Status *status, aos::Alliance alliance, WrapMode wrap_mode, |
| 54 | ShotMode shot_mode); |
| 55 | |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 56 | const Goal *TurretGoal() const { return &goal_.message(); } |
James Kuszmaul | 3b393d7 | 2020-02-26 19:43:51 -0800 | [diff] [blame] | 57 | |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame] | 58 | // Returns the distance to the goal, in meters. |
| 59 | double DistanceToGoal() const { return distance_; } |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 60 | |
| 61 | flatbuffers::Offset<AimerStatus> PopulateStatus( |
| 62 | flatbuffers::FlatBufferBuilder *fbb) const; |
| 63 | |
| 64 | private: |
| 65 | aos::FlatbufferDetachedBuffer<Goal> goal_; |
James Kuszmaul | a53c3ac | 2020-02-22 19:36:01 -0800 | [diff] [blame] | 66 | bool aiming_for_inner_port_ = false; |
| 67 | double distance_ = 0.0; |
James Kuszmaul | b1b2d8e | 2020-02-21 21:11:46 -0800 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // namespace turret |
| 71 | } // namespace superstructure |
| 72 | } // namespace control_loops |
| 73 | } // namespace y2020 |
| 74 | #endif // y2020_CONTROL_LOOPS_SUPERSTRUCTURE_TURRET_AIMING_H_ |