blob: 9906ffd496529a7e114112df0a14eaeea93e1998 [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
Ravago Jones937587c2020-12-26 17:21:09 -080047 static constexpr double kHoodEncoderRatio() {
48 // TODO: This math is not quite right
49 // 10.211 in of travel gets you 1 radian on the output
50 const double radians_per_in_travel = 1.0 / 10.211;
51
Austin Schuh72a878d2021-03-06 20:16:06 -080052 // one turn on the leadscrew gets you 0.5 in travel
53 const double in_travel_per_radian = 0.5 / (2.0 * M_PI);
Ravago Jones937587c2020-12-26 17:21:09 -080054
55 // units reduce; radians on the encoder * this number = radians on the hood
Austin Schuh72a878d2021-03-06 20:16:06 -080056 return in_travel_per_radian * radians_per_in_travel;
Ravago Jones937587c2020-12-26 17:21:09 -080057 }
58
59 static constexpr double kHoodSingleTurnEncoderRatio() { return 8.0 / 72.0; }
Sabina Davisa587fbd2020-01-31 22:11:15 -080060
61 static constexpr double kMaxHoodEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -080062 return control_loops::superstructure::hood::kFreeSpeed / (2.0 * M_PI) *
Sabina Davisa587fbd2020-01-31 22:11:15 -080063 control_loops::superstructure::hood::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -080064 kHoodEncoderRatio() * kHoodEncoderCountsPerRevolution();
Sabina Davisa587fbd2020-01-31 22:11:15 -080065 }
66
67 static constexpr ::frc971::constants::Range kHoodRange() {
68 return ::frc971::constants::Range{
Austin Schuh2efe1682021-03-06 22:47:15 -080069 -0.01, // Back Hard
70 0.65, // Front Hard
71 0.00, // Back Soft
72 0.63 // Front Soft
Sabina Davisa587fbd2020-01-31 22:11:15 -080073 };
74 }
75
Kai Tinkess10943cf2020-02-01 15:49:57 -080076 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
Ravago Jones937587c2020-12-26 17:21:09 -080077 ::frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingEstimator>
Kai Tinkess10943cf2020-02-01 15:49:57 -080078 hood;
79
Sabina Davise8d38992020-02-02 15:00:31 -080080 // Intake
81 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
82
83 static constexpr double kIntakeEncoderRatio() { return (16.0 / 32.0); }
84
85 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -080086 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
Sabina Davise8d38992020-02-02 15:00:31 -080087 control_loops::superstructure::intake::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -080088 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
Sabina Davise8d38992020-02-02 15:00:31 -080089 }
90
Sabina Davise8d38992020-02-02 15:00:31 -080091 static constexpr ::frc971::constants::Range kIntakeRange() {
92 return ::frc971::constants::Range{
Sabina Davisf7afd112020-02-23 13:42:14 -080093 -1.05, // Back Hard
94 1.44, // Front Hard
95 -0.89, // Back Soft
96 1.26 // Front Soft
Sabina Davise8d38992020-02-02 15:00:31 -080097 };
98 }
99
Sabina Davisf7afd112020-02-23 13:42:14 -0800100 static constexpr double kIntakeZero() { return -57 * M_PI / 180.0; }
101
Sabina Davisa587fbd2020-01-31 22:11:15 -0800102 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
103 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
Sabina Davise8d38992020-02-02 15:00:31 -0800104 intake;
Kai Tinkess10943cf2020-02-01 15:49:57 -0800105
Alex Perryc4691f52020-02-17 19:20:01 -0800106 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 30.0; }
107 static constexpr double kIntakeRollerStatorCurrentLimit() { return 40.0; }
108
Austin Schuhdf240b42021-10-13 21:33:43 -0700109 static constexpr double kFeederSupplyCurrentLimit() { return 40.0; }
110 static constexpr double kFeederStatorCurrentLimit() { return 50.0; }
Ravago Jones3dda5602021-03-10 00:33:13 -0800111
Kai Tinkess10943cf2020-02-01 15:49:57 -0800112 // Turret
113 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
114
115 static constexpr double kTurretEncoderRatio() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800116 return (26.0 / 150.0) * (130.0 / 26.0);
Kai Tinkess10943cf2020-02-01 15:49:57 -0800117 }
118
119 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -0800120 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
Kai Tinkess10943cf2020-02-01 15:49:57 -0800121 control_loops::superstructure::turret::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -0800122 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
Kai Tinkess10943cf2020-02-01 15:49:57 -0800123 }
124
Austin Schuh9dcd5202020-02-20 20:06:04 -0800125 static constexpr double kTurretPotRatio() { return (26.0 / 150.0); }
Kai Tinkess10943cf2020-02-01 15:49:57 -0800126
127 static constexpr ::frc971::constants::Range kTurretRange() {
128 return ::frc971::constants::Range{
Sabina Davisf7afd112020-02-23 13:42:14 -0800129 -4.6, // Back Hard
130 4.85, // Front Hard
131 -4.3, // Back Soft
132 4.7123 // Front Soft
Kai Tinkess10943cf2020-02-01 15:49:57 -0800133 };
134 }
135
136 struct PotAndAbsEncoderConstants {
137 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
138 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
139 subsystem_params;
140 double potentiometer_offset;
141 };
142
143 PotAndAbsEncoderConstants turret;
ravago901c4262020-02-16 15:33:14 -0800144
145 // Control Panel
146
147 // Mag encoder
148 static constexpr double kControlPanelEncoderCountsPerRevolution() {
149 return 4096.0;
150 }
151
152 // Ratio is encoder to output
153 static constexpr double kControlPanelEncoderRatio() { return (56.0 / 28.0); }
154
155 static constexpr double kMaxControlPanelEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -0800156 return control_loops::superstructure::control_panel::kFreeSpeed /
157 (2.0 * M_PI) *
ravago901c4262020-02-16 15:33:14 -0800158 control_loops::superstructure::control_panel::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -0800159 kControlPanelEncoderRatio() *
ravago901c4262020-02-16 15:33:14 -0800160 kControlPanelEncoderCountsPerRevolution();
161 }
Alex Perryc4691f52020-02-17 19:20:01 -0800162
163 // Shooter
Alex Perryc4691f52020-02-17 19:20:01 -0800164 static constexpr double kFinisherEncoderCountsPerRevolution() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800165 return 2048.0;
Alex Perryc4691f52020-02-17 19:20:01 -0800166 }
Austin Schuh0ad31d72021-03-06 17:07:04 -0800167 static constexpr double kFinisherEncoderRatio() { return 36.0 / 40.0; }
Austin Schuh9dcd5202020-02-20 20:06:04 -0800168
169 static constexpr double kMaxFinisherEncoderPulsesPerSecond() {
170 return control_loops::superstructure::finisher::kFreeSpeed / (2.0 * M_PI) *
171 control_loops::superstructure::finisher::kOutputRatio /
172 kFinisherEncoderRatio() * kFinisherEncoderCountsPerRevolution();
173 }
174
Alex Perryc4691f52020-02-17 19:20:01 -0800175 static constexpr double kAcceleratorEncoderCountsPerRevolution() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800176 return 2048.0;
Alex Perryc4691f52020-02-17 19:20:01 -0800177 }
Austin Schuh9dcd5202020-02-20 20:06:04 -0800178 static constexpr double kAcceleratorEncoderRatio() {
179 return (1.2 * 1.2 * 1.2) * (30.0 / 40.0);
180 }
181
182 static constexpr double kMaxAcceleratorEncoderPulsesPerSecond() {
183 return control_loops::superstructure::accelerator::kFreeSpeed /
184 (2.0 * M_PI) *
185 control_loops::superstructure::accelerator::kOutputRatio /
186 kAcceleratorEncoderRatio() *
187 kAcceleratorEncoderCountsPerRevolution();
188 }
Alex Perryc4691f52020-02-17 19:20:01 -0800189
190 // Climber
191 static constexpr double kClimberSupplyCurrentLimit() { return 60.0; }
James Kuszmaul98154a22021-04-03 16:09:29 -0700192
193 struct ShotParams {
194 // Measured in radians
195 double hood_angle;
milind-u0a178a82021-09-28 18:42:09 -0700196 // Muzzle velocity (m/s) of the ball as it is shot out of the shooter.
197 double velocity_ball;
James Kuszmaul98154a22021-04-03 16:09:29 -0700198
199 static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2) {
200 using ::frc971::shooter_interpolation::Blend;
milind-u0a178a82021-09-28 18:42:09 -0700201 return ShotParams{Blend(coefficient, a1.hood_angle, a2.hood_angle),
202 Blend(coefficient, a1.velocity_ball, a2.velocity_ball)};
James Kuszmaul98154a22021-04-03 16:09:29 -0700203 }
204 };
205
milind-u0a178a82021-09-28 18:42:09 -0700206 struct FlywheelShotParams {
207 // Angular velocity in radians per second of the slowest (lowest) wheel in
208 // the kicker. Positive is shooting the ball.
209 double velocity_accelerator;
210 // Angular velocity in radians per seconds of the flywheel. Positive is
211 // shooting.
212 double velocity_finisher;
213
214 static FlywheelShotParams BlendY(double coefficient, FlywheelShotParams a1,
215 FlywheelShotParams a2) {
216 using ::frc971::shooter_interpolation::Blend;
217 return FlywheelShotParams{
218 Blend(coefficient, a1.velocity_accelerator, a2.velocity_accelerator),
219 Blend(coefficient, a1.velocity_finisher, a2.velocity_finisher)};
220 }
221 };
222
223 // { distance_to_target, { hood_angle, velocity_ball }}
Tyler Chatowbf0609c2021-07-31 16:13:27 -0700224 InterpolationTable<ShotParams> shot_interpolation_table;
milind-u0a178a82021-09-28 18:42:09 -0700225 // { velocity_ball, { velocity_accelerator, velocity_finisher }}
226 InterpolationTable<FlywheelShotParams> flywheel_shot_interpolation_table;
Stephan Massaltd021f972020-01-05 20:41:23 -0800227};
228
milind-u62d4a8e2021-10-11 16:08:41 -0700229// Creates (once) a Values instance for ::aos::network::GetTeamNumber(). Should
230// be called before realtime because this allocates memory.
231void InitValues();
Stephan Massaltd021f972020-01-05 20:41:23 -0800232
milind-u62d4a8e2021-10-11 16:08:41 -0700233// Returns a reference to the Values instance for
234// ::aos::network::GetTeamNumber(). Values must be initialized through
235// InitValues() before calling this.
236const Values &GetValues();
Stephan Massaltd021f972020-01-05 20:41:23 -0800237
238} // namespace constants
239} // namespace y2020
240
241#endif // y2020_CONSTANTS_H_