blob: 297f8140272ff95c00341b7d0e0be8b8f92addf8 [file] [log] [blame]
milind-u086d7262022-01-19 20:44:18 -08001#ifndef Y2022_CONSTANTS_H_
2#define Y2022_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"
Ravago Jones3283ce02022-03-09 19:31:29 -080011#include "frc971/shooter_interpolation/interpolation.h"
milind-u086d7262022-01-19 20:44:18 -080012#include "y2022/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Austin Schuh39f26f62022-02-24 21:34:46 -080013#include "y2022/control_loops/superstructure/catapult/catapult_plant.h"
Henry Speiser55aa3ba2022-02-21 23:21:12 -080014#include "y2022/control_loops/superstructure/climber/climber_plant.h"
Yash Chainani997a7492022-01-29 15:48:56 -080015#include "y2022/control_loops/superstructure/intake/intake_plant.h"
Henry Speiser55aa3ba2022-02-21 23:21:12 -080016#include "y2022/control_loops/superstructure/turret/turret_plant.h"
milind-u086d7262022-01-19 20:44:18 -080017
Ravago Jones3283ce02022-03-09 19:31:29 -080018using ::frc971::shooter_interpolation::InterpolationTable;
19
milind-u086d7262022-01-19 20:44:18 -080020namespace y2022 {
21namespace constants {
22
Milind Upadhyayc76bb4c2022-09-21 09:31:48 -070023constexpr uint16_t kCompTeamNumber = 971;
24constexpr uint16_t kPracticeTeamNumber = 9971;
25constexpr uint16_t kCodingRobotTeamNumber = 7971;
26
milind-u086d7262022-01-19 20:44:18 -080027struct Values {
28 static const int kZeroingSampleSize = 200;
29
30 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
31 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
32 return kDrivetrainCyclesPerRevolution() * 4;
33 }
James Kuszmaulc2b2a802022-02-25 21:59:31 -080034 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
milind-u086d7262022-01-19 20:44:18 -080035 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
36 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
37 control_loops::drivetrain::kHighOutputRatio /
38 constants::Values::kDrivetrainEncoderRatio() *
39 kDrivetrainEncoderCountsPerRevolution();
40 }
James Kuszmaul53507e12022-02-12 18:36:40 -080041
42 static double DrivetrainEncoderToMeters(int32_t in) {
43 return ((static_cast<double>(in) /
44 kDrivetrainEncoderCountsPerRevolution()) *
45 (2.0 * M_PI)) *
Henry Speiser55aa3ba2022-02-21 23:21:12 -080046 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
Yash Chainani997a7492022-01-29 15:48:56 -080047 }
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080048
milind-u086d7262022-01-19 20:44:18 -080049 // Climber
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080050 static constexpr ::frc971::constants::Range kClimberRange() {
Milind Upadhyaye9075d12022-04-12 22:45:16 -070051 return ::frc971::constants::Range{.lower_hard = -0.01,
52 .upper_hard = 0.59,
53 .lower = 0.003,
54 .upper = 0.555};
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080055 }
56 static constexpr double kClimberPotMetersPerRevolution() {
57 return 22 * 0.25 * 0.0254;
58 }
59 static constexpr double kClimberPotRatio() { return 1.0; }
60
61 struct PotConstants {
62 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
63 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
64 subsystem_params;
65 double potentiometer_offset;
66 };
67
68 PotConstants climber;
Milo Lin6b5e4582022-01-29 14:51:37 -080069
70 // Intake
71 // two encoders with same gear ratio for intake
Henry Speiser55aa3ba2022-02-21 23:21:12 -080072 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
Milo Lin6b5e4582022-01-29 14:51:37 -080073
74 static constexpr double kIntakeEncoderRatio() {
Austin Schuh275f9812022-03-05 14:02:37 -080075 return (16.0 / 64.0) * (18.0 / 62.0);
Milo Lin6b5e4582022-01-29 14:51:37 -080076 }
77
Henry Speiser55aa3ba2022-02-21 23:21:12 -080078 static constexpr double kIntakePotRatio() { return 16.0 / 64.0; }
79
80 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
81 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
82 control_loops::superstructure::intake::kOutputRatio /
83 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
84 }
85
86 struct PotAndAbsEncoderConstants {
87 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
88 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
89 subsystem_params;
90 double potentiometer_offset;
91 };
92
93 PotAndAbsEncoderConstants intake_front;
94 PotAndAbsEncoderConstants intake_back;
95
96 // TODO (Yash): Constants need to be tuned
97 static constexpr ::frc971::constants::Range kIntakeRange() {
98 return ::frc971::constants::Range{
Austin Schuh465a2882022-03-05 15:39:04 -080099 .lower_hard = -0.85, // Back Hard
100 .upper_hard = 1.85, // Front Hard
101 .lower = -0.400, // Back Soft
102 .upper = 1.57 // Front Soft
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800103 };
104 }
105
106 // Intake rollers
107 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; }
108 static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; }
109
Ravago Jones5da06352022-03-04 20:26:24 -0800110 // Transfer rollers
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800111 static constexpr double kTransferRollerVoltage() { return 12.0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800112
113 // Voltage to wiggle the transfer rollers and keep a ball in.
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800114 static constexpr double kTransferRollerWiggleVoltage() { return 3.0; }
115
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800116 // Turret
117 PotAndAbsEncoderConstants turret;
Milind Upadhyaye9075d12022-04-12 22:45:16 -0700118 frc971::constants::Range turret_range;
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800119
Austin Schuh42d7e5f2022-03-16 23:35:09 -0700120 static constexpr double kTurretBackIntakePos() { return -M_PI; }
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800121 static constexpr double kTurretFrontIntakePos() { return 0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800122
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800123 static constexpr double kTurretPotRatio() { return 27.0 / 110.0; }
124 static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); }
125 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
126
127 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
128 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
129 control_loops::superstructure::turret::kOutputRatio /
130 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
131 }
Griffin Buibcbef482022-02-23 15:32:10 -0800132
133 // Flipper arms
milind-u37dc40b2022-03-08 19:51:27 -0800134 static constexpr double kFlipperArmSupplyCurrentLimit() { return 40.0; }
135 static constexpr double kFlipperArmStatorCurrentLimit() { return 60.0; }
Griffin Buibcbef482022-02-23 15:32:10 -0800136
Ravago Jones5da06352022-03-04 20:26:24 -0800137 // Voltage to open the flippers for firing
138 static constexpr double kFlipperOpenVoltage() { return 3.0; }
139 // Voltage to keep the flippers open for firing once they already are
Austin Schuh465a2882022-03-05 15:39:04 -0800140 static constexpr double kFlipperHoldVoltage() { return 2.5; }
Ravago Jones5da06352022-03-04 20:26:24 -0800141 // Voltage to feed a ball from the transfer rollers to the catpult with the
142 // flippers
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800143 static constexpr double kFlipperFeedVoltage() { return -12.0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800144
145 // Ball is fed into catapult for atleast this time no matter what
146 static constexpr std::chrono::milliseconds kExtraLoadingTime() {
147 return std::chrono::milliseconds(100);
148 }
149 // If we have been trying to transfer the ball for this amount of time, it
150 // probably got lost so abort
151 static constexpr std::chrono::seconds kBallLostTime() {
152 return std::chrono::seconds(2);
153 }
154 // If the flippers took more than this amount of time to open for firing,
155 // reseat the ball
156 static constexpr std::chrono::milliseconds kFlipperOpeningTimeout() {
milind-u37dc40b2022-03-08 19:51:27 -0800157 return std::chrono::milliseconds(1000);
Ravago Jones5da06352022-03-04 20:26:24 -0800158 }
159 // Don't use flipper velocity readings more than this amount of time in the
160 // past
161 static constexpr std::chrono::milliseconds kFlipperVelocityValidTime() {
162 return std::chrono::milliseconds(100);
163 }
164
Griffin Buibcbef482022-02-23 15:32:10 -0800165 // TODO: (Griffin) this needs to be set
166 static constexpr ::frc971::constants::Range kFlipperArmRange() {
167 return ::frc971::constants::Range{
Austin Schuh465a2882022-03-05 15:39:04 -0800168 .lower_hard = -0.01, .upper_hard = 0.4, .lower = 0.0, .upper = 0.5};
Griffin Buibcbef482022-02-23 15:32:10 -0800169 }
Ravago Jones5da06352022-03-04 20:26:24 -0800170 // Position of the flippers when they are open
Austin Schuh6b1e4d92022-03-12 12:02:46 -0800171 static constexpr double kFlipperOpenPosition() { return 0.20; }
Ravago Jones5da06352022-03-04 20:26:24 -0800172 // If the flippers were open but now moved back, reseat the ball if they go
173 // below this position
Austin Schuh465a2882022-03-05 15:39:04 -0800174 static constexpr double kReseatFlipperPosition() { return 0.1; }
Griffin Buibcbef482022-02-23 15:32:10 -0800175
176 static constexpr double kFlipperArmsPotRatio() { return 16.0 / 36.0; }
177
178 PotConstants flipper_arm_left;
179 PotConstants flipper_arm_right;
Austin Schuh39f26f62022-02-24 21:34:46 -0800180
181 // Catapult.
182 static constexpr double kCatapultPotRatio() { return (12.0 / 33.0); }
183 static constexpr double kCatapultEncoderRatio() {
184 return kCatapultPotRatio();
185 }
186 static constexpr double kCatapultEncoderCountsPerRevolution() {
187 return 4096.0;
188 }
189
190 static constexpr double kMaxCatapultEncoderPulsesPerSecond() {
191 return control_loops::superstructure::catapult::kFreeSpeed / (2.0 * M_PI) *
192 control_loops::superstructure::catapult::kOutputRatio /
193 kCatapultEncoderRatio() * kCatapultEncoderCountsPerRevolution();
194 }
195 static constexpr ::frc971::constants::Range kCatapultRange() {
196 return ::frc971::constants::Range{
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800197 .lower_hard = -1.0,
Austin Schuh39f26f62022-02-24 21:34:46 -0800198 .upper_hard = 2.0,
milind-u37dc40b2022-03-08 19:51:27 -0800199 .lower = -0.91,
Austin Schuh39f26f62022-02-24 21:34:46 -0800200 .upper = 1.57,
201 };
202 }
203
204 PotAndAbsEncoderConstants catapult;
milind-ucafdd5d2022-03-01 19:58:57 -0800205
206 // TODO(milind): set this
207 static constexpr double kImuHeight() { return 0.0; }
Ravago Jones3283ce02022-03-09 19:31:29 -0800208
209 struct ShotParams {
210 // Measured in radians
211 double shot_angle;
212 // Muzzle velocity (m/s) of the ball as it is released from the catapult.
213 double shot_velocity;
214
215 static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2) {
216 using ::frc971::shooter_interpolation::Blend;
217 return ShotParams{
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700218 .shot_angle = Blend(coefficient, a1.shot_angle, a2.shot_angle),
219 .shot_velocity =
220 Blend(coefficient, a1.shot_velocity, a2.shot_velocity),
Ravago Jones3283ce02022-03-09 19:31:29 -0800221 };
222 }
223 };
224
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700225 struct ShotVelocityParams {
226 // Speed over ground to use for shooting-on-the-fly.
227 double shot_speed_over_ground;
228
229 static ShotVelocityParams BlendY(double coefficient, ShotVelocityParams a1,
230 ShotVelocityParams a2) {
231 using ::frc971::shooter_interpolation::Blend;
232 return ShotVelocityParams{Blend(coefficient, a1.shot_speed_over_ground,
233 a2.shot_speed_over_ground)};
234 }
235 };
236
Ravago Jones3283ce02022-03-09 19:31:29 -0800237 InterpolationTable<ShotParams> shot_interpolation_table;
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700238
239 InterpolationTable<ShotVelocityParams> shot_velocity_interpolation_table;
Milind Upadhyayc76bb4c2022-09-21 09:31:48 -0700240
241 struct BallColorParams {
242 // Rects stored as {x, y, width, height}
243 std::array<int, 4> reference_red;
244 std::array<int, 4> reference_blue;
245 std::array<int, 4> ball_location;
246 };
247
248 BallColorParams ball_color;
milind-u086d7262022-01-19 20:44:18 -0800249};
250
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800251// Creates and returns a Values instance for the constants.
252// Should be called before realtime because this allocates memory.
253// Only the first call to either of these will be used.
254Values MakeValues(uint16_t team);
milind-u086d7262022-01-19 20:44:18 -0800255
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800256// Calls MakeValues with aos::network::GetTeamNumber()
257Values MakeValues();
milind-u086d7262022-01-19 20:44:18 -0800258
259} // namespace constants
260} // namespace y2022
261
262#endif // Y2022_CONSTANTS_H_