milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 1 | #ifndef Y2022_CONSTANTS_H_ |
| 2 | #define Y2022_CONSTANTS_H_ |
| 3 | |
| 4 | #include <array> |
| 5 | #include <cmath> |
| 6 | #include <cstdint> |
| 7 | |
| 8 | #include "frc971/constants.h" |
| 9 | #include "frc971/control_loops/pose.h" |
| 10 | #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h" |
Ravago Jones | 3283ce0 | 2022-03-09 19:31:29 -0800 | [diff] [blame] | 11 | #include "frc971/shooter_interpolation/interpolation.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 12 | #include "y2022/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 13 | #include "y2022/control_loops/superstructure/catapult/catapult_plant.h" |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 14 | #include "y2022/control_loops/superstructure/climber/climber_plant.h" |
Yash Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 15 | #include "y2022/control_loops/superstructure/intake/intake_plant.h" |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 16 | #include "y2022/control_loops/superstructure/turret/turret_plant.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 17 | |
Ravago Jones | 3283ce0 | 2022-03-09 19:31:29 -0800 | [diff] [blame] | 18 | using ::frc971::shooter_interpolation::InterpolationTable; |
| 19 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 20 | namespace y2022 { |
| 21 | namespace constants { |
| 22 | |
Milind Upadhyay | c76bb4c | 2022-09-21 09:31:48 -0700 | [diff] [blame] | 23 | constexpr uint16_t kCompTeamNumber = 971; |
| 24 | constexpr uint16_t kPracticeTeamNumber = 9971; |
| 25 | constexpr uint16_t kCodingRobotTeamNumber = 7971; |
| 26 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 27 | struct Values { |
| 28 | static const int kZeroingSampleSize = 200; |
| 29 | |
| 30 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 31 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 32 | return kDrivetrainCyclesPerRevolution() * 4; |
| 33 | } |
James Kuszmaul | c2b2a80 | 2022-02-25 21:59:31 -0800 | [diff] [blame] | 34 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 35 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 36 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 37 | control_loops::drivetrain::kHighOutputRatio / |
| 38 | constants::Values::kDrivetrainEncoderRatio() * |
| 39 | kDrivetrainEncoderCountsPerRevolution(); |
| 40 | } |
James Kuszmaul | 53507e1 | 2022-02-12 18:36:40 -0800 | [diff] [blame] | 41 | |
| 42 | static double DrivetrainEncoderToMeters(int32_t in) { |
| 43 | return ((static_cast<double>(in) / |
| 44 | kDrivetrainEncoderCountsPerRevolution()) * |
| 45 | (2.0 * M_PI)) * |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 46 | kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius; |
Yash Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 47 | } |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 48 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 49 | // Climber |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 50 | static constexpr ::frc971::constants::Range kClimberRange() { |
Milind Upadhyay | e9075d1 | 2022-04-12 22:45:16 -0700 | [diff] [blame] | 51 | return ::frc971::constants::Range{.lower_hard = -0.01, |
| 52 | .upper_hard = 0.59, |
| 53 | .lower = 0.003, |
| 54 | .upper = 0.555}; |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 55 | } |
| 56 | static constexpr double kClimberPotMetersPerRevolution() { |
| 57 | return 22 * 0.25 * 0.0254; |
| 58 | } |
| 59 | static constexpr double kClimberPotRatio() { return 1.0; } |
| 60 | |
Nathan Leong | 342b85e | 2023-01-08 13:49:33 -0800 | [diff] [blame] | 61 | static constexpr double kClimberPotMetersPerVolt() { |
| 62 | return kClimberPotRatio() * (5.0 /*turns*/ / 5.0 /*volts*/) * |
| 63 | kClimberPotMetersPerRevolution(); |
| 64 | } |
| 65 | |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 66 | struct PotConstants { |
| 67 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 68 | ::frc971::zeroing::RelativeEncoderZeroingEstimator> |
| 69 | subsystem_params; |
| 70 | double potentiometer_offset; |
| 71 | }; |
| 72 | |
| 73 | PotConstants climber; |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 74 | |
| 75 | // Intake |
| 76 | // two encoders with same gear ratio for intake |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 77 | static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; } |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 78 | |
| 79 | static constexpr double kIntakeEncoderRatio() { |
Austin Schuh | 275f981 | 2022-03-05 14:02:37 -0800 | [diff] [blame] | 80 | return (16.0 / 64.0) * (18.0 / 62.0); |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 83 | static constexpr double kIntakePotRatio() { return 16.0 / 64.0; } |
| 84 | |
Nathan Leong | 342b85e | 2023-01-08 13:49:33 -0800 | [diff] [blame] | 85 | static constexpr double kIntakePotRadiansPerVolt() { |
| 86 | return kIntakePotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) * |
| 87 | (2 * M_PI /*radians*/); |
| 88 | } |
| 89 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 90 | static constexpr double kMaxIntakeEncoderPulsesPerSecond() { |
| 91 | return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) * |
| 92 | control_loops::superstructure::intake::kOutputRatio / |
| 93 | kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution(); |
| 94 | } |
| 95 | |
| 96 | struct PotAndAbsEncoderConstants { |
| 97 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 98 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 99 | subsystem_params; |
| 100 | double potentiometer_offset; |
| 101 | }; |
| 102 | |
| 103 | PotAndAbsEncoderConstants intake_front; |
| 104 | PotAndAbsEncoderConstants intake_back; |
| 105 | |
| 106 | // TODO (Yash): Constants need to be tuned |
| 107 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 108 | return ::frc971::constants::Range{ |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 109 | .lower_hard = -0.85, // Back Hard |
| 110 | .upper_hard = 1.85, // Front Hard |
| 111 | .lower = -0.400, // Back Soft |
| 112 | .upper = 1.57 // Front Soft |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 113 | }; |
| 114 | } |
| 115 | |
| 116 | // Intake rollers |
| 117 | static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; } |
| 118 | static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; } |
| 119 | |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 120 | // Transfer rollers |
Milind Upadhyay | b1a74ea | 2022-03-09 20:34:35 -0800 | [diff] [blame] | 121 | static constexpr double kTransferRollerVoltage() { return 12.0; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 122 | |
| 123 | // Voltage to wiggle the transfer rollers and keep a ball in. |
Milind Upadhyay | b1a74ea | 2022-03-09 20:34:35 -0800 | [diff] [blame] | 124 | static constexpr double kTransferRollerWiggleVoltage() { return 3.0; } |
| 125 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 126 | // Turret |
| 127 | PotAndAbsEncoderConstants turret; |
Milind Upadhyay | e9075d1 | 2022-04-12 22:45:16 -0700 | [diff] [blame] | 128 | frc971::constants::Range turret_range; |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 129 | |
Austin Schuh | 42d7e5f | 2022-03-16 23:35:09 -0700 | [diff] [blame] | 130 | static constexpr double kTurretBackIntakePos() { return -M_PI; } |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 131 | static constexpr double kTurretFrontIntakePos() { return 0; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 132 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 133 | static constexpr double kTurretPotRatio() { return 27.0 / 110.0; } |
Nathan Leong | 342b85e | 2023-01-08 13:49:33 -0800 | [diff] [blame] | 134 | static constexpr double kTurretPotRadiansPerVolt() { |
| 135 | return kTurretPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) * |
| 136 | (2 * M_PI /*radians*/); |
| 137 | } |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 138 | static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); } |
| 139 | static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; } |
| 140 | |
| 141 | static constexpr double kMaxTurretEncoderPulsesPerSecond() { |
| 142 | return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) * |
| 143 | control_loops::superstructure::turret::kOutputRatio / |
| 144 | kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution(); |
| 145 | } |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 146 | |
| 147 | // Flipper arms |
milind-u | 37dc40b | 2022-03-08 19:51:27 -0800 | [diff] [blame] | 148 | static constexpr double kFlipperArmSupplyCurrentLimit() { return 40.0; } |
| 149 | static constexpr double kFlipperArmStatorCurrentLimit() { return 60.0; } |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 150 | |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 151 | // Voltage to open the flippers for firing |
| 152 | static constexpr double kFlipperOpenVoltage() { return 3.0; } |
| 153 | // Voltage to keep the flippers open for firing once they already are |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 154 | static constexpr double kFlipperHoldVoltage() { return 2.5; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 155 | // Voltage to feed a ball from the transfer rollers to the catpult with the |
| 156 | // flippers |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 157 | static constexpr double kFlipperFeedVoltage() { return -12.0; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 158 | |
| 159 | // Ball is fed into catapult for atleast this time no matter what |
| 160 | static constexpr std::chrono::milliseconds kExtraLoadingTime() { |
| 161 | return std::chrono::milliseconds(100); |
| 162 | } |
| 163 | // If we have been trying to transfer the ball for this amount of time, it |
| 164 | // probably got lost so abort |
| 165 | static constexpr std::chrono::seconds kBallLostTime() { |
| 166 | return std::chrono::seconds(2); |
| 167 | } |
| 168 | // If the flippers took more than this amount of time to open for firing, |
| 169 | // reseat the ball |
| 170 | static constexpr std::chrono::milliseconds kFlipperOpeningTimeout() { |
milind-u | 37dc40b | 2022-03-08 19:51:27 -0800 | [diff] [blame] | 171 | return std::chrono::milliseconds(1000); |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 172 | } |
| 173 | // Don't use flipper velocity readings more than this amount of time in the |
| 174 | // past |
| 175 | static constexpr std::chrono::milliseconds kFlipperVelocityValidTime() { |
| 176 | return std::chrono::milliseconds(100); |
| 177 | } |
| 178 | |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 179 | // TODO: (Griffin) this needs to be set |
| 180 | static constexpr ::frc971::constants::Range kFlipperArmRange() { |
| 181 | return ::frc971::constants::Range{ |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 182 | .lower_hard = -0.01, .upper_hard = 0.4, .lower = 0.0, .upper = 0.5}; |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 183 | } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 184 | // Position of the flippers when they are open |
Austin Schuh | 6b1e4d9 | 2022-03-12 12:02:46 -0800 | [diff] [blame] | 185 | static constexpr double kFlipperOpenPosition() { return 0.20; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 186 | // If the flippers were open but now moved back, reseat the ball if they go |
| 187 | // below this position |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 188 | static constexpr double kReseatFlipperPosition() { return 0.1; } |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 189 | |
| 190 | static constexpr double kFlipperArmsPotRatio() { return 16.0 / 36.0; } |
| 191 | |
Nathan Leong | 342b85e | 2023-01-08 13:49:33 -0800 | [diff] [blame] | 192 | static constexpr double kFlipperArmsPotRadiansPerVolt() { |
| 193 | return kFlipperArmsPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) * |
| 194 | (2 * M_PI /*radians*/); |
| 195 | } |
| 196 | |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 197 | PotConstants flipper_arm_left; |
| 198 | PotConstants flipper_arm_right; |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 199 | |
| 200 | // Catapult. |
| 201 | static constexpr double kCatapultPotRatio() { return (12.0 / 33.0); } |
| 202 | static constexpr double kCatapultEncoderRatio() { |
| 203 | return kCatapultPotRatio(); |
| 204 | } |
| 205 | static constexpr double kCatapultEncoderCountsPerRevolution() { |
| 206 | return 4096.0; |
| 207 | } |
| 208 | |
| 209 | static constexpr double kMaxCatapultEncoderPulsesPerSecond() { |
| 210 | return control_loops::superstructure::catapult::kFreeSpeed / (2.0 * M_PI) * |
| 211 | control_loops::superstructure::catapult::kOutputRatio / |
| 212 | kCatapultEncoderRatio() * kCatapultEncoderCountsPerRevolution(); |
| 213 | } |
| 214 | static constexpr ::frc971::constants::Range kCatapultRange() { |
| 215 | return ::frc971::constants::Range{ |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 216 | .lower_hard = -1.0, |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 217 | .upper_hard = 2.0, |
milind-u | 37dc40b | 2022-03-08 19:51:27 -0800 | [diff] [blame] | 218 | .lower = -0.91, |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 219 | .upper = 1.57, |
| 220 | }; |
| 221 | } |
| 222 | |
| 223 | PotAndAbsEncoderConstants catapult; |
milind-u | cafdd5d | 2022-03-01 19:58:57 -0800 | [diff] [blame] | 224 | |
| 225 | // TODO(milind): set this |
| 226 | static constexpr double kImuHeight() { return 0.0; } |
Ravago Jones | 3283ce0 | 2022-03-09 19:31:29 -0800 | [diff] [blame] | 227 | |
| 228 | struct ShotParams { |
| 229 | // Measured in radians |
| 230 | double shot_angle; |
| 231 | // Muzzle velocity (m/s) of the ball as it is released from the catapult. |
| 232 | double shot_velocity; |
| 233 | |
| 234 | static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2) { |
| 235 | using ::frc971::shooter_interpolation::Blend; |
| 236 | return ShotParams{ |
James Kuszmaul | b9ba9a5 | 2022-03-31 22:16:01 -0700 | [diff] [blame] | 237 | .shot_angle = Blend(coefficient, a1.shot_angle, a2.shot_angle), |
| 238 | .shot_velocity = |
| 239 | Blend(coefficient, a1.shot_velocity, a2.shot_velocity), |
Ravago Jones | 3283ce0 | 2022-03-09 19:31:29 -0800 | [diff] [blame] | 240 | }; |
| 241 | } |
| 242 | }; |
| 243 | |
James Kuszmaul | b9ba9a5 | 2022-03-31 22:16:01 -0700 | [diff] [blame] | 244 | struct ShotVelocityParams { |
| 245 | // Speed over ground to use for shooting-on-the-fly. |
| 246 | double shot_speed_over_ground; |
| 247 | |
| 248 | static ShotVelocityParams BlendY(double coefficient, ShotVelocityParams a1, |
| 249 | ShotVelocityParams a2) { |
| 250 | using ::frc971::shooter_interpolation::Blend; |
| 251 | return ShotVelocityParams{Blend(coefficient, a1.shot_speed_over_ground, |
| 252 | a2.shot_speed_over_ground)}; |
| 253 | } |
| 254 | }; |
| 255 | |
Ravago Jones | 3283ce0 | 2022-03-09 19:31:29 -0800 | [diff] [blame] | 256 | InterpolationTable<ShotParams> shot_interpolation_table; |
James Kuszmaul | b9ba9a5 | 2022-03-31 22:16:01 -0700 | [diff] [blame] | 257 | |
| 258 | InterpolationTable<ShotVelocityParams> shot_velocity_interpolation_table; |
Milind Upadhyay | c76bb4c | 2022-09-21 09:31:48 -0700 | [diff] [blame] | 259 | |
| 260 | struct BallColorParams { |
| 261 | // Rects stored as {x, y, width, height} |
| 262 | std::array<int, 4> reference_red; |
| 263 | std::array<int, 4> reference_blue; |
| 264 | std::array<int, 4> ball_location; |
| 265 | }; |
| 266 | |
| 267 | BallColorParams ball_color; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 268 | }; |
| 269 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 270 | // Creates and returns a Values instance for the constants. |
| 271 | // Should be called before realtime because this allocates memory. |
| 272 | // Only the first call to either of these will be used. |
| 273 | Values MakeValues(uint16_t team); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 274 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 275 | // Calls MakeValues with aos::network::GetTeamNumber() |
| 276 | Values MakeValues(); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 277 | |
| 278 | } // namespace constants |
| 279 | } // namespace y2022 |
| 280 | |
| 281 | #endif // Y2022_CONSTANTS_H_ |