blob: 254b180b259393f1f614b7158fe975ff6a2a1011 [file] [log] [blame]
Niko Sohmers3860f8a2024-01-12 21:05:19 -08001#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 Kujawa749f2442024-02-04 01:12:35 -080014#include "y2024/control_loops/superstructure/climber/climber_plant.h"
Austin Schuh3db875a2024-02-18 20:02:40 -080015#include "y2024/control_loops/superstructure/extend/extend_plant.h"
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080016#include "y2024/control_loops/superstructure/intake_pivot/intake_pivot_plant.h"
Niko Sohmers3860f8a2024-01-12 21:05:19 -080017
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080018namespace y2024::constants {
Niko Sohmers3860f8a2024-01-12 21:05:19 -080019
20constexpr uint16_t kCompTeamNumber = 971;
21constexpr uint16_t kPracticeTeamNumber = 9971;
22constexpr uint16_t kCodingRobotTeamNumber = 7971;
23
24struct Values {
Niko Sohmers3860f8a2024-01-12 21:05:19 -080025 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 Sohmers3860f8a2024-01-12 21:05:19 -080043 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 Sohmersb21dbdc2024-01-20 20:06:59 -080054 // 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 Hendersonce232a92024-02-18 12:17:37 -080059 static constexpr double kIntakePivotEncoderRatio() { return (15.0 / 24.0); }
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080060
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080061 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 Kujawa749f2442024-02-04 01:12:35 -080069 static constexpr double kClimberEncoderCountsPerRevolution() {
70 return 4096.0;
71 }
72
Maxwell Hendersonce232a92024-02-18 12:17:37 -080073 static constexpr double kClimberEncoderRatio() { return (16.0 / 60.0); }
74
75 static constexpr double kClimberPotMetersPerRevolution() {
Austin Schuhb0893872024-02-18 22:09:32 -080076 return 16 * 0.25 * 0.0254;
Filip Kujawa749f2442024-02-04 01:12:35 -080077 }
78
Maxwell Hendersonce232a92024-02-18 12:17:37 -080079 static constexpr double kClimberEncoderMetersPerRevolution() {
Austin Schuhb0893872024-02-18 22:09:32 -080080 return kClimberEncoderRatio() * kClimberPotMetersPerRevolution();
Maxwell Hendersonce232a92024-02-18 12:17:37 -080081 }
Filip Kujawa749f2442024-02-04 01:12:35 -080082
Maxwell Hendersonce232a92024-02-18 12:17:37 -080083 static constexpr double kClimberPotMetersPerVolt() {
84 return kClimberPotMetersPerRevolution() * (10.0 /*turns*/ / 5.0 /*volts*/);
Filip Kujawa749f2442024-02-04 01:12:35 -080085 }
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 Schuh3db875a2024-02-18 20:02:40 -080093 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 Kujawace385c32024-02-16 10:39:49 -0800111
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 Sohmersb21dbdc2024-01-20 20:06:59 -0800119 struct PotAndAbsEncoderConstants {
120 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
121 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
122 subsystem_params;
123 double potentiometer_offset;
124 };
Niko Sohmers74b0ad52024-02-03 18:00:31 -0800125
126 struct AbsoluteEncoderConstants {
127 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
128 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
129 subsystem_params;
130 };
Niko Sohmers3860f8a2024-01-12 21:05:19 -0800131};
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.
136constants::Values MakeValues(uint16_t team);
137
138// Calls MakeValues with aos::network::GetTeamNumber()
139constants::Values MakeValues();
140
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -0800141} // namespace y2024::constants
Niko Sohmers3860f8a2024-01-12 21:05:19 -0800142
143#endif // Y2024_CONSTANTS_H_