milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 1 | #ifndef Y2022_CONSTANTS_H_ |
| 2 | #define Y2022_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 "y2022/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 12 | #include "y2022/control_loops/superstructure/catapult/catapult_plant.h" |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 13 | #include "y2022/control_loops/superstructure/climber/climber_plant.h" |
Yash Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 14 | #include "y2022/control_loops/superstructure/intake/intake_plant.h" |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 15 | #include "y2022/control_loops/superstructure/turret/turret_plant.h" |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 16 | |
| 17 | namespace y2022 { |
| 18 | namespace constants { |
| 19 | |
| 20 | struct Values { |
| 21 | static const int kZeroingSampleSize = 200; |
| 22 | |
| 23 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 24 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 25 | return kDrivetrainCyclesPerRevolution() * 4; |
| 26 | } |
James Kuszmaul | c2b2a80 | 2022-02-25 21:59:31 -0800 | [diff] [blame] | 27 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 28 | static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() { |
| 29 | return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) * |
| 30 | control_loops::drivetrain::kHighOutputRatio / |
| 31 | constants::Values::kDrivetrainEncoderRatio() * |
| 32 | kDrivetrainEncoderCountsPerRevolution(); |
| 33 | } |
James Kuszmaul | 53507e1 | 2022-02-12 18:36:40 -0800 | [diff] [blame] | 34 | |
| 35 | static double DrivetrainEncoderToMeters(int32_t in) { |
| 36 | return ((static_cast<double>(in) / |
| 37 | kDrivetrainEncoderCountsPerRevolution()) * |
| 38 | (2.0 * M_PI)) * |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 39 | kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius; |
Yash Chainani | 997a749 | 2022-01-29 15:48:56 -0800 | [diff] [blame] | 40 | } |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 41 | |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 42 | // Climber |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 43 | static constexpr ::frc971::constants::Range kClimberRange() { |
| 44 | return ::frc971::constants::Range{ |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 45 | .lower_hard = -0.01, .upper_hard = 0.6, .lower = 0.0, .upper = 0.5}; |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 46 | } |
| 47 | static constexpr double kClimberPotMetersPerRevolution() { |
| 48 | return 22 * 0.25 * 0.0254; |
| 49 | } |
| 50 | static constexpr double kClimberPotRatio() { return 1.0; } |
| 51 | |
| 52 | struct PotConstants { |
| 53 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 54 | ::frc971::zeroing::RelativeEncoderZeroingEstimator> |
| 55 | subsystem_params; |
| 56 | double potentiometer_offset; |
| 57 | }; |
| 58 | |
| 59 | PotConstants climber; |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 60 | |
| 61 | // Intake |
| 62 | // two encoders with same gear ratio for intake |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 63 | static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; } |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 64 | |
| 65 | static constexpr double kIntakeEncoderRatio() { |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 66 | return (16.0 / 64.0) * (20.0 / 50.0); |
Milo Lin | 6b5e458 | 2022-01-29 14:51:37 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 69 | static constexpr double kIntakePotRatio() { return 16.0 / 64.0; } |
| 70 | |
| 71 | static constexpr double kMaxIntakeEncoderPulsesPerSecond() { |
| 72 | return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) * |
| 73 | control_loops::superstructure::intake::kOutputRatio / |
| 74 | kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution(); |
| 75 | } |
| 76 | |
| 77 | struct PotAndAbsEncoderConstants { |
| 78 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 79 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 80 | subsystem_params; |
| 81 | double potentiometer_offset; |
| 82 | }; |
| 83 | |
| 84 | PotAndAbsEncoderConstants intake_front; |
| 85 | PotAndAbsEncoderConstants intake_back; |
| 86 | |
| 87 | // TODO (Yash): Constants need to be tuned |
| 88 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 89 | return ::frc971::constants::Range{ |
| 90 | .lower_hard = -0.5, // Back Hard |
| 91 | .upper_hard = 2.85 + 0.05, // Front Hard |
| 92 | .lower = -0.300, // Back Soft |
| 93 | .upper = 2.725 // Front Soft |
| 94 | }; |
| 95 | } |
| 96 | |
| 97 | // Intake rollers |
| 98 | static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; } |
| 99 | static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; } |
| 100 | |
| 101 | // Turret |
| 102 | PotAndAbsEncoderConstants turret; |
| 103 | |
| 104 | // TODO (Yash): Constants need to be tuned |
| 105 | static constexpr ::frc971::constants::Range kTurretRange() { |
| 106 | return ::frc971::constants::Range{ |
Milind Upadhyay | 225156b | 2022-02-25 22:42:12 -0800 | [diff] [blame] | 107 | .lower_hard = -0.1, // Back Hard |
| 108 | .upper_hard = 4.71, // Front Hard |
| 109 | .lower = 0.0, // Back Soft |
| 110 | .upper = 3.3 // Front Soft |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 111 | }; |
| 112 | } |
| 113 | |
| 114 | // Turret |
| 115 | static constexpr double kTurretPotRatio() { return 27.0 / 110.0; } |
| 116 | static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); } |
| 117 | static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; } |
| 118 | |
| 119 | static constexpr double kMaxTurretEncoderPulsesPerSecond() { |
| 120 | return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) * |
| 121 | control_loops::superstructure::turret::kOutputRatio / |
| 122 | kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution(); |
| 123 | } |
Griffin Bui | bcbef48 | 2022-02-23 15:32:10 -0800 | [diff] [blame] | 124 | |
| 125 | // Flipper arms |
| 126 | static constexpr double kFlipperArmSupplyCurrentLimit() { return 30.0; } |
| 127 | static constexpr double kFlipperArmStatorCurrentLimit() { return 40.0; } |
| 128 | |
| 129 | // TODO: (Griffin) this needs to be set |
| 130 | static constexpr ::frc971::constants::Range kFlipperArmRange() { |
| 131 | return ::frc971::constants::Range{ |
| 132 | .lower_hard = -0.01, .upper_hard = 0.6, .lower = 0.0, .upper = 0.5}; |
| 133 | } |
| 134 | |
| 135 | static constexpr double kFlipperArmsPotRatio() { return 16.0 / 36.0; } |
| 136 | |
| 137 | PotConstants flipper_arm_left; |
| 138 | PotConstants flipper_arm_right; |
Austin Schuh | 39f26f6 | 2022-02-24 21:34:46 -0800 | [diff] [blame] | 139 | |
| 140 | // Catapult. |
| 141 | static constexpr double kCatapultPotRatio() { return (12.0 / 33.0); } |
| 142 | static constexpr double kCatapultEncoderRatio() { |
| 143 | return kCatapultPotRatio(); |
| 144 | } |
| 145 | static constexpr double kCatapultEncoderCountsPerRevolution() { |
| 146 | return 4096.0; |
| 147 | } |
| 148 | |
| 149 | static constexpr double kMaxCatapultEncoderPulsesPerSecond() { |
| 150 | return control_loops::superstructure::catapult::kFreeSpeed / (2.0 * M_PI) * |
| 151 | control_loops::superstructure::catapult::kOutputRatio / |
| 152 | kCatapultEncoderRatio() * kCatapultEncoderCountsPerRevolution(); |
| 153 | } |
| 154 | static constexpr ::frc971::constants::Range kCatapultRange() { |
| 155 | return ::frc971::constants::Range{ |
| 156 | .lower_hard = -1.2, |
| 157 | .upper_hard = 2.0, |
| 158 | .lower = -1.00, |
| 159 | .upper = 1.57, |
| 160 | }; |
| 161 | } |
| 162 | |
| 163 | PotAndAbsEncoderConstants catapult; |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 164 | }; |
| 165 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 166 | // Creates and returns a Values instance for the constants. |
| 167 | // Should be called before realtime because this allocates memory. |
| 168 | // Only the first call to either of these will be used. |
| 169 | Values MakeValues(uint16_t team); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 170 | |
Henry Speiser | 55aa3ba | 2022-02-21 23:21:12 -0800 | [diff] [blame] | 171 | // Calls MakeValues with aos::network::GetTeamNumber() |
| 172 | Values MakeValues(); |
milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame] | 173 | |
| 174 | } // namespace constants |
| 175 | } // namespace y2022 |
| 176 | |
| 177 | #endif // Y2022_CONSTANTS_H_ |