blob: 50c982ad3bf05df97652d50e32d6c44f7243a3ab [file] [log] [blame]
Maxwell Henderson43684fa2023-11-06 11:08:06 -08001#ifndef Y2023_BOT3_CONSTANTS_H_
2#define Y2023_BOT3_CONSTANTS_H_
Ariv Diggi0af59c02023-10-07 13:15:39 -07003
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"
Maxwell Henderson43684fa2023-11-06 11:08:06 -080011#include "frc971/zeroing/pot_and_absolute_encoder.h"
Ariv Diggi0af59c02023-10-07 13:15:39 -070012#include "y2023_bot3/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Maxwell Henderson43684fa2023-11-06 11:08:06 -080013#include "y2023_bot3/control_loops/superstructure/pivot_joint/pivot_joint_plant.h"
Ariv Diggi0af59c02023-10-07 13:15:39 -070014namespace y2023_bot3 {
15namespace constants {
16
17constexpr uint16_t kThirdRobotTeamNumber = 8971;
18
19struct Values {
20 static const int kZeroingSampleSize = 200;
21
22 static const int kSuperstructureCANWriterPriority = 35;
23 static const int kDrivetrainWriterPriority = 35;
24 static const int kDrivetrainTxPriority = 36;
25 static const int kDrivetrainRxPriority = 36;
26
27 // TODO(max): Change these constants based on 3rd drivetrain CAD
28 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
29 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
30 return kDrivetrainCyclesPerRevolution() * 4;
31 }
32 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
33 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
34 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
35 control_loops::drivetrain::kHighOutputRatio /
36 constants::Values::kDrivetrainEncoderRatio() *
37 kDrivetrainEncoderCountsPerRevolution();
38 }
39
40 static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; }
41 static constexpr double kDrivetrainStatorCurrentLimit() { return 60.0; }
42
Maxwell Henderson3772d282023-11-06 11:07:49 -080043 static constexpr double kRollerSupplyCurrentLimit() { return 30.0; }
44 static constexpr double kRollerStatorCurrentLimit() { return 100.0; }
45
Filip Kujawa35b5aad2023-11-14 21:53:19 -080046 static constexpr double kPivotSupplyCurrentLimit() { return 40.0; }
47 static constexpr double kPivotStatorCurrentLimit() { return 200.0; }
48
Ariv Diggic892e922023-10-21 15:52:06 -070049 // timeout to ensure code doesn't get stuck after releasing the "intake"
50 // button
51 static constexpr std::chrono::milliseconds kExtraIntakingTime() {
52 return std::chrono::milliseconds{100};
53 }
54
Ariv Diggi0af59c02023-10-07 13:15:39 -070055 static double DrivetrainEncoderToMeters(int32_t in) {
56 return ((static_cast<double>(in) /
57 kDrivetrainEncoderCountsPerRevolution()) *
58 (2.0 * M_PI)) *
59 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
60 }
61
62 static double DrivetrainCANEncoderToMeters(double rotations) {
63 return (rotations * (2.0 * M_PI)) *
64 control_loops::drivetrain::kHighOutputRatio *
65 control_loops::drivetrain::kWheelRadius;
66 }
Maxwell Henderson43684fa2023-11-06 11:08:06 -080067
Filip Kujawa35b5aad2023-11-14 21:53:19 -080068 // Pivot Joint
Maxwell Henderson43684fa2023-11-06 11:08:06 -080069 static constexpr double kPivotJointEncoderCountsPerRevolution() {
70 return 4096.0;
71 }
72
Filip Kujawa35b5aad2023-11-14 21:53:19 -080073 static constexpr double kPivotJointEncoderRatio() {
74 return (24.0 / 64.0) * (15.0 / 60.0);
75 }
Maxwell Henderson0d220772023-11-06 11:09:58 -080076
Filip Kujawa35b5aad2023-11-14 21:53:19 -080077 static constexpr double kPivotJointPotRatio() {
78 return (24.0 / 64.0) * (15.0 / 60.0);
79 }
Maxwell Henderson0d220772023-11-06 11:09:58 -080080
81 static constexpr double kPivotJointPotRadiansPerVolt() {
Filip Kujawa35b5aad2023-11-14 21:53:19 -080082 return kPivotJointPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) *
Maxwell Henderson0d220772023-11-06 11:09:58 -080083 (2 * M_PI /*radians*/);
84 }
Maxwell Henderson43684fa2023-11-06 11:08:06 -080085
86 static constexpr double kMaxPivotJointEncoderPulsesPerSecond() {
87 return control_loops::superstructure::pivot_joint::kFreeSpeed /
88 (2.0 * M_PI) *
89 control_loops::superstructure::pivot_joint::kOutputRatio /
90 kPivotJointEncoderRatio() * kPivotJointEncoderCountsPerRevolution();
91 }
92
93 static constexpr ::frc971::constants::Range kPivotJointRange() {
94 return ::frc971::constants::Range{
Filip Kujawa35b5aad2023-11-14 21:53:19 -080095 .lower_hard = -1.78879503977269, // Back Hard
96 .upper_hard = 1.76302285774785, // Front Hard
97 .lower = -1.77156498873494, // Back Soft
98 .upper = 1.76555657862879, // Front Soft
Maxwell Henderson43684fa2023-11-06 11:08:06 -080099 };
100 }
101
Maxwell Henderson0d220772023-11-06 11:09:58 -0800102 struct PotAndAbsEncoderConstants {
103 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
104 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
105 subsystem_params;
106 double potentiometer_offset;
107 };
108
Maxwell Henderson43684fa2023-11-06 11:08:06 -0800109 PotAndAbsEncoderConstants pivot_joint;
110
111 bool pivot_joint_flipped;
Ariv Diggi0af59c02023-10-07 13:15:39 -0700112};
113
114// Creates and returns a Values instance for the constants.
115// Should be called before realtime because this allocates memory.
116// Only the first call to either of these will be used.
117Values MakeValues(uint16_t team);
118
119// Calls MakeValues with aos::network::GetTeamNumber()
120Values MakeValues();
121
122} // namespace constants
123} // namespace y2023_bot3
124
Maxwell Henderson43684fa2023-11-06 11:08:06 -0800125#endif // Y2023_BOT3_CONSTANTS_H_