blob: b90534cb880df723c82120119b67a9e2d646f688 [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"
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080014#include "y2024/control_loops/superstructure/intake_pivot/intake_pivot_plant.h"
Niko Sohmers3860f8a2024-01-12 21:05:19 -080015
16namespace y2024 {
17namespace constants {
18
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
42 static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; }
43 static constexpr double kDrivetrainStatorCurrentLimit() { return 60.0; }
44
45 static double DrivetrainEncoderToMeters(int32_t in) {
46 return ((static_cast<double>(in) /
47 kDrivetrainEncoderCountsPerRevolution()) *
48 (2.0 * M_PI)) *
49 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
50 }
51
52 static double DrivetrainCANEncoderToMeters(double rotations) {
53 return (rotations * (2.0 * M_PI)) *
54 control_loops::drivetrain::kHighOutputRatio;
55 }
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080056 // TODO: (niko) add the gear ratios for the intake once we have them
57 static constexpr double kIntakePivotEncoderCountsPerRevolution() {
58 return 4096.0;
59 }
60
61 static constexpr double kIntakePivotEncoderRatio() {
62 return (16.0 / 64.0) * (18.0 / 62.0);
63 }
64
65 static constexpr double kIntakePivotPotRatio() { return 16.0 / 64.0; }
66
67 static constexpr double kIntakePivotPotRadiansPerVolt() {
68 return kIntakePivotPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) *
69 (2 * M_PI /*radians*/);
70 }
71
72 static constexpr double kMaxIntakePivotEncoderPulsesPerSecond() {
73 return control_loops::superstructure::intake_pivot::kFreeSpeed /
74 (2.0 * M_PI) *
75 control_loops::superstructure::intake_pivot::kOutputRatio /
76 kIntakePivotEncoderRatio() *
77 kIntakePivotEncoderCountsPerRevolution();
78 }
79
80 struct PotAndAbsEncoderConstants {
81 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
82 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
83 subsystem_params;
84 double potentiometer_offset;
85 };
Niko Sohmers3860f8a2024-01-12 21:05:19 -080086};
87
88// Creates and returns a Values instance for the constants.
89// Should be called before realtime because this allocates memory.
90// Only the first call to either of these will be used.
91constants::Values MakeValues(uint16_t team);
92
93// Calls MakeValues with aos::network::GetTeamNumber()
94constants::Values MakeValues();
95
96} // namespace constants
97} // namespace y2024
98
99#endif // Y2024_CONSTANTS_H_