blob: f4100149a57b2f6199485bed3173d73905e2ecf2 [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
23struct Values {
24 static const int kZeroingSampleSize = 200;
25
26 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
27 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
28 return kDrivetrainCyclesPerRevolution() * 4;
29 }
James Kuszmaulc2b2a802022-02-25 21:59:31 -080030 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
milind-u086d7262022-01-19 20:44:18 -080031 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
32 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
33 control_loops::drivetrain::kHighOutputRatio /
34 constants::Values::kDrivetrainEncoderRatio() *
35 kDrivetrainEncoderCountsPerRevolution();
36 }
James Kuszmaul53507e12022-02-12 18:36:40 -080037
38 static double DrivetrainEncoderToMeters(int32_t in) {
39 return ((static_cast<double>(in) /
40 kDrivetrainEncoderCountsPerRevolution()) *
41 (2.0 * M_PI)) *
Henry Speiser55aa3ba2022-02-21 23:21:12 -080042 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
Yash Chainani997a7492022-01-29 15:48:56 -080043 }
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080044
milind-u086d7262022-01-19 20:44:18 -080045 // Climber
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080046 static constexpr ::frc971::constants::Range kClimberRange() {
Milind Upadhyaye9075d12022-04-12 22:45:16 -070047 return ::frc971::constants::Range{.lower_hard = -0.01,
48 .upper_hard = 0.59,
49 .lower = 0.003,
50 .upper = 0.555};
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080051 }
52 static constexpr double kClimberPotMetersPerRevolution() {
53 return 22 * 0.25 * 0.0254;
54 }
55 static constexpr double kClimberPotRatio() { return 1.0; }
56
57 struct PotConstants {
58 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
59 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
60 subsystem_params;
61 double potentiometer_offset;
62 };
63
64 PotConstants climber;
Milo Lin6b5e4582022-01-29 14:51:37 -080065
66 // Intake
67 // two encoders with same gear ratio for intake
Henry Speiser55aa3ba2022-02-21 23:21:12 -080068 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
Milo Lin6b5e4582022-01-29 14:51:37 -080069
70 static constexpr double kIntakeEncoderRatio() {
Austin Schuh275f9812022-03-05 14:02:37 -080071 return (16.0 / 64.0) * (18.0 / 62.0);
Milo Lin6b5e4582022-01-29 14:51:37 -080072 }
73
Henry Speiser55aa3ba2022-02-21 23:21:12 -080074 static constexpr double kIntakePotRatio() { return 16.0 / 64.0; }
75
76 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
77 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
78 control_loops::superstructure::intake::kOutputRatio /
79 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
80 }
81
82 struct PotAndAbsEncoderConstants {
83 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
84 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
85 subsystem_params;
86 double potentiometer_offset;
87 };
88
89 PotAndAbsEncoderConstants intake_front;
90 PotAndAbsEncoderConstants intake_back;
91
92 // TODO (Yash): Constants need to be tuned
93 static constexpr ::frc971::constants::Range kIntakeRange() {
94 return ::frc971::constants::Range{
Austin Schuh465a2882022-03-05 15:39:04 -080095 .lower_hard = -0.85, // Back Hard
96 .upper_hard = 1.85, // Front Hard
97 .lower = -0.400, // Back Soft
98 .upper = 1.57 // Front Soft
Henry Speiser55aa3ba2022-02-21 23:21:12 -080099 };
100 }
101
102 // Intake rollers
103 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; }
104 static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; }
105
Ravago Jones5da06352022-03-04 20:26:24 -0800106 // Transfer rollers
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800107 static constexpr double kTransferRollerVoltage() { return 12.0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800108
109 // Voltage to wiggle the transfer rollers and keep a ball in.
Milind Upadhyayb1a74ea2022-03-09 20:34:35 -0800110 static constexpr double kTransferRollerWiggleVoltage() { return 3.0; }
111
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800112 // Turret
113 PotAndAbsEncoderConstants turret;
Milind Upadhyaye9075d12022-04-12 22:45:16 -0700114 frc971::constants::Range turret_range;
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800115
Austin Schuh42d7e5f2022-03-16 23:35:09 -0700116 static constexpr double kTurretBackIntakePos() { return -M_PI; }
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800117 static constexpr double kTurretFrontIntakePos() { return 0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800118
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800119 static constexpr double kTurretPotRatio() { return 27.0 / 110.0; }
120 static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); }
121 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
122
123 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
124 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
125 control_loops::superstructure::turret::kOutputRatio /
126 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
127 }
Griffin Buibcbef482022-02-23 15:32:10 -0800128
129 // Flipper arms
milind-u37dc40b2022-03-08 19:51:27 -0800130 static constexpr double kFlipperArmSupplyCurrentLimit() { return 40.0; }
131 static constexpr double kFlipperArmStatorCurrentLimit() { return 60.0; }
Griffin Buibcbef482022-02-23 15:32:10 -0800132
Ravago Jones5da06352022-03-04 20:26:24 -0800133 // Voltage to open the flippers for firing
134 static constexpr double kFlipperOpenVoltage() { return 3.0; }
135 // Voltage to keep the flippers open for firing once they already are
Austin Schuh465a2882022-03-05 15:39:04 -0800136 static constexpr double kFlipperHoldVoltage() { return 2.5; }
Ravago Jones5da06352022-03-04 20:26:24 -0800137 // Voltage to feed a ball from the transfer rollers to the catpult with the
138 // flippers
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800139 static constexpr double kFlipperFeedVoltage() { return -12.0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800140
141 // Ball is fed into catapult for atleast this time no matter what
142 static constexpr std::chrono::milliseconds kExtraLoadingTime() {
143 return std::chrono::milliseconds(100);
144 }
145 // If we have been trying to transfer the ball for this amount of time, it
146 // probably got lost so abort
147 static constexpr std::chrono::seconds kBallLostTime() {
148 return std::chrono::seconds(2);
149 }
150 // If the flippers took more than this amount of time to open for firing,
151 // reseat the ball
152 static constexpr std::chrono::milliseconds kFlipperOpeningTimeout() {
milind-u37dc40b2022-03-08 19:51:27 -0800153 return std::chrono::milliseconds(1000);
Ravago Jones5da06352022-03-04 20:26:24 -0800154 }
155 // Don't use flipper velocity readings more than this amount of time in the
156 // past
157 static constexpr std::chrono::milliseconds kFlipperVelocityValidTime() {
158 return std::chrono::milliseconds(100);
159 }
160
Griffin Buibcbef482022-02-23 15:32:10 -0800161 // TODO: (Griffin) this needs to be set
162 static constexpr ::frc971::constants::Range kFlipperArmRange() {
163 return ::frc971::constants::Range{
Austin Schuh465a2882022-03-05 15:39:04 -0800164 .lower_hard = -0.01, .upper_hard = 0.4, .lower = 0.0, .upper = 0.5};
Griffin Buibcbef482022-02-23 15:32:10 -0800165 }
Ravago Jones5da06352022-03-04 20:26:24 -0800166 // Position of the flippers when they are open
Austin Schuh6b1e4d92022-03-12 12:02:46 -0800167 static constexpr double kFlipperOpenPosition() { return 0.20; }
Ravago Jones5da06352022-03-04 20:26:24 -0800168 // If the flippers were open but now moved back, reseat the ball if they go
169 // below this position
Austin Schuh465a2882022-03-05 15:39:04 -0800170 static constexpr double kReseatFlipperPosition() { return 0.1; }
Griffin Buibcbef482022-02-23 15:32:10 -0800171
172 static constexpr double kFlipperArmsPotRatio() { return 16.0 / 36.0; }
173
174 PotConstants flipper_arm_left;
175 PotConstants flipper_arm_right;
Austin Schuh39f26f62022-02-24 21:34:46 -0800176
177 // Catapult.
178 static constexpr double kCatapultPotRatio() { return (12.0 / 33.0); }
179 static constexpr double kCatapultEncoderRatio() {
180 return kCatapultPotRatio();
181 }
182 static constexpr double kCatapultEncoderCountsPerRevolution() {
183 return 4096.0;
184 }
185
186 static constexpr double kMaxCatapultEncoderPulsesPerSecond() {
187 return control_loops::superstructure::catapult::kFreeSpeed / (2.0 * M_PI) *
188 control_loops::superstructure::catapult::kOutputRatio /
189 kCatapultEncoderRatio() * kCatapultEncoderCountsPerRevolution();
190 }
191 static constexpr ::frc971::constants::Range kCatapultRange() {
192 return ::frc971::constants::Range{
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800193 .lower_hard = -1.0,
Austin Schuh39f26f62022-02-24 21:34:46 -0800194 .upper_hard = 2.0,
milind-u37dc40b2022-03-08 19:51:27 -0800195 .lower = -0.91,
Austin Schuh39f26f62022-02-24 21:34:46 -0800196 .upper = 1.57,
197 };
198 }
199
200 PotAndAbsEncoderConstants catapult;
milind-ucafdd5d2022-03-01 19:58:57 -0800201
202 // TODO(milind): set this
203 static constexpr double kImuHeight() { return 0.0; }
Ravago Jones3283ce02022-03-09 19:31:29 -0800204
205 struct ShotParams {
206 // Measured in radians
207 double shot_angle;
208 // Muzzle velocity (m/s) of the ball as it is released from the catapult.
209 double shot_velocity;
210
211 static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2) {
212 using ::frc971::shooter_interpolation::Blend;
213 return ShotParams{
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700214 .shot_angle = Blend(coefficient, a1.shot_angle, a2.shot_angle),
215 .shot_velocity =
216 Blend(coefficient, a1.shot_velocity, a2.shot_velocity),
Ravago Jones3283ce02022-03-09 19:31:29 -0800217 };
218 }
219 };
220
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700221 struct ShotVelocityParams {
222 // Speed over ground to use for shooting-on-the-fly.
223 double shot_speed_over_ground;
224
225 static ShotVelocityParams BlendY(double coefficient, ShotVelocityParams a1,
226 ShotVelocityParams a2) {
227 using ::frc971::shooter_interpolation::Blend;
228 return ShotVelocityParams{Blend(coefficient, a1.shot_speed_over_ground,
229 a2.shot_speed_over_ground)};
230 }
231 };
232
Ravago Jones3283ce02022-03-09 19:31:29 -0800233 InterpolationTable<ShotParams> shot_interpolation_table;
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700234
235 InterpolationTable<ShotVelocityParams> shot_velocity_interpolation_table;
milind-u086d7262022-01-19 20:44:18 -0800236};
237
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800238// Creates and returns a Values instance for the constants.
239// Should be called before realtime because this allocates memory.
240// Only the first call to either of these will be used.
241Values MakeValues(uint16_t team);
milind-u086d7262022-01-19 20:44:18 -0800242
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800243// Calls MakeValues with aos::network::GetTeamNumber()
244Values MakeValues();
milind-u086d7262022-01-19 20:44:18 -0800245
246} // namespace constants
247} // namespace y2022
248
249#endif // Y2022_CONSTANTS_H_