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" |
| 11 | #include "y2022/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 12 | #include "y2022/control_loops/superstructure/catapult/catapult_plant.h" |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 13 | #include "y2022/control_loops/superstructure/climber/climber_plant.h" |
Yash Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 14 | #include "y2022/control_loops/superstructure/intake/intake_plant.h" |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 15 | #include "y2022/control_loops/superstructure/turret/turret_plant.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 16 | |
| 17 | namespace y2022 { |
| 18 | namespace constants { |
| 19 | |
| 20 | struct Values { |
| 21 | static const int kZeroingSampleSize = 200; |
| 22 | |
| 23 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 24 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 25 | return kDrivetrainCyclesPerRevolution() * 4; |
| 26 | } |
James Kuszmaul | c2b2a80 | 2022-02-25 21:59:31 -0800 | [diff] [blame] | 27 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 28 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 29 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 30 | control_loops::drivetrain::kHighOutputRatio / |
| 31 | constants::Values::kDrivetrainEncoderRatio() * |
| 32 | kDrivetrainEncoderCountsPerRevolution(); |
| 33 | } |
James Kuszmaul | 53507e1 | 2022-02-12 18:36:40 -0800 | [diff] [blame] | 34 | |
| 35 | static double DrivetrainEncoderToMeters(int32_t in) { |
| 36 | return ((static_cast<double>(in) / |
| 37 | kDrivetrainEncoderCountsPerRevolution()) * |
| 38 | (2.0 * M_PI)) * |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 39 | kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius; |
Yash Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 40 | } |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 41 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 42 | // Climber |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 43 | static constexpr ::frc971::constants::Range kClimberRange() { |
| 44 | return ::frc971::constants::Range{ |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 45 | .lower_hard = -0.01, .upper_hard = 0.6, .lower = 0.0, .upper = 0.5}; |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 46 | } |
| 47 | static constexpr double kClimberPotMetersPerRevolution() { |
| 48 | return 22 * 0.25 * 0.0254; |
| 49 | } |
| 50 | static constexpr double kClimberPotRatio() { return 1.0; } |
Henry Speiser | 0b9b005 | 2022-03-02 23:07:40 -0800 | [diff] [blame] | 51 | // TODO(milind): figure this out |
| 52 | // Climber position when it's comfortably above the mid rung. |
| 53 | static constexpr double kClimberMidRungHeight() { return 1.0; } |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 54 | |
| 55 | struct PotConstants { |
| 56 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 57 | ::frc971::zeroing::RelativeEncoderZeroingEstimator> |
| 58 | subsystem_params; |
| 59 | double potentiometer_offset; |
| 60 | }; |
| 61 | |
| 62 | PotConstants climber; |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 63 | |
| 64 | // Intake |
| 65 | // two encoders with same gear ratio for intake |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 66 | static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; } |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 67 | |
| 68 | static constexpr double kIntakeEncoderRatio() { |
Austin Schuh | 275f981 | 2022-03-05 14:02:37 -0800 | [diff] [blame] | 69 | return (16.0 / 64.0) * (18.0 / 62.0); |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 72 | static constexpr double kIntakePotRatio() { return 16.0 / 64.0; } |
| 73 | |
| 74 | static constexpr double kMaxIntakeEncoderPulsesPerSecond() { |
| 75 | return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) * |
| 76 | control_loops::superstructure::intake::kOutputRatio / |
| 77 | kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution(); |
| 78 | } |
| 79 | |
| 80 | struct PotAndAbsEncoderConstants { |
| 81 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 82 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 83 | subsystem_params; |
| 84 | double potentiometer_offset; |
| 85 | }; |
| 86 | |
| 87 | PotAndAbsEncoderConstants intake_front; |
| 88 | PotAndAbsEncoderConstants intake_back; |
| 89 | |
| 90 | // TODO (Yash): Constants need to be tuned |
| 91 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 92 | return ::frc971::constants::Range{ |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 93 | .lower_hard = -0.85, // Back Hard |
| 94 | .upper_hard = 1.85, // Front Hard |
| 95 | .lower = -0.400, // Back Soft |
| 96 | .upper = 1.57 // Front Soft |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 97 | }; |
| 98 | } |
| 99 | |
Henry Speiser | 0b9b005 | 2022-03-02 23:07:40 -0800 | [diff] [blame] | 100 | // When the intake is atleast this much out, always spin the rollers |
| 101 | static constexpr double kIntakeSlightlyOutPosition() { |
| 102 | return kIntakeRange().middle(); |
| 103 | } |
| 104 | static constexpr double kIntakeOutPosition() { return 1.24; } |
| 105 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 106 | // Intake rollers |
| 107 | static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; } |
| 108 | static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; } |
| 109 | |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 110 | // Transfer rollers |
| 111 | // Positive voltage means front transfer rollers pull in and back spits out, |
| 112 | // and vice versa |
| 113 | static constexpr double kTransferRollerFrontVoltage() { return 12.0; } |
| 114 | static constexpr double kTransferRollerBackVoltage() { |
| 115 | return -kTransferRollerFrontVoltage(); |
| 116 | } |
| 117 | |
| 118 | // Voltage to wiggle the transfer rollers and keep a ball in. |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 119 | static constexpr double kTransferRollerFrontWiggleVoltage() { return 3.0; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 120 | static constexpr double kTransferRollerBackWiggleVoltage() { |
| 121 | return -kTransferRollerFrontWiggleVoltage(); |
| 122 | } |
Henry Speiser | 0b9b005 | 2022-03-02 23:07:40 -0800 | [diff] [blame] | 123 | // Minimum roller speed when the intake is slightly out |
| 124 | static constexpr double kMinIntakeSlightlyOutRollerSpeed() { return 6.0; } |
| 125 | // Roller speeds when intake is out |
| 126 | static constexpr double kIntakeOutRollerSpeed() { return 7.0; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 127 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 128 | // Turret |
| 129 | PotAndAbsEncoderConstants turret; |
| 130 | |
| 131 | // TODO (Yash): Constants need to be tuned |
| 132 | static constexpr ::frc971::constants::Range kTurretRange() { |
| 133 | return ::frc971::constants::Range{ |
Austin Schuh | cddd904 | 2022-03-05 17:10:07 -0800 | [diff] [blame] | 134 | .lower_hard = -6.0, // Back Hard |
| 135 | .upper_hard = 4.0, // Front Hard |
| 136 | .lower = -5.0, // Back Soft |
| 137 | .upper = 3.7 // Front Soft |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 138 | }; |
| 139 | } |
| 140 | |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 141 | static constexpr double kTurretBackIntakePos() { return M_PI; } |
| 142 | static constexpr double kTurretFrontIntakePos() { return 0; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 143 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 144 | static constexpr double kTurretPotRatio() { return 27.0 / 110.0; } |
| 145 | static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); } |
| 146 | static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; } |
| 147 | |
| 148 | static constexpr double kMaxTurretEncoderPulsesPerSecond() { |
| 149 | return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) * |
| 150 | control_loops::superstructure::turret::kOutputRatio / |
| 151 | kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution(); |
| 152 | } |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 153 | |
| 154 | // Flipper arms |
milind-u | 37dc40b | 2022-03-08 19:51:27 -0800 | [diff] [blame] | 155 | static constexpr double kFlipperArmSupplyCurrentLimit() { return 40.0; } |
| 156 | static constexpr double kFlipperArmStatorCurrentLimit() { return 60.0; } |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 157 | |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 158 | // Voltage to open the flippers for firing |
| 159 | static constexpr double kFlipperOpenVoltage() { return 3.0; } |
| 160 | // Voltage to keep the flippers open for firing once they already are |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 161 | static constexpr double kFlipperHoldVoltage() { return 2.5; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 162 | // Voltage to feed a ball from the transfer rollers to the catpult with the |
| 163 | // flippers |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 164 | static constexpr double kFlipperFeedVoltage() { return -12.0; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 165 | |
| 166 | // Ball is fed into catapult for atleast this time no matter what |
| 167 | static constexpr std::chrono::milliseconds kExtraLoadingTime() { |
| 168 | return std::chrono::milliseconds(100); |
| 169 | } |
| 170 | // If we have been trying to transfer the ball for this amount of time, it |
| 171 | // probably got lost so abort |
| 172 | static constexpr std::chrono::seconds kBallLostTime() { |
| 173 | return std::chrono::seconds(2); |
| 174 | } |
| 175 | // If the flippers took more than this amount of time to open for firing, |
| 176 | // reseat the ball |
| 177 | static constexpr std::chrono::milliseconds kFlipperOpeningTimeout() { |
milind-u | 37dc40b | 2022-03-08 19:51:27 -0800 | [diff] [blame] | 178 | return std::chrono::milliseconds(1000); |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 179 | } |
| 180 | // Don't use flipper velocity readings more than this amount of time in the |
| 181 | // past |
| 182 | static constexpr std::chrono::milliseconds kFlipperVelocityValidTime() { |
| 183 | return std::chrono::milliseconds(100); |
| 184 | } |
| 185 | |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 186 | // TODO: (Griffin) this needs to be set |
| 187 | static constexpr ::frc971::constants::Range kFlipperArmRange() { |
| 188 | return ::frc971::constants::Range{ |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 189 | .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] | 190 | } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 191 | // Position of the flippers when they are open |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 192 | static constexpr double kFlipperOpenPosition() { return 0.15; } |
Ravago Jones | 5da0635 | 2022-03-04 20:26:24 -0800 | [diff] [blame] | 193 | // If the flippers were open but now moved back, reseat the ball if they go |
| 194 | // below this position |
Austin Schuh | 465a288 | 2022-03-05 15:39:04 -0800 | [diff] [blame] | 195 | static constexpr double kReseatFlipperPosition() { return 0.1; } |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 196 | |
| 197 | static constexpr double kFlipperArmsPotRatio() { return 16.0 / 36.0; } |
| 198 | |
| 199 | PotConstants flipper_arm_left; |
| 200 | PotConstants flipper_arm_right; |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 201 | |
| 202 | // Catapult. |
| 203 | static constexpr double kCatapultPotRatio() { return (12.0 / 33.0); } |
| 204 | static constexpr double kCatapultEncoderRatio() { |
| 205 | return kCatapultPotRatio(); |
| 206 | } |
| 207 | static constexpr double kCatapultEncoderCountsPerRevolution() { |
| 208 | return 4096.0; |
| 209 | } |
Henry Speiser | 0b9b005 | 2022-03-02 23:07:40 -0800 | [diff] [blame] | 210 | static constexpr double kDefaultCatapultShotPosition() { return 3.0; } |
| 211 | static constexpr double kDefaultCatapultShotVelocity() { return 3.0; } |
| 212 | static constexpr double kCatapultReturnPosition() { return -0.85; } |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 213 | |
| 214 | static constexpr double kMaxCatapultEncoderPulsesPerSecond() { |
| 215 | return control_loops::superstructure::catapult::kFreeSpeed / (2.0 * M_PI) * |
| 216 | control_loops::superstructure::catapult::kOutputRatio / |
| 217 | kCatapultEncoderRatio() * kCatapultEncoderCountsPerRevolution(); |
| 218 | } |
| 219 | static constexpr ::frc971::constants::Range kCatapultRange() { |
| 220 | return ::frc971::constants::Range{ |
Milind Upadhyay | 47e0d03 | 2022-03-05 23:06:25 -0800 | [diff] [blame] | 221 | .lower_hard = -1.0, |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 222 | .upper_hard = 2.0, |
milind-u | 37dc40b | 2022-03-08 19:51:27 -0800 | [diff] [blame] | 223 | .lower = -0.91, |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 224 | .upper = 1.57, |
| 225 | }; |
| 226 | } |
| 227 | |
| 228 | PotAndAbsEncoderConstants catapult; |
milind-u | cafdd5d | 2022-03-01 19:58:57 -0800 | [diff] [blame] | 229 | |
| 230 | // TODO(milind): set this |
| 231 | static constexpr double kImuHeight() { return 0.0; } |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 232 | }; |
| 233 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 234 | // Creates and returns a Values instance for the constants. |
| 235 | // Should be called before realtime because this allocates memory. |
| 236 | // Only the first call to either of these will be used. |
| 237 | Values MakeValues(uint16_t team); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 238 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 239 | // Calls MakeValues with aos::network::GetTeamNumber() |
| 240 | Values MakeValues(); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 241 | |
| 242 | } // namespace constants |
| 243 | } // namespace y2022 |
| 244 | |
| 245 | #endif // Y2022_CONSTANTS_H_ |