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