blob: 1d0f5d3090ea80e7c2992b233eb54587ca7d7f7e [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"
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080015#include "y2024/control_loops/superstructure/intake_pivot/intake_pivot_plant.h"
Niko Sohmers3860f8a2024-01-12 21:05:19 -080016
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080017namespace y2024::constants {
Niko Sohmers3860f8a2024-01-12 21:05:19 -080018
19constexpr uint16_t kCompTeamNumber = 971;
20constexpr uint16_t kPracticeTeamNumber = 9971;
21constexpr uint16_t kCodingRobotTeamNumber = 7971;
22
23struct Values {
Niko Sohmers3860f8a2024-01-12 21:05:19 -080024 static const int kSuperstructureCANWriterPriority = 35;
25 static const int kDrivetrainWriterPriority = 35;
26 static const int kDrivetrainTxPriority = 36;
27 static const int kDrivetrainRxPriority = 36;
28
29 // TODO: These values will need to be changed for the 2024 robot.
30 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
31 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
32 return kDrivetrainCyclesPerRevolution() * 4;
33 }
34 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
35 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
36 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
37 control_loops::drivetrain::kHighOutputRatio /
38 constants::Values::kDrivetrainEncoderRatio() *
39 kDrivetrainEncoderCountsPerRevolution();
40 }
41
Niko Sohmers3860f8a2024-01-12 21:05:19 -080042 static double DrivetrainEncoderToMeters(int32_t in) {
43 return ((static_cast<double>(in) /
44 kDrivetrainEncoderCountsPerRevolution()) *
45 (2.0 * M_PI)) *
46 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
47 }
48
49 static double DrivetrainCANEncoderToMeters(double rotations) {
50 return (rotations * (2.0 * M_PI)) *
51 control_loops::drivetrain::kHighOutputRatio;
52 }
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080053 // TODO: (niko) add the gear ratios for the intake once we have them
54 static constexpr double kIntakePivotEncoderCountsPerRevolution() {
55 return 4096.0;
56 }
57
58 static constexpr double kIntakePivotEncoderRatio() {
59 return (16.0 / 64.0) * (18.0 / 62.0);
60 }
61
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080062 static constexpr double kMaxIntakePivotEncoderPulsesPerSecond() {
63 return control_loops::superstructure::intake_pivot::kFreeSpeed /
64 (2.0 * M_PI) *
65 control_loops::superstructure::intake_pivot::kOutputRatio /
66 kIntakePivotEncoderRatio() *
67 kIntakePivotEncoderCountsPerRevolution();
68 }
69
Filip Kujawa749f2442024-02-04 01:12:35 -080070 // TODO(Filip): Update climber values once we have them.
71 static constexpr double kClimberEncoderCountsPerRevolution() {
72 return 4096.0;
73 }
74
75 static constexpr double kClimberEncoderRatio() {
76 return (16.0 / 64.0) * (18.0 / 62.0);
77 }
78
79 static constexpr double kClimberPotRatio() { return 16.0 / 64.0; }
80
81 static constexpr double kClimberPotRadiansPerVolt() {
82 return kClimberPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) *
83 (2 * M_PI /*radians*/);
84 }
85
86 static constexpr double kMaxClimberEncoderPulsesPerSecond() {
87 return control_loops::superstructure::climber::kFreeSpeed / (2.0 * M_PI) *
88 control_loops::superstructure::climber::kOutputRatio /
89 kClimberEncoderRatio() * kClimberEncoderCountsPerRevolution();
90 }
91
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080092 struct PotAndAbsEncoderConstants {
93 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
94 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
95 subsystem_params;
96 double potentiometer_offset;
97 };
Niko Sohmers74b0ad52024-02-03 18:00:31 -080098
99 struct AbsoluteEncoderConstants {
100 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
101 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
102 subsystem_params;
103 };
Niko Sohmers3860f8a2024-01-12 21:05:19 -0800104};
105
106// Creates and returns a Values instance for the constants.
107// Should be called before realtime because this allocates memory.
108// Only the first call to either of these will be used.
109constants::Values MakeValues(uint16_t team);
110
111// Calls MakeValues with aos::network::GetTeamNumber()
112constants::Values MakeValues();
113
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -0800114} // namespace y2024::constants
Niko Sohmers3860f8a2024-01-12 21:05:19 -0800115
116#endif // Y2024_CONSTANTS_H_