Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 1 | #ifndef Y2023_BOT3_CONSTANTS_H_ |
| 2 | #define Y2023_BOT3_CONSTANTS_H_ |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 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" |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 11 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 12 | #include "y2023_bot3/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 13 | #include "y2023_bot3/control_loops/superstructure/pivot_joint/pivot_joint_plant.h" |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 14 | namespace y2023_bot3 { |
| 15 | namespace constants { |
| 16 | |
Maxwell Henderson | 20fa069 | 2023-12-22 15:37:38 -0800 | [diff] [blame] | 17 | constexpr uint16_t kThirdRobotTeamNumber = 9984; |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 18 | |
| 19 | struct Values { |
| 20 | static const int kZeroingSampleSize = 200; |
| 21 | |
| 22 | static const int kSuperstructureCANWriterPriority = 35; |
| 23 | static const int kDrivetrainWriterPriority = 35; |
| 24 | static const int kDrivetrainTxPriority = 36; |
| 25 | static const int kDrivetrainRxPriority = 36; |
| 26 | |
| 27 | // TODO(max): Change these constants based on 3rd drivetrain CAD |
| 28 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 29 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 30 | return kDrivetrainCyclesPerRevolution() * 4; |
| 31 | } |
| 32 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
| 33 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 34 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 35 | control_loops::drivetrain::kHighOutputRatio / |
| 36 | constants::Values::kDrivetrainEncoderRatio() * |
| 37 | kDrivetrainEncoderCountsPerRevolution(); |
| 38 | } |
| 39 | |
| 40 | static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; } |
| 41 | static constexpr double kDrivetrainStatorCurrentLimit() { return 60.0; } |
| 42 | |
Maxwell Henderson | 3772d28 | 2023-11-06 11:07:49 -0800 | [diff] [blame] | 43 | static constexpr double kRollerSupplyCurrentLimit() { return 30.0; } |
| 44 | static constexpr double kRollerStatorCurrentLimit() { return 100.0; } |
| 45 | |
Filip Kujawa | 35b5aad | 2023-11-14 21:53:19 -0800 | [diff] [blame] | 46 | static constexpr double kPivotSupplyCurrentLimit() { return 40.0; } |
| 47 | static constexpr double kPivotStatorCurrentLimit() { return 200.0; } |
| 48 | |
Ariv Diggi | c892e92 | 2023-10-21 15:52:06 -0700 | [diff] [blame] | 49 | // timeout to ensure code doesn't get stuck after releasing the "intake" |
| 50 | // button |
| 51 | static constexpr std::chrono::milliseconds kExtraIntakingTime() { |
| 52 | return std::chrono::milliseconds{100}; |
| 53 | } |
| 54 | |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 55 | static double DrivetrainEncoderToMeters(int32_t in) { |
| 56 | return ((static_cast<double>(in) / |
| 57 | kDrivetrainEncoderCountsPerRevolution()) * |
| 58 | (2.0 * M_PI)) * |
| 59 | kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius; |
| 60 | } |
| 61 | |
| 62 | static double DrivetrainCANEncoderToMeters(double rotations) { |
| 63 | return (rotations * (2.0 * M_PI)) * |
Maxwell Henderson | f1cfe7f | 2023-12-26 10:48:26 -0800 | [diff] [blame^] | 64 | control_loops::drivetrain::kHighOutputRatio; |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 65 | } |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 66 | |
Filip Kujawa | 35b5aad | 2023-11-14 21:53:19 -0800 | [diff] [blame] | 67 | // Pivot Joint |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 68 | static constexpr double kPivotJointEncoderCountsPerRevolution() { |
| 69 | return 4096.0; |
| 70 | } |
| 71 | |
Filip Kujawa | 35b5aad | 2023-11-14 21:53:19 -0800 | [diff] [blame] | 72 | static constexpr double kPivotJointEncoderRatio() { |
| 73 | return (24.0 / 64.0) * (15.0 / 60.0); |
| 74 | } |
Maxwell Henderson | 0d22077 | 2023-11-06 11:09:58 -0800 | [diff] [blame] | 75 | |
Filip Kujawa | 35b5aad | 2023-11-14 21:53:19 -0800 | [diff] [blame] | 76 | static constexpr double kPivotJointPotRatio() { |
| 77 | return (24.0 / 64.0) * (15.0 / 60.0); |
| 78 | } |
Maxwell Henderson | 0d22077 | 2023-11-06 11:09:58 -0800 | [diff] [blame] | 79 | |
| 80 | static constexpr double kPivotJointPotRadiansPerVolt() { |
Filip Kujawa | 35b5aad | 2023-11-14 21:53:19 -0800 | [diff] [blame] | 81 | return kPivotJointPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) * |
Maxwell Henderson | 0d22077 | 2023-11-06 11:09:58 -0800 | [diff] [blame] | 82 | (2 * M_PI /*radians*/); |
| 83 | } |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 84 | |
| 85 | static constexpr double kMaxPivotJointEncoderPulsesPerSecond() { |
| 86 | return control_loops::superstructure::pivot_joint::kFreeSpeed / |
| 87 | (2.0 * M_PI) * |
| 88 | control_loops::superstructure::pivot_joint::kOutputRatio / |
| 89 | kPivotJointEncoderRatio() * kPivotJointEncoderCountsPerRevolution(); |
| 90 | } |
| 91 | |
| 92 | static constexpr ::frc971::constants::Range kPivotJointRange() { |
| 93 | return ::frc971::constants::Range{ |
Filip Kujawa | 35b5aad | 2023-11-14 21:53:19 -0800 | [diff] [blame] | 94 | .lower_hard = -1.78879503977269, // Back Hard |
| 95 | .upper_hard = 1.76302285774785, // Front Hard |
| 96 | .lower = -1.77156498873494, // Back Soft |
| 97 | .upper = 1.76555657862879, // Front Soft |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 98 | }; |
| 99 | } |
| 100 | |
Maxwell Henderson | 0d22077 | 2023-11-06 11:09:58 -0800 | [diff] [blame] | 101 | struct PotAndAbsEncoderConstants { |
| 102 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 103 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 104 | subsystem_params; |
| 105 | double potentiometer_offset; |
| 106 | }; |
| 107 | |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 108 | PotAndAbsEncoderConstants pivot_joint; |
| 109 | |
| 110 | bool pivot_joint_flipped; |
Ariv Diggi | 0af59c0 | 2023-10-07 13:15:39 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | // Creates and returns a Values instance for the constants. |
| 114 | // Should be called before realtime because this allocates memory. |
| 115 | // Only the first call to either of these will be used. |
| 116 | Values MakeValues(uint16_t team); |
| 117 | |
| 118 | // Calls MakeValues with aos::network::GetTeamNumber() |
| 119 | Values MakeValues(); |
| 120 | |
| 121 | } // namespace constants |
| 122 | } // namespace y2023_bot3 |
| 123 | |
Maxwell Henderson | 43684fa | 2023-11-06 11:08:06 -0800 | [diff] [blame] | 124 | #endif // Y2023_BOT3_CONSTANTS_H_ |