Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 1 | #ifndef y2020_CONSTANTS_H_ |
| 2 | #define y2020_CONSTANTS_H_ |
| 3 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 4 | #include <array> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 5 | #include <cmath> |
| 6 | #include <cstdint> |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 7 | |
| 8 | #include "frc971/constants.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 9 | #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h" |
James Kuszmaul | 98154a2 | 2021-04-03 16:09:29 -0700 | [diff] [blame] | 10 | #include "frc971/shooter_interpolation/interpolation.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 11 | #include "y2020/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 12 | #include "y2020/control_loops/superstructure/accelerator/accelerator_plant.h" |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame] | 13 | #include "y2020/control_loops/superstructure/control_panel/control_panel_plant.h" |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 14 | #include "y2020/control_loops/superstructure/finisher/finisher_plant.h" |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 15 | #include "y2020/control_loops/superstructure/hood/hood_plant.h" |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 16 | #include "y2020/control_loops/superstructure/intake/intake_plant.h" |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 17 | #include "y2020/control_loops/superstructure/turret/turret_plant.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 18 | |
James Kuszmaul | 98154a2 | 2021-04-03 16:09:29 -0700 | [diff] [blame] | 19 | using ::frc971::shooter_interpolation::InterpolationTable; |
| 20 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 21 | namespace y2020 { |
| 22 | namespace constants { |
| 23 | |
| 24 | struct Values { |
James Kuszmaul | 0a98140 | 2021-10-09 21:00:34 -0700 | [diff] [blame] | 25 | static const uint16_t kCompTeamNumber = 971; |
| 26 | static const uint16_t kPracticeTeamNumber = 9971; |
Austin Schuh | 83873c3 | 2020-02-22 14:58:39 -0800 | [diff] [blame] | 27 | static const uint16_t kCodingRobotTeamNumber = 7971; |
James Kuszmaul | 0a98140 | 2021-10-09 21:00:34 -0700 | [diff] [blame] | 28 | static const uint16_t kSpareRoborioTeamNumber = 6971; |
Austin Schuh | 83873c3 | 2020-02-22 14:58:39 -0800 | [diff] [blame] | 29 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 30 | static const int kZeroingSampleSize = 200; |
| 31 | |
| 32 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 33 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 34 | return kDrivetrainCyclesPerRevolution() * 4; |
| 35 | } |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 36 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 37 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 38 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 39 | control_loops::drivetrain::kHighGearRatio / |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 40 | constants::Values::kDrivetrainEncoderRatio() * |
| 41 | kDrivetrainEncoderCountsPerRevolution(); |
| 42 | } |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 43 | |
| 44 | // Hood |
| 45 | static constexpr double kHoodEncoderCountsPerRevolution() { return 4096.0; } |
| 46 | |
milind-u | d53408e | 2021-10-21 19:43:58 -0700 | [diff] [blame] | 47 | // TODO: This math is not quite right |
| 48 | // 10.211 in of travel gets you 1 radian on the output |
| 49 | static constexpr double kHoodEncoderRadiansPerInTravel() { |
| 50 | return 1.0 / 10.211; |
| 51 | } |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 52 | |
milind-u | d53408e | 2021-10-21 19:43:58 -0700 | [diff] [blame] | 53 | static constexpr double kHoodEncoderRatio() { |
Austin Schuh | 72a878d | 2021-03-06 20:16:06 -0800 | [diff] [blame] | 54 | // one turn on the leadscrew gets you 0.5 in travel |
| 55 | const double in_travel_per_radian = 0.5 / (2.0 * M_PI); |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 56 | |
| 57 | // units reduce; radians on the encoder * this number = radians on the hood |
milind-u | d53408e | 2021-10-21 19:43:58 -0700 | [diff] [blame] | 58 | return in_travel_per_radian * kHoodEncoderRadiansPerInTravel(); |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static constexpr double kHoodSingleTurnEncoderRatio() { return 8.0 / 72.0; } |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 62 | |
| 63 | static constexpr double kMaxHoodEncoderPulsesPerSecond() { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 64 | return control_loops::superstructure::hood::kFreeSpeed / (2.0 * M_PI) * |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 65 | control_loops::superstructure::hood::kOutputRatio / |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 66 | kHoodEncoderRatio() * kHoodEncoderCountsPerRevolution(); |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static constexpr ::frc971::constants::Range kHoodRange() { |
| 70 | return ::frc971::constants::Range{ |
Austin Schuh | 2efe168 | 2021-03-06 22:47:15 -0800 | [diff] [blame] | 71 | -0.01, // Back Hard |
| 72 | 0.65, // Front Hard |
| 73 | 0.00, // Back Soft |
| 74 | 0.63 // Front Soft |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 75 | }; |
| 76 | } |
| 77 | |
milind-u | d53408e | 2021-10-21 19:43:58 -0700 | [diff] [blame] | 78 | struct HoodGeometry { |
| 79 | // Measurements for hood zeroing calculations (all lengths in meters and |
| 80 | // angles in radians) |
| 81 | |
| 82 | // Measurements when hood is at 0 |
| 83 | double theta_0; |
| 84 | double screw_length_0; |
| 85 | |
| 86 | double radius; |
| 87 | double diagonal_length; |
| 88 | double back_plate_diagonal_length; |
| 89 | }; |
| 90 | |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 91 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 92 | ::frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingEstimator> |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 93 | hood; |
| 94 | |
milind-u | d53408e | 2021-10-21 19:43:58 -0700 | [diff] [blame] | 95 | HoodGeometry hood_geometry; |
| 96 | |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 97 | // Intake |
| 98 | static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; } |
| 99 | |
| 100 | static constexpr double kIntakeEncoderRatio() { return (16.0 / 32.0); } |
| 101 | |
| 102 | static constexpr double kMaxIntakeEncoderPulsesPerSecond() { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 103 | return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) * |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 104 | control_loops::superstructure::intake::kOutputRatio / |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 105 | kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution(); |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 108 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 109 | return ::frc971::constants::Range{ |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 110 | -1.05, // Back Hard |
| 111 | 1.44, // Front Hard |
| 112 | -0.89, // Back Soft |
| 113 | 1.26 // Front Soft |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 114 | }; |
| 115 | } |
| 116 | |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 117 | static constexpr double kIntakeZero() { return -57 * M_PI / 180.0; } |
| 118 | |
Sabina Davis | a587fbd | 2020-01-31 22:11:15 -0800 | [diff] [blame] | 119 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 120 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> |
Sabina Davis | e8d3899 | 2020-02-02 15:00:31 -0800 | [diff] [blame] | 121 | intake; |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 122 | |
Austin Schuh | d0e9e06 | 2021-10-24 17:40:58 -0700 | [diff] [blame^] | 123 | static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; } |
| 124 | static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; } |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 125 | |
Austin Schuh | df240b4 | 2021-10-13 21:33:43 -0700 | [diff] [blame] | 126 | static constexpr double kFeederSupplyCurrentLimit() { return 40.0; } |
| 127 | static constexpr double kFeederStatorCurrentLimit() { return 50.0; } |
Ravago Jones | 3dda560 | 2021-03-10 00:33:13 -0800 | [diff] [blame] | 128 | |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 129 | // Turret |
| 130 | static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; } |
| 131 | |
| 132 | static constexpr double kTurretEncoderRatio() { |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 133 | return (26.0 / 150.0) * (130.0 / 26.0); |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static constexpr double kMaxTurretEncoderPulsesPerSecond() { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 137 | return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) * |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 138 | control_loops::superstructure::turret::kOutputRatio / |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 139 | kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution(); |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 142 | static constexpr double kTurretPotRatio() { return (26.0 / 150.0); } |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 143 | |
| 144 | static constexpr ::frc971::constants::Range kTurretRange() { |
| 145 | return ::frc971::constants::Range{ |
Austin Schuh | d9a1f86 | 2021-10-27 21:29:19 -0700 | [diff] [blame] | 146 | -3.45, // Back Hard |
| 147 | 3.45, // Front Hard |
| 148 | -3.3, // Back Soft |
| 149 | 3.3 // Front Soft |
Kai Tinkess | 10943cf | 2020-02-01 15:49:57 -0800 | [diff] [blame] | 150 | }; |
| 151 | } |
| 152 | |
| 153 | struct PotAndAbsEncoderConstants { |
| 154 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 155 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 156 | subsystem_params; |
| 157 | double potentiometer_offset; |
| 158 | }; |
| 159 | |
| 160 | PotAndAbsEncoderConstants turret; |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame] | 161 | |
| 162 | // Control Panel |
| 163 | |
| 164 | // Mag encoder |
| 165 | static constexpr double kControlPanelEncoderCountsPerRevolution() { |
| 166 | return 4096.0; |
| 167 | } |
| 168 | |
| 169 | // Ratio is encoder to output |
| 170 | static constexpr double kControlPanelEncoderRatio() { return (56.0 / 28.0); } |
| 171 | |
| 172 | static constexpr double kMaxControlPanelEncoderPulsesPerSecond() { |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 173 | return control_loops::superstructure::control_panel::kFreeSpeed / |
| 174 | (2.0 * M_PI) * |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame] | 175 | control_loops::superstructure::control_panel::kOutputRatio / |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 176 | kControlPanelEncoderRatio() * |
ravago | 901c426 | 2020-02-16 15:33:14 -0800 | [diff] [blame] | 177 | kControlPanelEncoderCountsPerRevolution(); |
| 178 | } |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 179 | |
| 180 | // Shooter |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 181 | static constexpr double kFinisherEncoderCountsPerRevolution() { |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 182 | return 2048.0; |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 183 | } |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 184 | static constexpr double kFinisherEncoderRatio() { return 36.0 / 40.0; } |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 185 | |
| 186 | static constexpr double kMaxFinisherEncoderPulsesPerSecond() { |
| 187 | return control_loops::superstructure::finisher::kFreeSpeed / (2.0 * M_PI) * |
| 188 | control_loops::superstructure::finisher::kOutputRatio / |
| 189 | kFinisherEncoderRatio() * kFinisherEncoderCountsPerRevolution(); |
| 190 | } |
| 191 | |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 192 | static constexpr double kAcceleratorEncoderCountsPerRevolution() { |
Sabina Davis | f7afd11 | 2020-02-23 13:42:14 -0800 | [diff] [blame] | 193 | return 2048.0; |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 194 | } |
Austin Schuh | 9dcd520 | 2020-02-20 20:06:04 -0800 | [diff] [blame] | 195 | static constexpr double kAcceleratorEncoderRatio() { |
| 196 | return (1.2 * 1.2 * 1.2) * (30.0 / 40.0); |
| 197 | } |
| 198 | |
| 199 | static constexpr double kMaxAcceleratorEncoderPulsesPerSecond() { |
| 200 | return control_loops::superstructure::accelerator::kFreeSpeed / |
| 201 | (2.0 * M_PI) * |
| 202 | control_loops::superstructure::accelerator::kOutputRatio / |
| 203 | kAcceleratorEncoderRatio() * |
| 204 | kAcceleratorEncoderCountsPerRevolution(); |
| 205 | } |
Alex Perry | c4691f5 | 2020-02-17 19:20:01 -0800 | [diff] [blame] | 206 | |
| 207 | // Climber |
| 208 | static constexpr double kClimberSupplyCurrentLimit() { return 60.0; } |
James Kuszmaul | 98154a2 | 2021-04-03 16:09:29 -0700 | [diff] [blame] | 209 | |
| 210 | struct ShotParams { |
| 211 | // Measured in radians |
| 212 | double hood_angle; |
milind-u | 0a178a8 | 2021-09-28 18:42:09 -0700 | [diff] [blame] | 213 | // Muzzle velocity (m/s) of the ball as it is shot out of the shooter. |
| 214 | double velocity_ball; |
James Kuszmaul | 98154a2 | 2021-04-03 16:09:29 -0700 | [diff] [blame] | 215 | |
| 216 | static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2) { |
| 217 | using ::frc971::shooter_interpolation::Blend; |
milind-u | 0a178a8 | 2021-09-28 18:42:09 -0700 | [diff] [blame] | 218 | return ShotParams{Blend(coefficient, a1.hood_angle, a2.hood_angle), |
| 219 | Blend(coefficient, a1.velocity_ball, a2.velocity_ball)}; |
James Kuszmaul | 98154a2 | 2021-04-03 16:09:29 -0700 | [diff] [blame] | 220 | } |
| 221 | }; |
| 222 | |
milind-u | 0a178a8 | 2021-09-28 18:42:09 -0700 | [diff] [blame] | 223 | struct FlywheelShotParams { |
| 224 | // Angular velocity in radians per second of the slowest (lowest) wheel in |
| 225 | // the kicker. Positive is shooting the ball. |
| 226 | double velocity_accelerator; |
| 227 | // Angular velocity in radians per seconds of the flywheel. Positive is |
| 228 | // shooting. |
| 229 | double velocity_finisher; |
| 230 | |
| 231 | static FlywheelShotParams BlendY(double coefficient, FlywheelShotParams a1, |
| 232 | FlywheelShotParams a2) { |
| 233 | using ::frc971::shooter_interpolation::Blend; |
| 234 | return FlywheelShotParams{ |
| 235 | Blend(coefficient, a1.velocity_accelerator, a2.velocity_accelerator), |
| 236 | Blend(coefficient, a1.velocity_finisher, a2.velocity_finisher)}; |
| 237 | } |
| 238 | }; |
| 239 | |
| 240 | // { distance_to_target, { hood_angle, velocity_ball }} |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 241 | InterpolationTable<ShotParams> shot_interpolation_table; |
milind-u | 0a178a8 | 2021-09-28 18:42:09 -0700 | [diff] [blame] | 242 | // { velocity_ball, { velocity_accelerator, velocity_finisher }} |
| 243 | InterpolationTable<FlywheelShotParams> flywheel_shot_interpolation_table; |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 244 | }; |
| 245 | |
milind-u | 62d4a8e | 2021-10-11 16:08:41 -0700 | [diff] [blame] | 246 | // Creates (once) a Values instance for ::aos::network::GetTeamNumber(). Should |
| 247 | // be called before realtime because this allocates memory. |
| 248 | void InitValues(); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 249 | |
milind-u | 62d4a8e | 2021-10-11 16:08:41 -0700 | [diff] [blame] | 250 | // Returns a reference to the Values instance for |
| 251 | // ::aos::network::GetTeamNumber(). Values must be initialized through |
| 252 | // InitValues() before calling this. |
| 253 | const Values &GetValues(); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 254 | |
| 255 | } // namespace constants |
| 256 | } // namespace y2020 |
| 257 | |
| 258 | #endif // y2020_CONSTANTS_H_ |