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