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