Henry Speiser | 354d278 | 2022-07-22 13:56:48 -0700 | [diff] [blame] | 1 | #ifndef Y2022_BOT3_CONSTANTS_H_ |
| 2 | #define Y2022_BOT3_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/shooter_interpolation/interpolation.h" |
James Kuszmaul | ec635d2 | 2023-08-12 18:39:24 -0700 | [diff] [blame] | 12 | #include "frc971/zeroing/pot_and_absolute_encoder.h" |
Henry Speiser | 354d278 | 2022-07-22 13:56:48 -0700 | [diff] [blame] | 13 | #include "y2022_bot3/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
Thiago Monteiro | a47ae66 | 2022-08-27 16:05:54 -0700 | [diff] [blame] | 14 | #include "y2022_bot3/control_loops/superstructure/climber/climber_plant.h" |
| 15 | #include "y2022_bot3/control_loops/superstructure/intake/intake_plant.h" |
Henry Speiser | 354d278 | 2022-07-22 13:56:48 -0700 | [diff] [blame] | 16 | |
| 17 | using ::frc971::shooter_interpolation::InterpolationTable; |
| 18 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 19 | namespace y2022_bot3::constants { |
Henry Speiser | 354d278 | 2022-07-22 13:56:48 -0700 | [diff] [blame] | 20 | |
| 21 | struct Values { |
| 22 | static const int kZeroingSampleSize = 200; |
| 23 | |
| 24 | static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; } |
| 25 | static constexpr double kDrivetrainEncoderCountsPerRevolution() { |
| 26 | return kDrivetrainCyclesPerRevolution() * 4; |
| 27 | } |
| 28 | static constexpr double kDrivetrainEncoderRatio() { return 1.0; } |
| 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 | } |
| 35 | |
| 36 | static double DrivetrainEncoderToMeters(int32_t in) { |
| 37 | return ((static_cast<double>(in) / |
| 38 | kDrivetrainEncoderCountsPerRevolution()) * |
| 39 | (2.0 * M_PI)) * |
| 40 | kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius; |
| 41 | } |
| 42 | |
| 43 | struct PotAndAbsEncoderConstants { |
| 44 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 45 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 46 | subsystem_params; |
| 47 | double potentiometer_offset; |
| 48 | }; |
Nikita Narang | 869ebf3 | 2022-08-20 13:09:49 -0700 | [diff] [blame] | 49 | |
Nikita Narang | 869ebf3 | 2022-08-20 13:09:49 -0700 | [diff] [blame] | 50 | static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; } |
| 51 | static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; } |
| 52 | |
Thiago Monteiro | a47ae66 | 2022-08-27 16:05:54 -0700 | [diff] [blame] | 53 | // Intake |
| 54 | // TODO (Logan): Constants need to be tuned |
| 55 | static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; } |
| 56 | |
| 57 | static constexpr double kIntakeEncoderRatio() { |
| 58 | return (16.0 / 64.0) * (18.0 / 62.0); |
| 59 | } |
| 60 | |
| 61 | static constexpr double kIntakePotRatio() { return 16.0 / 64.0; } |
| 62 | |
| 63 | static constexpr double kMaxIntakeEncoderPulsesPerSecond() { |
| 64 | return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) * |
| 65 | control_loops::superstructure::intake::kOutputRatio / |
| 66 | kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution(); |
| 67 | } |
| 68 | PotAndAbsEncoderConstants intake; |
| 69 | |
| 70 | static constexpr ::frc971::constants::Range kIntakeRange() { |
| 71 | return ::frc971::constants::Range{ |
| 72 | .lower_hard = -0.85, // Back Hard |
| 73 | .upper_hard = 1.85, // Front Hard |
| 74 | .lower = -0.400, // Back Soft |
| 75 | .upper = 1.57 // Front Soft |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | // Climber |
| 80 | // TODO (Logan): Constants need to be tuned |
| 81 | static constexpr double kClimberEncoderCountsPerRevolution() { |
| 82 | return 4096.0; |
| 83 | } |
| 84 | |
| 85 | static constexpr double kClimberEncoderRatio() { |
| 86 | return (16.0 / 64.0) * (18.0 / 62.0); |
| 87 | } |
| 88 | |
| 89 | static constexpr double kClimberEncoderMetersPerRevolution() { return 1.0; } |
| 90 | |
| 91 | static constexpr double kClimberPotMetersPerRevolution() { return 0.125; } |
| 92 | |
| 93 | static constexpr double kClimberPotRatio() { return 16.0 / 64.0; } |
| 94 | |
| 95 | static constexpr double kMaxClimberEncoderPulsesPerSecond() { |
| 96 | return control_loops::superstructure::climber::kFreeSpeed / (2.0 * M_PI) * |
| 97 | control_loops::superstructure::climber::kOutputRatio / |
| 98 | kClimberEncoderRatio() * kClimberEncoderCountsPerRevolution(); |
| 99 | } |
| 100 | PotAndAbsEncoderConstants climber_left; |
| 101 | PotAndAbsEncoderConstants climber_right; |
| 102 | |
| 103 | static constexpr ::frc971::constants::Range kClimberRange() { |
| 104 | return ::frc971::constants::Range{ |
| 105 | .lower_hard = -0.01, // Back Hard |
| 106 | .upper_hard = 0.59, // Front Hard |
| 107 | .lower = 0.003, // Back Soft |
| 108 | .upper = 0.555 // Front Soft |
| 109 | }; |
| 110 | } |
Henry Speiser | 354d278 | 2022-07-22 13:56:48 -0700 | [diff] [blame] | 111 | }; |
Nikita Narang | 869ebf3 | 2022-08-20 13:09:49 -0700 | [diff] [blame] | 112 | |
Henry Speiser | 354d278 | 2022-07-22 13:56:48 -0700 | [diff] [blame] | 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 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 121 | } // namespace y2022_bot3::constants |
Henry Speiser | 354d278 | 2022-07-22 13:56:48 -0700 | [diff] [blame] | 122 | |
uid | 8253b0a | 2022-10-12 20:43:29 -0700 | [diff] [blame] | 123 | #endif // Y2022_BOT3_CONSTANTS_H_ |