blob: a5bef55753799d3dc60393bcfd4b01b03242fa14 [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() {
76 return 16 * 0.25 * 0.0254 * kClimberEncoderRatio();
Filip Kujawa749f2442024-02-04 01:12:35 -080077 }
78
Maxwell Hendersonce232a92024-02-18 12:17:37 -080079 static constexpr double kClimberEncoderMetersPerRevolution() {
80 return kClimberPotMetersPerRevolution();
81 }
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 }
Niko Sohmersb21dbdc2024-01-20 20:06:59 -0800111 struct PotAndAbsEncoderConstants {
112 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
113 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
114 subsystem_params;
115 double potentiometer_offset;
116 };
Niko Sohmers74b0ad52024-02-03 18:00:31 -0800117
118 struct AbsoluteEncoderConstants {
119 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
120 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
121 subsystem_params;
122 };
Niko Sohmers3860f8a2024-01-12 21:05:19 -0800123};
124
125// Creates and returns a Values instance for the constants.
126// Should be called before realtime because this allocates memory.
127// Only the first call to either of these will be used.
128constants::Values MakeValues(uint16_t team);
129
130// Calls MakeValues with aos::network::GetTeamNumber()
131constants::Values MakeValues();
132
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -0800133} // namespace y2024::constants
Niko Sohmers3860f8a2024-01-12 21:05:19 -0800134
135#endif // Y2024_CONSTANTS_H_