James Kuszmaul | 851b396 | 2022-02-27 16:42:15 -0800 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_AIMING_AIMING_H_ |
| 2 | #define FRC971_CONTROL_LOOPS_AIMING_AIMING_H_ |
| 3 | #include "frc971/constants.h" |
| 4 | #include "frc971/control_loops/pose.h" |
| 5 | |
| 6 | // This library provides utilities associated with attempting to aim balls into |
| 7 | // a goal. |
| 8 | |
| 9 | namespace frc971::control_loops::aiming { |
| 10 | |
| 11 | // Control modes for managing how we manage shooting on the fly. |
| 12 | enum class ShotMode { |
| 13 | // Don't do any shooting-on-the-fly compensation--just point straight at the |
| 14 | // target. Primarily used in tests. |
| 15 | kStatic, |
| 16 | // Do do shooting-on-the-fly compensation. |
| 17 | kShootOnTheFly, |
| 18 | }; |
| 19 | |
| 20 | struct TurretGoal { |
| 21 | // Goal position (in radians) for the turret. |
| 22 | double position = 0.0; |
| 23 | // Goal velocity (in radians / sec) for the turret. |
| 24 | double velocity = 0.0; |
| 25 | // Physical distance from the robot's origin to the target we are shooting at, |
| 26 | // in meters. |
| 27 | double target_distance = 0.0; |
| 28 | // Shot distance to use when shooting on the fly (e.g., if driving towards the |
| 29 | // target, we will aim for a shorter shot than the actual physical distance), |
| 30 | // in meters. |
| 31 | double virtual_shot_distance = 0.0; |
| 32 | }; |
| 33 | |
| 34 | struct RobotState { |
| 35 | // Pose of the robot, in the field frame. |
| 36 | Pose pose; |
| 37 | // X/Y components of the robot velocity, in m/s. |
| 38 | Eigen::Vector2d velocity; |
| 39 | // Yaw rate of the robot, in rad / sec. |
| 40 | double yaw_rate; |
| 41 | // Last turret goal that we produced. |
| 42 | double last_turret_goal; |
| 43 | }; |
| 44 | |
| 45 | struct ShotConfig { |
| 46 | // Pose of the goal, in the field frame. |
| 47 | Pose goal; |
| 48 | ShotMode mode; |
| 49 | const constants::Range turret_range; |
| 50 | // We assume that the ball being shot has an ~constant speed over the ground, |
| 51 | // to allow us to estimate shooting-on-the fly values. |
| 52 | double ball_speed_over_ground; |
| 53 | // Amount of buffer to add on each side of the range to prevent wrapping/to |
| 54 | // prevent getting too close to the hard stops. |
| 55 | double anti_wrap_buffer; |
| 56 | // Offset from zero in the robot frame to zero for the turret. |
| 57 | double turret_zero_offset; |
| 58 | }; |
| 59 | |
| 60 | TurretGoal AimerGoal(const ShotConfig &config, const RobotState &state); |
| 61 | } |
| 62 | #endif // FRC971_CONTROL_LOOPS_AIMING_AIMING_H_ |