blob: 9dfed4445f4c543c9c5c2238925959c95cbd625a [file] [log] [blame]
Stephan Massaltd021f972020-01-05 20:41:23 -08001#ifndef y2020_CONSTANTS_H_
2#define y2020_CONSTANTS_H_
3
Stephan Massaltd021f972020-01-05 20:41:23 -08004#include <array>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07005#include <cmath>
6#include <cstdint>
Stephan Massaltd021f972020-01-05 20:41:23 -08007
8#include "frc971/constants.h"
Stephan Massaltd021f972020-01-05 20:41:23 -08009#include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h"
James Kuszmaul98154a22021-04-03 16:09:29 -070010#include "frc971/shooter_interpolation/interpolation.h"
Stephan Massaltd021f972020-01-05 20:41:23 -080011#include "y2020/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Austin Schuh9dcd5202020-02-20 20:06:04 -080012#include "y2020/control_loops/superstructure/accelerator/accelerator_plant.h"
ravago901c4262020-02-16 15:33:14 -080013#include "y2020/control_loops/superstructure/control_panel/control_panel_plant.h"
Austin Schuh9dcd5202020-02-20 20:06:04 -080014#include "y2020/control_loops/superstructure/finisher/finisher_plant.h"
Sabina Davisa587fbd2020-01-31 22:11:15 -080015#include "y2020/control_loops/superstructure/hood/hood_plant.h"
Sabina Davise8d38992020-02-02 15:00:31 -080016#include "y2020/control_loops/superstructure/intake/intake_plant.h"
Kai Tinkess10943cf2020-02-01 15:49:57 -080017#include "y2020/control_loops/superstructure/turret/turret_plant.h"
Stephan Massaltd021f972020-01-05 20:41:23 -080018
James Kuszmaul98154a22021-04-03 16:09:29 -070019using ::frc971::shooter_interpolation::InterpolationTable;
20
Stephan Massaltd021f972020-01-05 20:41:23 -080021namespace y2020 {
22namespace constants {
23
24struct Values {
James Kuszmaul0a981402021-10-09 21:00:34 -070025 static const uint16_t kCompTeamNumber = 971;
26 static const uint16_t kPracticeTeamNumber = 9971;
Austin Schuh83873c32020-02-22 14:58:39 -080027 static const uint16_t kCodingRobotTeamNumber = 7971;
James Kuszmaul0a981402021-10-09 21:00:34 -070028 static const uint16_t kSpareRoborioTeamNumber = 6971;
Austin Schuh83873c32020-02-22 14:58:39 -080029
Stephan Massaltd021f972020-01-05 20:41:23 -080030 static const int kZeroingSampleSize = 200;
31
32 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
33 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
34 return kDrivetrainCyclesPerRevolution() * 4;
35 }
Austin Schuh9dcd5202020-02-20 20:06:04 -080036 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
Stephan Massaltd021f972020-01-05 20:41:23 -080037 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
38 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
Austin Schuh9dcd5202020-02-20 20:06:04 -080039 control_loops::drivetrain::kHighGearRatio /
Stephan Massaltd021f972020-01-05 20:41:23 -080040 constants::Values::kDrivetrainEncoderRatio() *
41 kDrivetrainEncoderCountsPerRevolution();
42 }
Sabina Davisa587fbd2020-01-31 22:11:15 -080043
44 // Hood
45 static constexpr double kHoodEncoderCountsPerRevolution() { return 4096.0; }
46
milind-ud53408e2021-10-21 19:43:58 -070047 // TODO: This math is not quite right
48 // 10.211 in of travel gets you 1 radian on the output
49 static constexpr double kHoodEncoderRadiansPerInTravel() {
50 return 1.0 / 10.211;
51 }
Ravago Jones937587c2020-12-26 17:21:09 -080052
milind-ud53408e2021-10-21 19:43:58 -070053 static constexpr double kHoodEncoderRatio() {
Austin Schuh72a878d2021-03-06 20:16:06 -080054 // one turn on the leadscrew gets you 0.5 in travel
55 const double in_travel_per_radian = 0.5 / (2.0 * M_PI);
Ravago Jones937587c2020-12-26 17:21:09 -080056
57 // units reduce; radians on the encoder * this number = radians on the hood
milind-ud53408e2021-10-21 19:43:58 -070058 return in_travel_per_radian * kHoodEncoderRadiansPerInTravel();
Ravago Jones937587c2020-12-26 17:21:09 -080059 }
60
61 static constexpr double kHoodSingleTurnEncoderRatio() { return 8.0 / 72.0; }
Sabina Davisa587fbd2020-01-31 22:11:15 -080062
63 static constexpr double kMaxHoodEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -080064 return control_loops::superstructure::hood::kFreeSpeed / (2.0 * M_PI) *
Sabina Davisa587fbd2020-01-31 22:11:15 -080065 control_loops::superstructure::hood::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -080066 kHoodEncoderRatio() * kHoodEncoderCountsPerRevolution();
Sabina Davisa587fbd2020-01-31 22:11:15 -080067 }
68
69 static constexpr ::frc971::constants::Range kHoodRange() {
70 return ::frc971::constants::Range{
Austin Schuh2efe1682021-03-06 22:47:15 -080071 -0.01, // Back Hard
72 0.65, // Front Hard
73 0.00, // Back Soft
74 0.63 // Front Soft
Sabina Davisa587fbd2020-01-31 22:11:15 -080075 };
76 }
77
milind-ud53408e2021-10-21 19:43:58 -070078 struct HoodGeometry {
79 // Measurements for hood zeroing calculations (all lengths in meters and
80 // angles in radians)
81
82 // Measurements when hood is at 0
83 double theta_0;
84 double screw_length_0;
85
86 double radius;
87 double diagonal_length;
88 double back_plate_diagonal_length;
89 };
90
Kai Tinkess10943cf2020-02-01 15:49:57 -080091 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
Ravago Jones937587c2020-12-26 17:21:09 -080092 ::frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingEstimator>
Kai Tinkess10943cf2020-02-01 15:49:57 -080093 hood;
94
milind-ud53408e2021-10-21 19:43:58 -070095 HoodGeometry hood_geometry;
96
Sabina Davise8d38992020-02-02 15:00:31 -080097 // Intake
98 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
99
100 static constexpr double kIntakeEncoderRatio() { return (16.0 / 32.0); }
101
102 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -0800103 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
Sabina Davise8d38992020-02-02 15:00:31 -0800104 control_loops::superstructure::intake::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -0800105 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
Sabina Davise8d38992020-02-02 15:00:31 -0800106 }
107
Sabina Davise8d38992020-02-02 15:00:31 -0800108 static constexpr ::frc971::constants::Range kIntakeRange() {
109 return ::frc971::constants::Range{
Sabina Davisf7afd112020-02-23 13:42:14 -0800110 -1.05, // Back Hard
111 1.44, // Front Hard
112 -0.89, // Back Soft
113 1.26 // Front Soft
Sabina Davise8d38992020-02-02 15:00:31 -0800114 };
115 }
116
Sabina Davisf7afd112020-02-23 13:42:14 -0800117 static constexpr double kIntakeZero() { return -57 * M_PI / 180.0; }
118
Sabina Davisa587fbd2020-01-31 22:11:15 -0800119 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
120 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
Sabina Davise8d38992020-02-02 15:00:31 -0800121 intake;
Kai Tinkess10943cf2020-02-01 15:49:57 -0800122
Alex Perryc4691f52020-02-17 19:20:01 -0800123 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 30.0; }
124 static constexpr double kIntakeRollerStatorCurrentLimit() { return 40.0; }
125
Austin Schuhdf240b42021-10-13 21:33:43 -0700126 static constexpr double kFeederSupplyCurrentLimit() { return 40.0; }
127 static constexpr double kFeederStatorCurrentLimit() { return 50.0; }
Ravago Jones3dda5602021-03-10 00:33:13 -0800128
Kai Tinkess10943cf2020-02-01 15:49:57 -0800129 // Turret
130 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
131
132 static constexpr double kTurretEncoderRatio() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800133 return (26.0 / 150.0) * (130.0 / 26.0);
Kai Tinkess10943cf2020-02-01 15:49:57 -0800134 }
135
136 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -0800137 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
Kai Tinkess10943cf2020-02-01 15:49:57 -0800138 control_loops::superstructure::turret::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -0800139 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
Kai Tinkess10943cf2020-02-01 15:49:57 -0800140 }
141
Austin Schuh9dcd5202020-02-20 20:06:04 -0800142 static constexpr double kTurretPotRatio() { return (26.0 / 150.0); }
Kai Tinkess10943cf2020-02-01 15:49:57 -0800143
144 static constexpr ::frc971::constants::Range kTurretRange() {
145 return ::frc971::constants::Range{
Sabina Davisf7afd112020-02-23 13:42:14 -0800146 -4.6, // Back Hard
147 4.85, // Front Hard
148 -4.3, // Back Soft
149 4.7123 // Front Soft
Kai Tinkess10943cf2020-02-01 15:49:57 -0800150 };
151 }
152
153 struct PotAndAbsEncoderConstants {
154 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
155 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
156 subsystem_params;
157 double potentiometer_offset;
158 };
159
160 PotAndAbsEncoderConstants turret;
ravago901c4262020-02-16 15:33:14 -0800161
162 // Control Panel
163
164 // Mag encoder
165 static constexpr double kControlPanelEncoderCountsPerRevolution() {
166 return 4096.0;
167 }
168
169 // Ratio is encoder to output
170 static constexpr double kControlPanelEncoderRatio() { return (56.0 / 28.0); }
171
172 static constexpr double kMaxControlPanelEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -0800173 return control_loops::superstructure::control_panel::kFreeSpeed /
174 (2.0 * M_PI) *
ravago901c4262020-02-16 15:33:14 -0800175 control_loops::superstructure::control_panel::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -0800176 kControlPanelEncoderRatio() *
ravago901c4262020-02-16 15:33:14 -0800177 kControlPanelEncoderCountsPerRevolution();
178 }
Alex Perryc4691f52020-02-17 19:20:01 -0800179
180 // Shooter
Alex Perryc4691f52020-02-17 19:20:01 -0800181 static constexpr double kFinisherEncoderCountsPerRevolution() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800182 return 2048.0;
Alex Perryc4691f52020-02-17 19:20:01 -0800183 }
Austin Schuh0ad31d72021-03-06 17:07:04 -0800184 static constexpr double kFinisherEncoderRatio() { return 36.0 / 40.0; }
Austin Schuh9dcd5202020-02-20 20:06:04 -0800185
186 static constexpr double kMaxFinisherEncoderPulsesPerSecond() {
187 return control_loops::superstructure::finisher::kFreeSpeed / (2.0 * M_PI) *
188 control_loops::superstructure::finisher::kOutputRatio /
189 kFinisherEncoderRatio() * kFinisherEncoderCountsPerRevolution();
190 }
191
Alex Perryc4691f52020-02-17 19:20:01 -0800192 static constexpr double kAcceleratorEncoderCountsPerRevolution() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800193 return 2048.0;
Alex Perryc4691f52020-02-17 19:20:01 -0800194 }
Austin Schuh9dcd5202020-02-20 20:06:04 -0800195 static constexpr double kAcceleratorEncoderRatio() {
196 return (1.2 * 1.2 * 1.2) * (30.0 / 40.0);
197 }
198
199 static constexpr double kMaxAcceleratorEncoderPulsesPerSecond() {
200 return control_loops::superstructure::accelerator::kFreeSpeed /
201 (2.0 * M_PI) *
202 control_loops::superstructure::accelerator::kOutputRatio /
203 kAcceleratorEncoderRatio() *
204 kAcceleratorEncoderCountsPerRevolution();
205 }
Alex Perryc4691f52020-02-17 19:20:01 -0800206
207 // Climber
208 static constexpr double kClimberSupplyCurrentLimit() { return 60.0; }
James Kuszmaul98154a22021-04-03 16:09:29 -0700209
210 struct ShotParams {
211 // Measured in radians
212 double hood_angle;
milind-u0a178a82021-09-28 18:42:09 -0700213 // Muzzle velocity (m/s) of the ball as it is shot out of the shooter.
214 double velocity_ball;
James Kuszmaul98154a22021-04-03 16:09:29 -0700215
216 static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2) {
217 using ::frc971::shooter_interpolation::Blend;
milind-u0a178a82021-09-28 18:42:09 -0700218 return ShotParams{Blend(coefficient, a1.hood_angle, a2.hood_angle),
219 Blend(coefficient, a1.velocity_ball, a2.velocity_ball)};
James Kuszmaul98154a22021-04-03 16:09:29 -0700220 }
221 };
222
milind-u0a178a82021-09-28 18:42:09 -0700223 struct FlywheelShotParams {
224 // Angular velocity in radians per second of the slowest (lowest) wheel in
225 // the kicker. Positive is shooting the ball.
226 double velocity_accelerator;
227 // Angular velocity in radians per seconds of the flywheel. Positive is
228 // shooting.
229 double velocity_finisher;
230
231 static FlywheelShotParams BlendY(double coefficient, FlywheelShotParams a1,
232 FlywheelShotParams a2) {
233 using ::frc971::shooter_interpolation::Blend;
234 return FlywheelShotParams{
235 Blend(coefficient, a1.velocity_accelerator, a2.velocity_accelerator),
236 Blend(coefficient, a1.velocity_finisher, a2.velocity_finisher)};
237 }
238 };
239
240 // { distance_to_target, { hood_angle, velocity_ball }}
Tyler Chatowbf0609c2021-07-31 16:13:27 -0700241 InterpolationTable<ShotParams> shot_interpolation_table;
milind-u0a178a82021-09-28 18:42:09 -0700242 // { velocity_ball, { velocity_accelerator, velocity_finisher }}
243 InterpolationTable<FlywheelShotParams> flywheel_shot_interpolation_table;
Stephan Massaltd021f972020-01-05 20:41:23 -0800244};
245
milind-u62d4a8e2021-10-11 16:08:41 -0700246// Creates (once) a Values instance for ::aos::network::GetTeamNumber(). Should
247// be called before realtime because this allocates memory.
248void InitValues();
Stephan Massaltd021f972020-01-05 20:41:23 -0800249
milind-u62d4a8e2021-10-11 16:08:41 -0700250// Returns a reference to the Values instance for
251// ::aos::network::GetTeamNumber(). Values must be initialized through
252// InitValues() before calling this.
253const Values &GetValues();
Stephan Massaltd021f972020-01-05 20:41:23 -0800254
255} // namespace constants
256} // namespace y2020
257
258#endif // y2020_CONSTANTS_H_