blob: 45fd8b00d0d4690469292674e7472ec65dd997dd [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 {
24 static const int kZeroingSampleSize = 200;
25
26 static const int kSuperstructureCANWriterPriority = 35;
27 static const int kDrivetrainWriterPriority = 35;
28 static const int kDrivetrainTxPriority = 36;
29 static const int kDrivetrainRxPriority = 36;
30
31 // TODO: These values will need to be changed for the 2024 robot.
32 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
33 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
34 return kDrivetrainCyclesPerRevolution() * 4;
35 }
36 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
37 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
38 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
39 control_loops::drivetrain::kHighOutputRatio /
40 constants::Values::kDrivetrainEncoderRatio() *
41 kDrivetrainEncoderCountsPerRevolution();
42 }
43
44 static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; }
45 static constexpr double kDrivetrainStatorCurrentLimit() { return 60.0; }
46
47 static double DrivetrainEncoderToMeters(int32_t in) {
48 return ((static_cast<double>(in) /
49 kDrivetrainEncoderCountsPerRevolution()) *
50 (2.0 * M_PI)) *
51 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
52 }
53
54 static double DrivetrainCANEncoderToMeters(double rotations) {
55 return (rotations * (2.0 * M_PI)) *
56 control_loops::drivetrain::kHighOutputRatio;
57 }
Niko Sohmersb21dbdc2024-01-20 20:06:59 -080058 // TODO: (niko) add the gear ratios for the intake once we have them
59 static constexpr double kIntakePivotEncoderCountsPerRevolution() {
60 return 4096.0;
61 }
62
63 static constexpr double kIntakePivotEncoderRatio() {
64 return (16.0 / 64.0) * (18.0 / 62.0);
65 }
66
67 static constexpr double kIntakePivotPotRatio() { return 16.0 / 64.0; }
68
69 static constexpr double kIntakePivotPotRadiansPerVolt() {
70 return kIntakePivotPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) *
71 (2 * M_PI /*radians*/);
72 }
73
74 static constexpr double kMaxIntakePivotEncoderPulsesPerSecond() {
75 return control_loops::superstructure::intake_pivot::kFreeSpeed /
76 (2.0 * M_PI) *
77 control_loops::superstructure::intake_pivot::kOutputRatio /
78 kIntakePivotEncoderRatio() *
79 kIntakePivotEncoderCountsPerRevolution();
80 }
81
82 struct PotAndAbsEncoderConstants {
83 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
84 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
85 subsystem_params;
86 double potentiometer_offset;
87 };
Niko Sohmers3860f8a2024-01-12 21:05:19 -080088};
89
90// Creates and returns a Values instance for the constants.
91// Should be called before realtime because this allocates memory.
92// Only the first call to either of these will be used.
93constants::Values MakeValues(uint16_t team);
94
95// Calls MakeValues with aos::network::GetTeamNumber()
96constants::Values MakeValues();
97
98} // namespace constants
99} // namespace y2024
100
101#endif // Y2024_CONSTANTS_H_