blob: 92428db655f7c18870c825b791752808d7692e79 [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"
James Kuszmaulec635d22023-08-12 18:39:24 -070011#include "frc971/zeroing/absolute_encoder.h"
12#include "frc971/zeroing/pot_and_absolute_encoder.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080013#include "y2023/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
milind-u37385182023-02-20 15:07:28 -080014#include "y2023/control_loops/superstructure/arm/arm_constants.h"
milind-u051c7002023-02-20 16:28:18 -080015#include "y2023/control_loops/superstructure/roll/roll_plant.h"
16#include "y2023/control_loops/superstructure/wrist/wrist_plant.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080017
18namespace y2023 {
19namespace constants {
20
21constexpr uint16_t kCompTeamNumber = 971;
22constexpr uint16_t kPracticeTeamNumber = 9971;
23constexpr uint16_t kCodingRobotTeamNumber = 7971;
24
25struct Values {
26 static const int kZeroingSampleSize = 200;
27
milind-u32d29d32023-02-24 21:11:51 -080028 static const int kSuperstructureCANWriterPriority = 35;
Ravago Jones2060ee62023-02-03 18:12:24 -080029 static const int kDrivetrainWriterPriority = 35;
30 static const int kDrivetrainTxPriority = 36;
31 static const int kDrivetrainRxPriority = 36;
32
Maxwell Hendersonad312342023-01-10 12:07:47 -080033 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
34 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
35 return kDrivetrainCyclesPerRevolution() * 4;
36 }
37 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
38 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
39 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
40 control_loops::drivetrain::kHighOutputRatio /
41 constants::Values::kDrivetrainEncoderRatio() *
42 kDrivetrainEncoderCountsPerRevolution();
43 }
44
Ravago Jones2060ee62023-02-03 18:12:24 -080045 static constexpr double kDrivetrainSupplyCurrentLimit() { return 35.0; }
Austin Schuhe70cdeb2023-02-23 21:45:00 -080046 static constexpr double kDrivetrainStatorCurrentLimit() { return 60.0; }
Ravago Jones2060ee62023-02-03 18:12:24 -080047
Maxwell Hendersonad312342023-01-10 12:07:47 -080048 static double DrivetrainEncoderToMeters(int32_t in) {
49 return ((static_cast<double>(in) /
50 kDrivetrainEncoderCountsPerRevolution()) *
51 (2.0 * M_PI)) *
52 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
53 }
54
Ravago Jones2060ee62023-02-03 18:12:24 -080055 static double DrivetrainCANEncoderToMeters(double rotations) {
56 return (rotations * (2.0 * M_PI)) *
Maxwell Hendersonf1cfe7f2023-12-26 10:48:26 -080057 control_loops::drivetrain::kHighOutputRatio;
Ravago Jones2060ee62023-02-03 18:12:24 -080058 }
milind-u37385182023-02-20 15:07:28 -080059 static constexpr double kProximalEncoderCountsPerRevolution() {
60 return 4096.0;
61 }
62 static constexpr double kProximalEncoderRatio() { return (15.0 / 95.0); }
63 static constexpr double kMaxProximalEncoderPulsesPerSecond() {
64 return control_loops::superstructure::arm::kArmConstants.free_speed /
milind-u0a7d28d2023-02-20 17:44:37 -080065 (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g0 /
milind-u37385182023-02-20 15:07:28 -080066 kProximalEncoderRatio() * kProximalEncoderCountsPerRevolution();
67 }
68 static constexpr double kProximalPotRatio() {
Austin Schuh7dcc49b2023-02-21 17:35:10 -080069 return (36.0 / 24.0) * (15.0 / 95.0);
milind-u37385182023-02-20 15:07:28 -080070 }
71
milind-u051c7002023-02-20 16:28:18 -080072 static constexpr double kProximalPotRadiansPerVolt() {
73 return kProximalPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) *
74 (2 * M_PI /*radians*/);
75 }
76
milind-u37385182023-02-20 15:07:28 -080077 static constexpr double kDistalEncoderCountsPerRevolution() { return 4096.0; }
Austin Schuhebf76ee2023-02-24 20:34:33 -080078 static constexpr double kDistalEncoderRatio() { return (15.0 / 96.0); }
milind-u37385182023-02-20 15:07:28 -080079 static constexpr double kMaxDistalEncoderPulsesPerSecond() {
80 return control_loops::superstructure::arm::kArmConstants.free_speed /
milind-u0a7d28d2023-02-20 17:44:37 -080081 (2.0 * M_PI) / control_loops::superstructure::arm::kArmConstants.g1 /
82 kDistalEncoderRatio() * kProximalEncoderCountsPerRevolution();
milind-u37385182023-02-20 15:07:28 -080083 }
84 static constexpr double kDistalPotRatio() {
Austin Schuhebf76ee2023-02-24 20:34:33 -080085 return (36.0 / 24.0) * (15.0 / 96.0);
milind-u37385182023-02-20 15:07:28 -080086 }
Ravago Jones2060ee62023-02-03 18:12:24 -080087
milind-u051c7002023-02-20 16:28:18 -080088 static constexpr double kDistalPotRadiansPerVolt() {
89 return kDistalPotRatio() * (10.0 /*turns*/ / 5.0 /*volts*/) *
90 (2 * M_PI /*radians*/);
91 }
92
93 // Roll joint
94 static constexpr double kRollJointEncoderCountsPerRevolution() {
95 return 4096.0;
96 }
97
98 static constexpr double kRollJointEncoderRatio() { return (18.0 / 48.0); }
99
100 static constexpr double kRollJointPotRatio() { return (18.0 / 48.0); }
101
102 static constexpr double kRollJointPotRadiansPerVolt() {
103 return kRollJointPotRatio() * (3.0 /*turns*/ / 5.0 /*volts*/) *
104 (2 * M_PI /*radians*/);
105 }
106
107 static constexpr double kMaxRollJointEncoderPulsesPerSecond() {
108 return control_loops::superstructure::roll::kFreeSpeed / (2.0 * M_PI) *
109 control_loops::superstructure::roll::kOutputRatio /
110 kRollJointEncoderRatio() * kRollJointEncoderCountsPerRevolution();
111 }
112
113 static constexpr ::frc971::constants::Range kRollJointRange() {
114 return ::frc971::constants::Range{
115 -1.05, // Back Hard
116 1.44, // Front Hard
117 -0.89, // Back Soft
118 1.26 // Front Soft
119 };
120 }
121
122 // Wrist
123 static constexpr double kWristEncoderCountsPerRevolution() { return 4096.0; }
124
Ravago Jones8c65c432023-03-25 17:35:39 -0700125 static constexpr double kCompWristEncoderRatio() { return 1.0; }
Austin Schuhe5248cd2023-03-05 12:46:16 -0800126 static constexpr double kPracticeWristEncoderRatio() {
milind-u051c7002023-02-20 16:28:18 -0800127 return (24.0 / 36.0) * (36.0 / 60.0);
128 }
129
Austin Schuhe5248cd2023-03-05 12:46:16 -0800130 static constexpr double kMaxCompWristEncoderPulsesPerSecond() {
milind-u051c7002023-02-20 16:28:18 -0800131 return control_loops::superstructure::wrist::kFreeSpeed / (2.0 * M_PI) *
132 control_loops::superstructure::wrist::kOutputRatio /
Austin Schuhe5248cd2023-03-05 12:46:16 -0800133 kCompWristEncoderRatio() * kWristEncoderCountsPerRevolution();
134 }
135 static constexpr double kMaxPracticeWristEncoderPulsesPerSecond() {
136 return control_loops::superstructure::wrist::kFreeSpeed / (2.0 * M_PI) *
137 control_loops::superstructure::wrist::kOutputRatio /
138 kPracticeWristEncoderRatio() * kWristEncoderCountsPerRevolution();
milind-u051c7002023-02-20 16:28:18 -0800139 }
140
Austin Schuhe5248cd2023-03-05 12:46:16 -0800141 static constexpr ::frc971::constants::Range kCompWristRange() {
142 return ::frc971::constants::Range{
143 .lower_hard = -0.10, // Back Hard
144 .upper_hard = 4.90, // Front Hard
145 .lower = 0.0, // Back Soft
146 .upper = 4.0, // Front Soft
147 };
148 }
149
150 static constexpr ::frc971::constants::Range kPracticeWristRange() {
milind-u051c7002023-02-20 16:28:18 -0800151 return ::frc971::constants::Range{
Austin Schuh6dc925b2023-02-24 16:23:32 -0800152 .lower_hard = -0.10, // Back Hard
153 .upper_hard = 2.30, // Front Hard
154 .lower = 0.0, // Back Soft
Austin Schuh35a7f622023-02-25 19:00:20 -0800155 .upper = 2.2, // Front Soft
milind-u051c7002023-02-20 16:28:18 -0800156 };
157 }
158
milind-u18934eb2023-02-20 16:28:58 -0800159 // Rollers
160 static constexpr double kRollerSupplyCurrentLimit() { return 30.0; }
Austin Schuh23a90022023-02-24 22:13:39 -0800161 static constexpr double kRollerStatorCurrentLimit() { return 100.0; }
Maxwell Henderson589cf272023-02-22 15:56:40 -0800162
163 // Game object is fed into end effector for at least this time
164 static constexpr std::chrono::milliseconds kExtraIntakingTime() {
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800165 return std::chrono::seconds(2);
Maxwell Henderson589cf272023-02-22 15:56:40 -0800166 }
167
168 // Game object is spit from end effector for at least this time
169 static constexpr std::chrono::milliseconds kExtraSpittingTime() {
Austin Schuh1f0cc772023-03-22 20:29:04 -0700170 return std::chrono::seconds(1);
Maxwell Henderson589cf272023-02-22 15:56:40 -0800171 }
milind-u18934eb2023-02-20 16:28:58 -0800172
Maxwell Henderson5c47a462023-02-25 14:40:44 -0800173 // if true, tune down all the arm constants for testing.
Austin Schuh7c0a5762023-04-09 14:15:57 -0700174 static constexpr bool kArmGrannyMode() { return false; }
Maxwell Henderson5c47a462023-02-25 14:40:44 -0800175
176 // the operating voltage.
177 static constexpr double kArmOperatingVoltage() {
178 return kArmGrannyMode() ? 6.0 : 12.0;
179 }
180 static constexpr double kArmDt() { return 0.00505; }
181 static constexpr std::chrono::nanoseconds kArmDtDuration() {
182 return std::chrono::duration_cast<std::chrono::nanoseconds>(
183 std::chrono::duration<double>(kArmDt()));
184 }
185 static constexpr double kArmAlpha0Max() {
186 return kArmGrannyMode() ? 15.0 : 15.0;
187 }
188 static constexpr double kArmAlpha1Max() {
189 return kArmGrannyMode() ? 10.0 : 10.0;
190 }
191 static constexpr double kArmAlpha2Max() {
192 return kArmGrannyMode() ? 90.0 : 90.0;
193 }
194
195 static constexpr double kArmVMax() { return kArmGrannyMode() ? 4.0 : 9.5; }
Austin Schuhf0db08e2023-04-05 19:48:42 -0700196 static constexpr double kArmPathlessVMax() { return 9.5; }
197 static constexpr double kArmGotoPathVMax() { return 9.5; }
Maxwell Henderson5c47a462023-02-25 14:40:44 -0800198
Maxwell Hendersonad312342023-01-10 12:07:47 -0800199 struct PotConstants {
200 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
201 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
202 subsystem_params;
203 double potentiometer_offset;
204 };
205
206 struct PotAndAbsEncoderConstants {
207 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
208 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
209 subsystem_params;
210 double potentiometer_offset;
211 };
milind-u37385182023-02-20 15:07:28 -0800212
Maxwell Henderson8ca44562023-02-23 13:11:51 -0800213 struct AbsEncoderConstants {
214 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
215 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
216 subsystem_params;
217 };
218
milind-u37385182023-02-20 15:07:28 -0800219 struct ArmJointConstants {
220 ::frc971::constants::PotAndAbsoluteEncoderZeroingConstants zeroing;
221 double potentiometer_offset;
222 };
223
224 ArmJointConstants arm_proximal;
225 ArmJointConstants arm_distal;
milind-u18a901d2023-02-17 21:51:55 -0800226 ArmJointConstants roll_joint;
milind-u051c7002023-02-20 16:28:18 -0800227
Austin Schuhe5248cd2023-03-05 12:46:16 -0800228 bool wrist_flipped;
Maxwell Hendersonad312342023-01-10 12:07:47 -0800229};
230
231// Creates and returns a Values instance for the constants.
232// Should be called before realtime because this allocates memory.
233// Only the first call to either of these will be used.
234Values MakeValues(uint16_t team);
235
236// Calls MakeValues with aos::network::GetTeamNumber()
237Values MakeValues();
238
239} // namespace constants
240} // namespace y2023
241
242#endif // Y2023_CONSTANTS_H_