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