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 | |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 26 | static const int kDrivetrainWriterPriority = 35; |
| 27 | static const int kDrivetrainTxPriority = 36; |
| 28 | static const int kDrivetrainRxPriority = 36; |
| 29 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 30 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 31 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 32 | return kDrivetrainCyclesPerRevolution() * 4; |
| 33 | } |
| 34 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
| 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 | } |
| 41 | |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 42 | static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; } |
| 43 | static constexpr double kDrivetrainStatorCurrentLimit() { return 40.0; } |
| 44 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 45 | static double DrivetrainEncoderToMeters(int32_t in) { |
| 46 | return ((static_cast<double>(in) / |
| 47 | kDrivetrainEncoderCountsPerRevolution()) * |
| 48 | (2.0 * M_PI)) * |
| 49 | kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius; |
| 50 | } |
| 51 | |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 52 | static double DrivetrainCANEncoderToMeters(double rotations) { |
| 53 | return (rotations * (2.0 * M_PI)) * |
| 54 | control_loops::drivetrain::kHighOutputRatio * |
| 55 | control_loops::drivetrain::kWheelRadius; |
| 56 | } |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 57 | static constexpr double kProximalEncoderCountsPerRevolution() { |
| 58 | return 4096.0; |
| 59 | } |
| 60 | static constexpr double kProximalEncoderRatio() { return (15.0 / 95.0); } |
| 61 | static constexpr double kMaxProximalEncoderPulsesPerSecond() { |
| 62 | return control_loops::superstructure::arm::kArmConstants.free_speed / |
| 63 | (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g1 / |
| 64 | kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution(); |
| 65 | } |
| 66 | static constexpr double kProximalPotRatio() { |
| 67 | return (24.0 / 36.0) * (24.0 / 58.0) * (15.0 / 95.0); |
| 68 | } |
| 69 | |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 70 | static constexpr double kProximalPotRadiansPerVolt() { |
| 71 | return kProximalPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) * |
| 72 | (2 * M_PI /*radians*/); |
| 73 | } |
| 74 | |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 75 | static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; } |
| 76 | static constexpr double kDistalEncoderRatio() { return (15.0 / 95.0); } |
| 77 | static constexpr double kMaxDistalEncoderPulsesPerSecond() { |
| 78 | return control_loops::superstructure::arm::kArmConstants.free_speed / |
| 79 | (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g2 / |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 80 | kDistalEncoderRatio() * kDistalEncoderCountsPerRevolution(); |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 81 | } |
| 82 | static constexpr double kDistalPotRatio() { |
| 83 | return (24.0 / 36.0) * (18.0 / 66.0) * (15.0 / 95.0); |
| 84 | } |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 85 | |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 86 | static constexpr double kDistalPotRadiansPerVolt() { |
| 87 | return kDistalPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) * |
| 88 | (2 * M_PI /*radians*/); |
| 89 | } |
| 90 | |
| 91 | // Roll joint |
| 92 | static constexpr double kRollJointEncoderCountsPerRevolution() { |
| 93 | return 4096.0; |
| 94 | } |
| 95 | |
| 96 | static constexpr double kRollJointEncoderRatio() { return (18.0 / 48.0); } |
| 97 | |
| 98 | static constexpr double kRollJointPotRatio() { return (18.0 / 48.0); } |
| 99 | |
| 100 | static constexpr double kRollJointPotRadiansPerVolt() { |
| 101 | return kRollJointPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) * |
| 102 | (2 * M_PI /*radians*/); |
| 103 | } |
| 104 | |
| 105 | static constexpr double kMaxRollJointEncoderPulsesPerSecond() { |
| 106 | return control_loops::superstructure::roll::kFreeSpeed / (2.0 * M_PI) * |
| 107 | control_loops::superstructure::roll::kOutputRatio / |
| 108 | kRollJointEncoderRatio() * kRollJointEncoderCountsPerRevolution(); |
| 109 | } |
| 110 | |
| 111 | static constexpr ::frc971::constants::Range kRollJointRange() { |
| 112 | return ::frc971::constants::Range{ |
| 113 | -1.05, // Back Hard |
| 114 | 1.44, // Front Hard |
| 115 | -0.89, // Back Soft |
| 116 | 1.26 // Front Soft |
| 117 | }; |
| 118 | } |
| 119 | |
| 120 | // Wrist |
| 121 | static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; } |
| 122 | |
| 123 | static constexpr double kWristEncoderRatio() { |
| 124 | return (24.0 / 36.0) * (36.0 / 60.0); |
| 125 | } |
| 126 | |
| 127 | static constexpr double kMaxWristEncoderPulsesPerSecond() { |
| 128 | return control_loops::superstructure::wrist::kFreeSpeed / (2.0 * M_PI) * |
| 129 | control_loops::superstructure::wrist::kOutputRatio / |
| 130 | kWristEncoderRatio() * kWristEncoderCountsPerRevolution(); |
| 131 | } |
| 132 | |
| 133 | static constexpr ::frc971::constants::Range kWristRange() { |
| 134 | return ::frc971::constants::Range{ |
| 135 | -1.05, // Back Hard |
| 136 | 1.44, // Front Hard |
| 137 | -0.89, // Back Soft |
| 138 | 1.26 // Front Soft |
| 139 | }; |
| 140 | } |
| 141 | |
milind-u | 18934eb | 2023-02-20 16:28:58 -0800 | [diff] [blame^] | 142 | // Rollers |
| 143 | static constexpr double kRollerSupplyCurrentLimit() { return 30.0; } |
| 144 | static constexpr double kRollerStatorCurrentLimit() { return 60.0; } |
| 145 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 146 | struct PotConstants { |
| 147 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 148 | ::frc971::zeroing::RelativeEncoderZeroingEstimator> |
| 149 | subsystem_params; |
| 150 | double potentiometer_offset; |
| 151 | }; |
| 152 | |
| 153 | struct PotAndAbsEncoderConstants { |
| 154 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 155 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 156 | subsystem_params; |
| 157 | double potentiometer_offset; |
| 158 | }; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 159 | |
| 160 | struct ArmJointConstants { |
| 161 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
| 162 | double potentiometer_offset; |
| 163 | }; |
| 164 | |
| 165 | ArmJointConstants arm_proximal; |
| 166 | ArmJointConstants arm_distal; |
milind-u | 051c700 | 2023-02-20 16:28:18 -0800 | [diff] [blame] | 167 | |
| 168 | PotAndAbsEncoderConstants roll_joint; |
| 169 | |
| 170 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 171 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> |
| 172 | wrist; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | // Creates and returns a Values instance for the constants. |
| 176 | // Should be called before realtime because this allocates memory. |
| 177 | // Only the first call to either of these will be used. |
| 178 | Values MakeValues(uint16_t team); |
| 179 | |
| 180 | // Calls MakeValues with aos::network::GetTeamNumber() |
| 181 | Values MakeValues(); |
| 182 | |
| 183 | } // namespace constants |
| 184 | } // namespace y2023 |
| 185 | |
| 186 | #endif // Y2023_CONSTANTS_H_ |