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