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