Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 1 | #ifndef Y2023_CONSTANTS_H_ |
| 2 | #define Y2023_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" |
James Kuszmaul | ec635d2 | 2023-08-12 18:39:24 -0700 | [diff] [blame] | 11 | #include "frc971/zeroing/absolute_encoder.h" |
| 12 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 13 | #include "y2023/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 14 | #include "y2023/control_loops/superstructure/arm/arm_constants.h" |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 15 | #include "y2023/control_loops/superstructure/roll/roll_plant.h" |
| 16 | #include "y2023/control_loops/superstructure/wrist/wrist_plant.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 17 | |
| 18 | namespace y2023 { |
| 19 | namespace constants { |
| 20 | |
| 21 | constexpr uint16_t kCompTeamNumber = 971; |
| 22 | constexpr uint16_t kPracticeTeamNumber = 9971; |
| 23 | constexpr uint16_t kCodingRobotTeamNumber = 7971; |
| 24 | |
| 25 | struct Values { |
| 26 | static const int kZeroingSampleSize = 200; |
| 27 | |
milind-u | 32d29d3 | 2023-02-24 21:11:51 -0800 | [diff] [blame] | 28 | static const int kSuperstructureCANWriterPriority = 35; |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 29 | static const int kDrivetrainWriterPriority = 35; |
| 30 | static const int kDrivetrainTxPriority = 36; |
| 31 | static const int kDrivetrainRxPriority = 36; |
| 32 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 33 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 34 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 35 | return kDrivetrainCyclesPerRevolution() * 4; |
| 36 | } |
| 37 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
| 38 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 39 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 40 | control_loops::drivetrain::kHighOutputRatio / |
| 41 | constants::Values::kDrivetrainEncoderRatio() * |
| 42 | kDrivetrainEncoderCountsPerRevolution(); |
| 43 | } |
| 44 | |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 45 | static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; } |
Austin Schuh | e70cdeb | 2023-02-23 21:45:00 -0800 | [diff] [blame] | 46 | static constexpr double kDrivetrainStatorCurrentLimit() { return 60.0; } |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 47 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 48 | static double DrivetrainEncoderToMeters(int32_t in) { |
| 49 | return ((static_cast<double>(in) / |
| 50 | kDrivetrainEncoderCountsPerRevolution()) * |
| 51 | (2.0 * M_PI)) * |
| 52 | kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius; |
| 53 | } |
| 54 | |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 55 | static double DrivetrainCANEncoderToMeters(double rotations) { |
| 56 | return (rotations * (2.0 * M_PI)) * |
Maxwell Henderson | f1cfe7f | 2023-12-26 10:48:26 -0800 | [diff] [blame^] | 57 | control_loops::drivetrain::kHighOutputRatio; |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 58 | } |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 59 | static constexpr double kProximalEncoderCountsPerRevolution() { |
| 60 | return 4096.0; |
| 61 | } |
| 62 | static constexpr double kProximalEncoderRatio() { return (15.0 / 95.0); } |
| 63 | static constexpr double kMaxProximalEncoderPulsesPerSecond() { |
| 64 | return control_loops::superstructure::arm::kArmConstants.free_speed / |
milind-u | 0a7d28d | 2023-02-20 17:44:37 -0800 | [diff] [blame] | 65 | (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g0 / |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 66 | kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution(); |
| 67 | } |
| 68 | static constexpr double kProximalPotRatio() { |
Austin Schuh | 7dcc49b | 2023-02-21 17:35:10 -0800 | [diff] [blame] | 69 | return (36.0 / 24.0) * (15.0 / 95.0); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 70 | } |
| 71 | |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 72 | static constexpr double kProximalPotRadiansPerVolt() { |
| 73 | return kProximalPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) * |
| 74 | (2 * M_PI /*radians*/); |
| 75 | } |
| 76 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 77 | static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; } |
Austin Schuh | ebf76ee | 2023-02-24 20:34:33 -0800 | [diff] [blame] | 78 | static constexpr double kDistalEncoderRatio() { return (15.0 / 96.0); } |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 79 | static constexpr double kMaxDistalEncoderPulsesPerSecond() { |
| 80 | return control_loops::superstructure::arm::kArmConstants.free_speed / |
milind-u | 0a7d28d | 2023-02-20 17:44:37 -0800 | [diff] [blame] | 81 | (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g1 / |
| 82 | kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution(); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 83 | } |
| 84 | static constexpr double kDistalPotRatio() { |
Austin Schuh | ebf76ee | 2023-02-24 20:34:33 -0800 | [diff] [blame] | 85 | return (36.0 / 24.0) * (15.0 / 96.0); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 86 | } |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 87 | |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 88 | static constexpr double kDistalPotRadiansPerVolt() { |
| 89 | return kDistalPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) * |
| 90 | (2 * M_PI /*radians*/); |
| 91 | } |
| 92 | |
| 93 | // Roll joint |
| 94 | static constexpr double kRollJointEncoderCountsPerRevolution() { |
| 95 | return 4096.0; |
| 96 | } |
| 97 | |
| 98 | static constexpr double kRollJointEncoderRatio() { return (18.0 / 48.0); } |
| 99 | |
| 100 | static constexpr double kRollJointPotRatio() { return (18.0 / 48.0); } |
| 101 | |
| 102 | static constexpr double kRollJointPotRadiansPerVolt() { |
| 103 | return kRollJointPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) * |
| 104 | (2 * M_PI /*radians*/); |
| 105 | } |
| 106 | |
| 107 | static constexpr double kMaxRollJointEncoderPulsesPerSecond() { |
| 108 | return control_loops::superstructure::roll::kFreeSpeed / (2.0 * M_PI) * |
| 109 | control_loops::superstructure::roll::kOutputRatio / |
| 110 | kRollJointEncoderRatio() * kRollJointEncoderCountsPerRevolution(); |
| 111 | } |
| 112 | |
| 113 | static constexpr ::frc971::constants::Range kRollJointRange() { |
| 114 | return ::frc971::constants::Range{ |
| 115 | -1.05, // Back Hard |
| 116 | 1.44, // Front Hard |
| 117 | -0.89, // Back Soft |
| 118 | 1.26 // Front Soft |
| 119 | }; |
| 120 | } |
| 121 | |
| 122 | // Wrist |
| 123 | static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; } |
| 124 | |
Ravago Jones | 8c65c43 | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 125 | static constexpr double kCompWristEncoderRatio() { return 1.0; } |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 126 | static constexpr double kPracticeWristEncoderRatio() { |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 127 | return (24.0 / 36.0) * (36.0 / 60.0); |
| 128 | } |
| 129 | |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 130 | static constexpr double kMaxCompWristEncoderPulsesPerSecond() { |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 131 | return control_loops::superstructure::wrist::kFreeSpeed / (2.0 * M_PI) * |
| 132 | control_loops::superstructure::wrist::kOutputRatio / |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 133 | kCompWristEncoderRatio() * kWristEncoderCountsPerRevolution(); |
| 134 | } |
| 135 | static constexpr double kMaxPracticeWristEncoderPulsesPerSecond() { |
| 136 | return control_loops::superstructure::wrist::kFreeSpeed / (2.0 * M_PI) * |
| 137 | control_loops::superstructure::wrist::kOutputRatio / |
| 138 | kPracticeWristEncoderRatio() * kWristEncoderCountsPerRevolution(); |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 141 | static constexpr ::frc971::constants::Range kCompWristRange() { |
| 142 | return ::frc971::constants::Range{ |
| 143 | .lower_hard = -0.10, // Back Hard |
| 144 | .upper_hard = 4.90, // Front Hard |
| 145 | .lower = 0.0, // Back Soft |
| 146 | .upper = 4.0, // Front Soft |
| 147 | }; |
| 148 | } |
| 149 | |
| 150 | static constexpr ::frc971::constants::Range kPracticeWristRange() { |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 151 | return ::frc971::constants::Range{ |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 152 | .lower_hard = -0.10, // Back Hard |
| 153 | .upper_hard = 2.30, // Front Hard |
| 154 | .lower = 0.0, // Back Soft |
Austin Schuh | 35a7f62 | 2023-02-25 19:00:20 -0800 | [diff] [blame] | 155 | .upper = 2.2, // Front Soft |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 156 | }; |
| 157 | } |
| 158 | |
milind-u | 18934eb | 2023-02-20 16:28:58 -0800 | [diff] [blame] | 159 | // Rollers |
| 160 | static constexpr double kRollerSupplyCurrentLimit() { return 30.0; } |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 161 | static constexpr double kRollerStatorCurrentLimit() { return 100.0; } |
Maxwell Henderson | 589cf27 | 2023-02-22 15:56:40 -0800 | [diff] [blame] | 162 | |
| 163 | // Game object is fed into end effector for at least this time |
| 164 | static constexpr std::chrono::milliseconds kExtraIntakingTime() { |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 165 | return std::chrono::seconds(2); |
Maxwell Henderson | 589cf27 | 2023-02-22 15:56:40 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | // Game object is spit from end effector for at least this time |
| 169 | static constexpr std::chrono::milliseconds kExtraSpittingTime() { |
Austin Schuh | 1f0cc77 | 2023-03-22 20:29:04 -0700 | [diff] [blame] | 170 | return std::chrono::seconds(1); |
Maxwell Henderson | 589cf27 | 2023-02-22 15:56:40 -0800 | [diff] [blame] | 171 | } |
milind-u | 18934eb | 2023-02-20 16:28:58 -0800 | [diff] [blame] | 172 | |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 173 | // if true, tune down all the arm constants for testing. |
Austin Schuh | 7c0a576 | 2023-04-09 14:15:57 -0700 | [diff] [blame] | 174 | static constexpr bool kArmGrannyMode() { return false; } |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 175 | |
| 176 | // the operating voltage. |
| 177 | static constexpr double kArmOperatingVoltage() { |
| 178 | return kArmGrannyMode() ? 6.0 : 12.0; |
| 179 | } |
| 180 | static constexpr double kArmDt() { return 0.00505; } |
| 181 | static constexpr std::chrono::nanoseconds kArmDtDuration() { |
| 182 | return std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 183 | std::chrono::duration<double>(kArmDt())); |
| 184 | } |
| 185 | static constexpr double kArmAlpha0Max() { |
| 186 | return kArmGrannyMode() ? 15.0 : 15.0; |
| 187 | } |
| 188 | static constexpr double kArmAlpha1Max() { |
| 189 | return kArmGrannyMode() ? 10.0 : 10.0; |
| 190 | } |
| 191 | static constexpr double kArmAlpha2Max() { |
| 192 | return kArmGrannyMode() ? 90.0 : 90.0; |
| 193 | } |
| 194 | |
| 195 | static constexpr double kArmVMax() { return kArmGrannyMode() ? 4.0 : 9.5; } |
Austin Schuh | f0db08e | 2023-04-05 19:48:42 -0700 | [diff] [blame] | 196 | static constexpr double kArmPathlessVMax() { return 9.5; } |
| 197 | static constexpr double kArmGotoPathVMax() { return 9.5; } |
Maxwell Henderson | 5c47a46 | 2023-02-25 14:40:44 -0800 | [diff] [blame] | 198 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 199 | struct PotConstants { |
| 200 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 201 | ::frc971::zeroing::RelativeEncoderZeroingEstimator> |
| 202 | subsystem_params; |
| 203 | double potentiometer_offset; |
| 204 | }; |
| 205 | |
| 206 | struct PotAndAbsEncoderConstants { |
| 207 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 208 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 209 | subsystem_params; |
| 210 | double potentiometer_offset; |
| 211 | }; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 212 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 213 | struct AbsEncoderConstants { |
| 214 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 215 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> |
| 216 | subsystem_params; |
| 217 | }; |
| 218 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 219 | struct ArmJointConstants { |
| 220 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
| 221 | double potentiometer_offset; |
| 222 | }; |
| 223 | |
| 224 | ArmJointConstants arm_proximal; |
| 225 | ArmJointConstants arm_distal; |
milind-u | 18a901d | 2023-02-17 21:51:55 -0800 | [diff] [blame] | 226 | ArmJointConstants roll_joint; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 227 | |
Maxwell Henderson | 8ca4456 | 2023-02-23 13:11:51 -0800 | [diff] [blame] | 228 | AbsEncoderConstants wrist; |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 229 | |
| 230 | bool wrist_flipped; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | // Creates and returns a Values instance for the constants. |
| 234 | // Should be called before realtime because this allocates memory. |
| 235 | // Only the first call to either of these will be used. |
| 236 | Values MakeValues(uint16_t team); |
| 237 | |
| 238 | // Calls MakeValues with aos::network::GetTeamNumber() |
| 239 | Values MakeValues(); |
| 240 | |
| 241 | } // namespace constants |
| 242 | } // namespace y2023 |
| 243 | |
| 244 | #endif // Y2023_CONSTANTS_H_ |