blob: 77f78f4d8ef32dbfcb952ba7299fdb15e6eb9b96 [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 {
Austin Schuh83873c32020-02-22 14:58:39 -080025 static const uint16_t kCodingRobotTeamNumber = 7971;
26
Stephan Massaltd021f972020-01-05 20:41:23 -080027 static const int kZeroingSampleSize = 200;
28
29 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
30 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
31 return kDrivetrainCyclesPerRevolution() * 4;
32 }
Austin Schuh9dcd5202020-02-20 20:06:04 -080033 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
Stephan Massaltd021f972020-01-05 20:41:23 -080034 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
35 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
Austin Schuh9dcd5202020-02-20 20:06:04 -080036 control_loops::drivetrain::kHighGearRatio /
Stephan Massaltd021f972020-01-05 20:41:23 -080037 constants::Values::kDrivetrainEncoderRatio() *
38 kDrivetrainEncoderCountsPerRevolution();
39 }
Sabina Davisa587fbd2020-01-31 22:11:15 -080040
41 // Hood
42 static constexpr double kHoodEncoderCountsPerRevolution() { return 4096.0; }
43
Ravago Jones937587c2020-12-26 17:21:09 -080044 static constexpr double kHoodEncoderRatio() {
45 // TODO: This math is not quite right
46 // 10.211 in of travel gets you 1 radian on the output
47 const double radians_per_in_travel = 1.0 / 10.211;
48
Austin Schuh72a878d2021-03-06 20:16:06 -080049 // one turn on the leadscrew gets you 0.5 in travel
50 const double in_travel_per_radian = 0.5 / (2.0 * M_PI);
Ravago Jones937587c2020-12-26 17:21:09 -080051
52 // units reduce; radians on the encoder * this number = radians on the hood
Austin Schuh72a878d2021-03-06 20:16:06 -080053 return in_travel_per_radian * radians_per_in_travel;
Ravago Jones937587c2020-12-26 17:21:09 -080054 }
55
56 static constexpr double kHoodSingleTurnEncoderRatio() { return 8.0 / 72.0; }
Sabina Davisa587fbd2020-01-31 22:11:15 -080057
58 static constexpr double kMaxHoodEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -080059 return control_loops::superstructure::hood::kFreeSpeed / (2.0 * M_PI) *
Sabina Davisa587fbd2020-01-31 22:11:15 -080060 control_loops::superstructure::hood::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -080061 kHoodEncoderRatio() * kHoodEncoderCountsPerRevolution();
Sabina Davisa587fbd2020-01-31 22:11:15 -080062 }
63
64 static constexpr ::frc971::constants::Range kHoodRange() {
65 return ::frc971::constants::Range{
Austin Schuh2efe1682021-03-06 22:47:15 -080066 -0.01, // Back Hard
67 0.65, // Front Hard
68 0.00, // Back Soft
69 0.63 // Front Soft
Sabina Davisa587fbd2020-01-31 22:11:15 -080070 };
71 }
72
Kai Tinkess10943cf2020-02-01 15:49:57 -080073 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
Ravago Jones937587c2020-12-26 17:21:09 -080074 ::frc971::zeroing::AbsoluteAndAbsoluteEncoderZeroingEstimator>
Kai Tinkess10943cf2020-02-01 15:49:57 -080075 hood;
76
Sabina Davise8d38992020-02-02 15:00:31 -080077 // Intake
78 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
79
80 static constexpr double kIntakeEncoderRatio() { return (16.0 / 32.0); }
81
82 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -080083 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
Sabina Davise8d38992020-02-02 15:00:31 -080084 control_loops::superstructure::intake::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -080085 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
Sabina Davise8d38992020-02-02 15:00:31 -080086 }
87
Sabina Davise8d38992020-02-02 15:00:31 -080088 static constexpr ::frc971::constants::Range kIntakeRange() {
89 return ::frc971::constants::Range{
Sabina Davisf7afd112020-02-23 13:42:14 -080090 -1.05, // Back Hard
91 1.44, // Front Hard
92 -0.89, // Back Soft
93 1.26 // Front Soft
Sabina Davise8d38992020-02-02 15:00:31 -080094 };
95 }
96
Sabina Davisf7afd112020-02-23 13:42:14 -080097 static constexpr double kIntakeZero() { return -57 * M_PI / 180.0; }
98
Sabina Davisa587fbd2020-01-31 22:11:15 -080099 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
100 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator>
Sabina Davise8d38992020-02-02 15:00:31 -0800101 intake;
Kai Tinkess10943cf2020-02-01 15:49:57 -0800102
Alex Perryc4691f52020-02-17 19:20:01 -0800103 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 30.0; }
104 static constexpr double kIntakeRollerStatorCurrentLimit() { return 40.0; }
105
Ravago Jones3dda5602021-03-10 00:33:13 -0800106 static constexpr double kFeederSupplyCurrentLimit() { return 30.0; }
107 static constexpr double kFeederStatorCurrentLimit() { return 40.0; }
108
Kai Tinkess10943cf2020-02-01 15:49:57 -0800109 // Turret
110 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
111
112 static constexpr double kTurretEncoderRatio() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800113 return (26.0 / 150.0) * (130.0 / 26.0);
Kai Tinkess10943cf2020-02-01 15:49:57 -0800114 }
115
116 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -0800117 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
Kai Tinkess10943cf2020-02-01 15:49:57 -0800118 control_loops::superstructure::turret::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -0800119 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
Kai Tinkess10943cf2020-02-01 15:49:57 -0800120 }
121
Austin Schuh9dcd5202020-02-20 20:06:04 -0800122 static constexpr double kTurretPotRatio() { return (26.0 / 150.0); }
Kai Tinkess10943cf2020-02-01 15:49:57 -0800123
124 static constexpr ::frc971::constants::Range kTurretRange() {
125 return ::frc971::constants::Range{
Sabina Davisf7afd112020-02-23 13:42:14 -0800126 -4.6, // Back Hard
127 4.85, // Front Hard
128 -4.3, // Back Soft
129 4.7123 // Front Soft
Kai Tinkess10943cf2020-02-01 15:49:57 -0800130 };
131 }
132
133 struct PotAndAbsEncoderConstants {
134 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
135 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
136 subsystem_params;
137 double potentiometer_offset;
138 };
139
140 PotAndAbsEncoderConstants turret;
ravago901c4262020-02-16 15:33:14 -0800141
142 // Control Panel
143
144 // Mag encoder
145 static constexpr double kControlPanelEncoderCountsPerRevolution() {
146 return 4096.0;
147 }
148
149 // Ratio is encoder to output
150 static constexpr double kControlPanelEncoderRatio() { return (56.0 / 28.0); }
151
152 static constexpr double kMaxControlPanelEncoderPulsesPerSecond() {
Austin Schuh9dcd5202020-02-20 20:06:04 -0800153 return control_loops::superstructure::control_panel::kFreeSpeed /
154 (2.0 * M_PI) *
ravago901c4262020-02-16 15:33:14 -0800155 control_loops::superstructure::control_panel::kOutputRatio /
Austin Schuh9dcd5202020-02-20 20:06:04 -0800156 kControlPanelEncoderRatio() *
ravago901c4262020-02-16 15:33:14 -0800157 kControlPanelEncoderCountsPerRevolution();
158 }
Alex Perryc4691f52020-02-17 19:20:01 -0800159
160 // Shooter
Alex Perryc4691f52020-02-17 19:20:01 -0800161 static constexpr double kFinisherEncoderCountsPerRevolution() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800162 return 2048.0;
Alex Perryc4691f52020-02-17 19:20:01 -0800163 }
Austin Schuh0ad31d72021-03-06 17:07:04 -0800164 static constexpr double kFinisherEncoderRatio() { return 36.0 / 40.0; }
Austin Schuh9dcd5202020-02-20 20:06:04 -0800165
166 static constexpr double kMaxFinisherEncoderPulsesPerSecond() {
167 return control_loops::superstructure::finisher::kFreeSpeed / (2.0 * M_PI) *
168 control_loops::superstructure::finisher::kOutputRatio /
169 kFinisherEncoderRatio() * kFinisherEncoderCountsPerRevolution();
170 }
171
Alex Perryc4691f52020-02-17 19:20:01 -0800172 static constexpr double kAcceleratorEncoderCountsPerRevolution() {
Sabina Davisf7afd112020-02-23 13:42:14 -0800173 return 2048.0;
Alex Perryc4691f52020-02-17 19:20:01 -0800174 }
Austin Schuh9dcd5202020-02-20 20:06:04 -0800175 static constexpr double kAcceleratorEncoderRatio() {
176 return (1.2 * 1.2 * 1.2) * (30.0 / 40.0);
177 }
178
179 static constexpr double kMaxAcceleratorEncoderPulsesPerSecond() {
180 return control_loops::superstructure::accelerator::kFreeSpeed /
181 (2.0 * M_PI) *
182 control_loops::superstructure::accelerator::kOutputRatio /
183 kAcceleratorEncoderRatio() *
184 kAcceleratorEncoderCountsPerRevolution();
185 }
Alex Perryc4691f52020-02-17 19:20:01 -0800186
187 // Climber
188 static constexpr double kClimberSupplyCurrentLimit() { return 60.0; }
James Kuszmaul98154a22021-04-03 16:09:29 -0700189
190 struct ShotParams {
191 // Measured in radians
192 double hood_angle;
Tyler Chatowbf0609c2021-07-31 16:13:27 -0700193 // Angular velocity in radians per second of the slowest (lowest) wheel in
194 // the kicker. Positive is shooting the ball.
James Kuszmaul98154a22021-04-03 16:09:29 -0700195 double accelerator_power;
Tyler Chatowbf0609c2021-07-31 16:13:27 -0700196 // Angular velocity in radians per seconds of the flywheel. Positive is
197 // shooting.
James Kuszmaul98154a22021-04-03 16:09:29 -0700198 double finisher_power;
199
200 static ShotParams BlendY(double coefficient, ShotParams a1, ShotParams a2) {
201 using ::frc971::shooter_interpolation::Blend;
202 return ShotParams{
203 Blend(coefficient, a1.hood_angle, a2.hood_angle),
204 Blend(coefficient, a1.accelerator_power, a2.accelerator_power),
205 Blend(coefficient, a1.finisher_power, a2.finisher_power)};
206 }
207 };
208
209 // { distance_to_target, { hood_angle, accelerator_power, finisher_power }}
Tyler Chatowbf0609c2021-07-31 16:13:27 -0700210 InterpolationTable<ShotParams> shot_interpolation_table;
Stephan Massaltd021f972020-01-05 20:41:23 -0800211};
212
213// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
214// returns a reference to it.
215const Values &GetValues();
216
Sabina Davise8d38992020-02-02 15:00:31 -0800217// Creates Values instances for each team number it is called with and
218// returns them.
Stephan Massaltd021f972020-01-05 20:41:23 -0800219const Values &GetValuesForTeam(uint16_t team_number);
220
221} // namespace constants
222} // namespace y2020
223
224#endif // y2020_CONSTANTS_H_