Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 1 | #ifndef Y2024_CONSTANTS_H_ |
| 2 | #define Y2024_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 "frc971/zeroing/absolute_encoder.h" |
| 12 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
| 13 | #include "y2024/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 14 | #include "y2024/control_loops/superstructure/climber/climber_plant.h" |
Austin Schuh | 3db875a | 2024-02-18 20:02:40 -0800 | [diff] [blame] | 15 | #include "y2024/control_loops/superstructure/extend/extend_plant.h" |
Niko Sohmers | b21dbdc | 2024-01-20 20:06:59 -0800 | [diff] [blame] | 16 | #include "y2024/control_loops/superstructure/intake_pivot/intake_pivot_plant.h" |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 17 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 18 | namespace y2024::constants { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 19 | |
| 20 | constexpr uint16_t kCompTeamNumber = 971; |
| 21 | constexpr uint16_t kPracticeTeamNumber = 9971; |
| 22 | constexpr uint16_t kCodingRobotTeamNumber = 7971; |
| 23 | |
| 24 | struct Values { |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 25 | static const int kSuperstructureCANWriterPriority = 35; |
| 26 | static const int kDrivetrainWriterPriority = 35; |
| 27 | static const int kDrivetrainTxPriority = 36; |
| 28 | static const int kDrivetrainRxPriority = 36; |
| 29 | |
| 30 | // TODO: These values will need to be changed for the 2024 robot. |
| 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 | |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 43 | static double DrivetrainEncoderToMeters(int32_t in) { |
| 44 | return ((static_cast<double>(in) / |
| 45 | kDrivetrainEncoderCountsPerRevolution()) * |
| 46 | (2.0 * M_PI)) * |
| 47 | kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius; |
| 48 | } |
| 49 | |
| 50 | static double DrivetrainCANEncoderToMeters(double rotations) { |
| 51 | return (rotations * (2.0 * M_PI)) * |
| 52 | control_loops::drivetrain::kHighOutputRatio; |
| 53 | } |
Niko Sohmers | b21dbdc | 2024-01-20 20:06:59 -0800 | [diff] [blame] | 54 | // TODO: (niko) add the gear ratios for the intake once we have them |
| 55 | static constexpr double kIntakePivotEncoderCountsPerRevolution() { |
| 56 | return 4096.0; |
| 57 | } |
| 58 | |
Maxwell Henderson | ce232a9 | 2024-02-18 12:17:37 -0800 | [diff] [blame] | 59 | static constexpr double kIntakePivotEncoderRatio() { return (15.0 / 24.0); } |
Niko Sohmers | b21dbdc | 2024-01-20 20:06:59 -0800 | [diff] [blame] | 60 | |
Niko Sohmers | b21dbdc | 2024-01-20 20:06:59 -0800 | [diff] [blame] | 61 | static constexpr double kMaxIntakePivotEncoderPulsesPerSecond() { |
| 62 | return control_loops::superstructure::intake_pivot::kFreeSpeed / |
| 63 | (2.0 * M_PI) * |
| 64 | control_loops::superstructure::intake_pivot::kOutputRatio / |
| 65 | kIntakePivotEncoderRatio() * |
| 66 | kIntakePivotEncoderCountsPerRevolution(); |
| 67 | } |
| 68 | |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 69 | static constexpr double kClimberEncoderCountsPerRevolution() { |
| 70 | return 4096.0; |
| 71 | } |
| 72 | |
Maxwell Henderson | ce232a9 | 2024-02-18 12:17:37 -0800 | [diff] [blame] | 73 | static constexpr double kClimberEncoderRatio() { return (16.0 / 60.0); } |
| 74 | |
| 75 | static constexpr double kClimberPotMetersPerRevolution() { |
| 76 | return 16 * 0.25 * 0.0254 * kClimberEncoderRatio(); |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Maxwell Henderson | ce232a9 | 2024-02-18 12:17:37 -0800 | [diff] [blame] | 79 | static constexpr double kClimberEncoderMetersPerRevolution() { |
| 80 | return kClimberPotMetersPerRevolution(); |
| 81 | } |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 82 | |
Maxwell Henderson | ce232a9 | 2024-02-18 12:17:37 -0800 | [diff] [blame] | 83 | static constexpr double kClimberPotMetersPerVolt() { |
| 84 | return kClimberPotMetersPerRevolution() * (10.0 /*turns*/ / 5.0 /*volts*/); |
Filip Kujawa | 749f244 | 2024-02-04 01:12:35 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static constexpr double kMaxClimberEncoderPulsesPerSecond() { |
| 88 | return control_loops::superstructure::climber::kFreeSpeed / (2.0 * M_PI) * |
| 89 | control_loops::superstructure::climber::kOutputRatio / |
| 90 | kClimberEncoderRatio() * kClimberEncoderCountsPerRevolution(); |
| 91 | } |
| 92 | |
Austin Schuh | 3db875a | 2024-02-18 20:02:40 -0800 | [diff] [blame] | 93 | static constexpr double kExtendEncoderCountsPerRevolution() { return 4096.0; } |
| 94 | |
| 95 | static constexpr double kExtendEncoderRatio() { return 1.0; } |
| 96 | |
| 97 | static constexpr double kExtendPotMetersPerRevolution() { |
| 98 | return 36 * 0.005 * kExtendEncoderRatio(); |
| 99 | } |
| 100 | static constexpr double kExtendEncoderMetersPerRevolution() { |
| 101 | return kExtendPotMetersPerRevolution(); |
| 102 | } |
| 103 | static constexpr double kExtendPotMetersPerVolt() { |
| 104 | return kExtendPotMetersPerRevolution() * (5.0 /*turns*/ / 5.0 /*volts*/); |
| 105 | } |
| 106 | static constexpr double kMaxExtendEncoderPulsesPerSecond() { |
| 107 | return control_loops::superstructure::extend::kFreeSpeed / (2.0 * M_PI) * |
| 108 | control_loops::superstructure::extend::kOutputRatio / |
| 109 | kExtendEncoderRatio() * kExtendEncoderCountsPerRevolution(); |
| 110 | } |
Filip Kujawa | ce385c3 | 2024-02-16 10:39:49 -0800 | [diff] [blame^] | 111 | |
| 112 | // 20 -> 28 reduction to a 0.5" radius roller |
| 113 | static constexpr double kTransferRollerOutputRatio = (20.0 / 28.0) * 0.0127; |
| 114 | // 20 -> 34 reduction, and the 34 is on a 0.625" radius roller |
| 115 | static constexpr double kIntakeRollerOutputRatio = (20.0 / 34.0) * 0.015875; |
| 116 | // 20 -> 28 reduction to a 0.5" radius roller |
| 117 | static constexpr double kExtendRollerOutputRatio = (20.0 / 28.0) * 0.0127; |
| 118 | |
Niko Sohmers | b21dbdc | 2024-01-20 20:06:59 -0800 | [diff] [blame] | 119 | struct PotAndAbsEncoderConstants { |
| 120 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 121 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 122 | subsystem_params; |
| 123 | double potentiometer_offset; |
| 124 | }; |
Niko Sohmers | 74b0ad5 | 2024-02-03 18:00:31 -0800 | [diff] [blame] | 125 | |
| 126 | struct AbsoluteEncoderConstants { |
| 127 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 128 | ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> |
| 129 | subsystem_params; |
| 130 | }; |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | // Creates and returns a Values instance for the constants. |
| 134 | // Should be called before realtime because this allocates memory. |
| 135 | // Only the first call to either of these will be used. |
| 136 | constants::Values MakeValues(uint16_t team); |
| 137 | |
| 138 | // Calls MakeValues with aos::network::GetTeamNumber() |
| 139 | constants::Values MakeValues(); |
| 140 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 141 | } // namespace y2024::constants |
Niko Sohmers | 3860f8a | 2024-01-12 21:05:19 -0800 | [diff] [blame] | 142 | |
| 143 | #endif // Y2024_CONSTANTS_H_ |