Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 1 | #ifndef Y2023_CONSTANTS_H_ |
| 2 | #define Y2023_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 "y2023/control_loops/drivetrain/drivetrain_dog_motor_plant.h" |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 12 | #include "y2023/control_loops/superstructure/arm/arm_constants.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 13 | |
| 14 | namespace y2023 { |
| 15 | namespace constants { |
| 16 | |
| 17 | constexpr uint16_t kCompTeamNumber = 971; |
| 18 | constexpr uint16_t kPracticeTeamNumber = 9971; |
| 19 | constexpr uint16_t kCodingRobotTeamNumber = 7971; |
| 20 | |
| 21 | struct Values { |
| 22 | static const int kZeroingSampleSize = 200; |
| 23 | |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 24 | static const int kDrivetrainWriterPriority = 35; |
| 25 | static const int kDrivetrainTxPriority = 36; |
| 26 | static const int kDrivetrainRxPriority = 36; |
| 27 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 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 | |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 40 | static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; } |
| 41 | static constexpr double kDrivetrainStatorCurrentLimit() { return 40.0; } |
| 42 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -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 | |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 50 | static double DrivetrainCANEncoderToMeters(double rotations) { |
| 51 | return (rotations * (2.0 * M_PI)) * |
| 52 | control_loops::drivetrain::kHighOutputRatio * |
| 53 | control_loops::drivetrain::kWheelRadius; |
| 54 | } |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 55 | static constexpr double kProximalEncoderCountsPerRevolution() { |
| 56 | return 4096.0; |
| 57 | } |
| 58 | static constexpr double kProximalEncoderRatio() { return (15.0 / 95.0); } |
| 59 | static constexpr double kMaxProximalEncoderPulsesPerSecond() { |
| 60 | return control_loops::superstructure::arm::kArmConstants.free_speed / |
| 61 | (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g1 / |
| 62 | kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution(); |
| 63 | } |
| 64 | static constexpr double kProximalPotRatio() { |
| 65 | return (24.0 / 36.0) * (24.0 / 58.0) * (15.0 / 95.0); |
| 66 | } |
| 67 | |
| 68 | static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; } |
| 69 | static constexpr double kDistalEncoderRatio() { return (15.0 / 95.0); } |
| 70 | static constexpr double kMaxDistalEncoderPulsesPerSecond() { |
| 71 | return control_loops::superstructure::arm::kArmConstants.free_speed / |
| 72 | (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g2 / |
| 73 | kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution(); |
| 74 | } |
| 75 | static constexpr double kDistalPotRatio() { |
| 76 | return (24.0 / 36.0) * (18.0 / 66.0) * (15.0 / 95.0); |
| 77 | } |
Ravago Jones | 2060ee6 | 2023-02-03 18:12:24 -0800 | [diff] [blame] | 78 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 79 | struct PotConstants { |
| 80 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 81 | ::frc971::zeroing::RelativeEncoderZeroingEstimator> |
| 82 | subsystem_params; |
| 83 | double potentiometer_offset; |
| 84 | }; |
| 85 | |
| 86 | struct PotAndAbsEncoderConstants { |
| 87 | ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams< |
| 88 | ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator> |
| 89 | subsystem_params; |
| 90 | double potentiometer_offset; |
| 91 | }; |
milind-u | 3738518 | 2023-02-20 15:07:28 -0800 | [diff] [blame] | 92 | |
| 93 | struct ArmJointConstants { |
| 94 | ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing; |
| 95 | double potentiometer_offset; |
| 96 | }; |
| 97 | |
| 98 | ArmJointConstants arm_proximal; |
| 99 | ArmJointConstants arm_distal; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | // Creates and returns a Values instance for the constants. |
| 103 | // Should be called before realtime because this allocates memory. |
| 104 | // Only the first call to either of these will be used. |
| 105 | Values MakeValues(uint16_t team); |
| 106 | |
| 107 | // Calls MakeValues with aos::network::GetTeamNumber() |
| 108 | Values MakeValues(); |
| 109 | |
| 110 | } // namespace constants |
| 111 | } // namespace y2023 |
| 112 | |
| 113 | #endif // Y2023_CONSTANTS_H_ |