blob: 595a694965aaf5bd4ac50accb86f40a97f8ed140 [file] [log] [blame]
Maxwell Hendersonad312342023-01-10 12:07:47 -08001#ifndef Y2023_CONSTANTS_H_
2#define Y2023_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 "y2023/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
milind-u37385182023-02-20 15:07:28 -080012#include "y2023/control_loops/superstructure/arm/arm_constants.h"
milind-u051c7002023-02-20 16:28:18 -080013#include "y2023/control_loops/superstructure/roll/roll_plant.h"
14#include "y2023/control_loops/superstructure/wrist/wrist_plant.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080015
16namespace y2023 {
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
milind-u32d29d32023-02-24 21:11:51 -080026 static const int kSuperstructureCANWriterPriority = 35;
Ravago Jones2060ee62023-02-03 18:12:24 -080027 static const int kDrivetrainWriterPriority = 35;
28 static const int kDrivetrainTxPriority = 36;
29 static const int kDrivetrainRxPriority = 36;
30
Maxwell Hendersonad312342023-01-10 12:07:47 -080031 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
32 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
33 return kDrivetrainCyclesPerRevolution() * 4;
34 }
35 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
36 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
37 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
38 control_loops::drivetrain::kHighOutputRatio /
39 constants::Values::kDrivetrainEncoderRatio() *
40 kDrivetrainEncoderCountsPerRevolution();
41 }
42
Ravago Jones2060ee62023-02-03 18:12:24 -080043 static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; }
Austin Schuhe70cdeb2023-02-23 21:45:00 -080044 static constexpr double kDrivetrainStatorCurrentLimit() { return 60.0; }
Ravago Jones2060ee62023-02-03 18:12:24 -080045
Maxwell Hendersonad312342023-01-10 12:07:47 -080046 static double DrivetrainEncoderToMeters(int32_t in) {
47 return ((static_cast<double>(in) /
48 kDrivetrainEncoderCountsPerRevolution()) *
49 (2.0 * M_PI)) *
50 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
51 }
52
Ravago Jones2060ee62023-02-03 18:12:24 -080053 static double DrivetrainCANEncoderToMeters(double rotations) {
54 return (rotations * (2.0 * M_PI)) *
55 control_loops::drivetrain::kHighOutputRatio *
56 control_loops::drivetrain::kWheelRadius;
57 }
milind-u37385182023-02-20 15:07:28 -080058 static constexpr double kProximalEncoderCountsPerRevolution() {
59 return 4096.0;
60 }
61 static constexpr double kProximalEncoderRatio() { return (15.0 / 95.0); }
62 static constexpr double kMaxProximalEncoderPulsesPerSecond() {
63 return control_loops::superstructure::arm::kArmConstants.free_speed /
milind-u0a7d28d2023-02-20 17:44:37 -080064 (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g0 /
milind-u37385182023-02-20 15:07:28 -080065 kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution();
66 }
67 static constexpr double kProximalPotRatio() {
Austin Schuh7dcc49b2023-02-21 17:35:10 -080068 return (36.0 / 24.0) * (15.0 / 95.0);
milind-u37385182023-02-20 15:07:28 -080069 }
70
milind-u051c7002023-02-20 16:28:18 -080071 static constexpr double kProximalPotRadiansPerVolt() {
72 return kProximalPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) *
73 (2 * M_PI /*radians*/);
74 }
75
milind-u37385182023-02-20 15:07:28 -080076 static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; }
Austin Schuhebf76ee2023-02-24 20:34:33 -080077 static constexpr double kDistalEncoderRatio() { return (15.0 / 96.0); }
milind-u37385182023-02-20 15:07:28 -080078 static constexpr double kMaxDistalEncoderPulsesPerSecond() {
79 return control_loops::superstructure::arm::kArmConstants.free_speed /
milind-u0a7d28d2023-02-20 17:44:37 -080080 (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g1 /
81 kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution();
milind-u37385182023-02-20 15:07:28 -080082 }
83 static constexpr double kDistalPotRatio() {
Austin Schuhebf76ee2023-02-24 20:34:33 -080084 return (36.0 / 24.0) * (15.0 / 96.0);
milind-u37385182023-02-20 15:07:28 -080085 }
Ravago Jones2060ee62023-02-03 18:12:24 -080086
milind-u051c7002023-02-20 16:28:18 -080087 static constexpr double kDistalPotRadiansPerVolt() {
88 return kDistalPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) *
89 (2 * M_PI /*radians*/);
90 }
91
92 // Roll joint
93 static constexpr double kRollJointEncoderCountsPerRevolution() {
94 return 4096.0;
95 }
96
97 static constexpr double kRollJointEncoderRatio() { return (18.0 / 48.0); }
98
99 static constexpr double kRollJointPotRatio() { return (18.0 / 48.0); }
100
101 static constexpr double kRollJointPotRadiansPerVolt() {
102 return kRollJointPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) *
103 (2 * M_PI /*radians*/);
104 }
105
106 static constexpr double kMaxRollJointEncoderPulsesPerSecond() {
107 return control_loops::superstructure::roll::kFreeSpeed / (2.0 * M_PI) *
108 control_loops::superstructure::roll::kOutputRatio /
109 kRollJointEncoderRatio() * kRollJointEncoderCountsPerRevolution();
110 }
111
112 static constexpr ::frc971::constants::Range kRollJointRange() {
113 return ::frc971::constants::Range{
114 -1.05, // Back Hard
115 1.44, // Front Hard
116 -0.89, // Back Soft
117 1.26 // Front Soft
118 };
119 }
120
121 // Wrist
122 static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; }
123
Austin Schuhe5248cd2023-03-05 12:46:16 -0800124 static constexpr double kCompWristEncoderRatio() {
125 return 1.0;
126 }
127 static constexpr double kPracticeWristEncoderRatio() {
milind-u051c7002023-02-20 16:28:18 -0800128 return (24.0 / 36.0) * (36.0 / 60.0);
129 }
130
Austin Schuhe5248cd2023-03-05 12:46:16 -0800131 static constexpr double kMaxCompWristEncoderPulsesPerSecond() {
milind-u051c7002023-02-20 16:28:18 -0800132 return control_loops::superstructure::wrist::kFreeSpeed / (2.0 * M_PI) *
133 control_loops::superstructure::wrist::kOutputRatio /
Austin Schuhe5248cd2023-03-05 12:46:16 -0800134 kCompWristEncoderRatio() * kWristEncoderCountsPerRevolution();
135 }
136 static constexpr double kMaxPracticeWristEncoderPulsesPerSecond() {
137 return control_loops::superstructure::wrist::kFreeSpeed / (2.0 * M_PI) *
138 control_loops::superstructure::wrist::kOutputRatio /
139 kPracticeWristEncoderRatio() * kWristEncoderCountsPerRevolution();
milind-u051c7002023-02-20 16:28:18 -0800140 }
141
Austin Schuhe5248cd2023-03-05 12:46:16 -0800142 static constexpr ::frc971::constants::Range kCompWristRange() {
143 return ::frc971::constants::Range{
144 .lower_hard = -0.10, // Back Hard
145 .upper_hard = 4.90, // Front Hard
146 .lower = 0.0, // Back Soft
147 .upper = 4.0, // Front Soft
148 };
149 }
150
151 static constexpr ::frc971::constants::Range kPracticeWristRange() {
milind-u051c7002023-02-20 16:28:18 -0800152 return ::frc971::constants::Range{
Austin Schuh6dc925b2023-02-24 16:23:32 -0800153 .lower_hard = -0.10, // Back Hard
154 .upper_hard = 2.30, // Front Hard
155 .lower = 0.0, // Back Soft
Austin Schuh35a7f622023-02-25 19:00:20 -0800156 .upper = 2.2, // Front Soft
milind-u051c7002023-02-20 16:28:18 -0800157 };
158 }
159
milind-u18934eb2023-02-20 16:28:58 -0800160 // Rollers
161 static constexpr double kRollerSupplyCurrentLimit() { return 30.0; }
Austin Schuh23a90022023-02-24 22:13:39 -0800162 static constexpr double kRollerStatorCurrentLimit() { return 100.0; }
Maxwell Henderson589cf272023-02-22 15:56:40 -0800163
164 // Game object is fed into end effector for at least this time
165 static constexpr std::chrono::milliseconds kExtraIntakingTime() {
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800166 return std::chrono::seconds(2);
Maxwell Henderson589cf272023-02-22 15:56:40 -0800167 }
168
169 // Game object is spit from end effector for at least this time
170 static constexpr std::chrono::milliseconds kExtraSpittingTime() {
Austin Schuh1f0cc772023-03-22 20:29:04 -0700171 return std::chrono::seconds(1);
Maxwell Henderson589cf272023-02-22 15:56:40 -0800172 }
milind-u18934eb2023-02-20 16:28:58 -0800173
Maxwell Henderson5c47a462023-02-25 14:40:44 -0800174 // if true, tune down all the arm constants for testing.
175 static constexpr bool kArmGrannyMode() { return false; }
176
177 // the operating voltage.
178 static constexpr double kArmOperatingVoltage() {
179 return kArmGrannyMode() ? 6.0 : 12.0;
180 }
181 static constexpr double kArmDt() { return 0.00505; }
182 static constexpr std::chrono::nanoseconds kArmDtDuration() {
183 return std::chrono::duration_cast<std::chrono::nanoseconds>(
184 std::chrono::duration<double>(kArmDt()));
185 }
186 static constexpr double kArmAlpha0Max() {
187 return kArmGrannyMode() ? 15.0 : 15.0;
188 }
189 static constexpr double kArmAlpha1Max() {
190 return kArmGrannyMode() ? 10.0 : 10.0;
191 }
192 static constexpr double kArmAlpha2Max() {
193 return kArmGrannyMode() ? 90.0 : 90.0;
194 }
195
196 static constexpr double kArmVMax() { return kArmGrannyMode() ? 4.0 : 9.5; }
197 static constexpr double kArmPathlessVMax() { return 4.5; }
198 static constexpr double kArmGotoPathVMax() { return 4.5; }
199
Maxwell Hendersonad312342023-01-10 12:07:47 -0800200 struct PotConstants {
201 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
202 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
203 subsystem_params;
204 double potentiometer_offset;
205 };
206
207 struct PotAndAbsEncoderConstants {
208 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
209 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
210 subsystem_params;
211 double potentiometer_offset;
212 };
milind-u37385182023-02-20 15:07:28 -0800213
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800214 struct AbsEncoderConstants {
215 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
216 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
217 subsystem_params;
218 };
219
milind-u37385182023-02-20 15:07:28 -0800220 struct ArmJointConstants {
221 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
222 double potentiometer_offset;
223 };
224
225 ArmJointConstants arm_proximal;
226 ArmJointConstants arm_distal;
milind-u18a901d2023-02-17 21:51:55 -0800227 ArmJointConstants roll_joint;
milind-u051c7002023-02-20 16:28:18 -0800228
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800229 AbsEncoderConstants wrist;
Austin Schuhe5248cd2023-03-05 12:46:16 -0800230
231 bool wrist_flipped;
Maxwell Hendersonad312342023-01-10 12:07:47 -0800232};
233
234// Creates and returns a Values instance for the constants.
235// Should be called before realtime because this allocates memory.
236// Only the first call to either of these will be used.
237Values MakeValues(uint16_t team);
238
239// Calls MakeValues with aos::network::GetTeamNumber()
240Values MakeValues();
241
242} // namespace constants
243} // namespace y2023
244
245#endif // Y2023_CONSTANTS_H_