blob: 865a0e6b471d0b9cc196ec655c147d0aed2f1d30 [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"
11#include "y2022/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
Austin Schuh39f26f62022-02-24 21:34:46 -080012#include "y2022/control_loops/superstructure/catapult/catapult_plant.h"
Henry Speiser55aa3ba2022-02-21 23:21:12 -080013#include "y2022/control_loops/superstructure/climber/climber_plant.h"
Yash Chainani997a7492022-01-29 15:48:56 -080014#include "y2022/control_loops/superstructure/intake/intake_plant.h"
Henry Speiser55aa3ba2022-02-21 23:21:12 -080015#include "y2022/control_loops/superstructure/turret/turret_plant.h"
milind-u086d7262022-01-19 20:44:18 -080016
17namespace y2022 {
18namespace constants {
19
20struct Values {
21 static const int kZeroingSampleSize = 200;
22
23 static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
24 static constexpr double kDrivetrainEncoderCountsPerRevolution() {
25 return kDrivetrainCyclesPerRevolution() * 4;
26 }
James Kuszmaulc2b2a802022-02-25 21:59:31 -080027 static constexpr double kDrivetrainEncoderRatio() { return 1.0; }
milind-u086d7262022-01-19 20:44:18 -080028 static constexpr double kMaxDrivetrainEncoderPulsesPerSecond() {
29 return control_loops::drivetrain::kFreeSpeed / (2.0 * M_PI) *
30 control_loops::drivetrain::kHighOutputRatio /
31 constants::Values::kDrivetrainEncoderRatio() *
32 kDrivetrainEncoderCountsPerRevolution();
33 }
James Kuszmaul53507e12022-02-12 18:36:40 -080034
35 static double DrivetrainEncoderToMeters(int32_t in) {
36 return ((static_cast<double>(in) /
37 kDrivetrainEncoderCountsPerRevolution()) *
38 (2.0 * M_PI)) *
Henry Speiser55aa3ba2022-02-21 23:21:12 -080039 kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
Yash Chainani997a7492022-01-29 15:48:56 -080040 }
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080041
milind-u086d7262022-01-19 20:44:18 -080042 // Climber
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080043 static constexpr ::frc971::constants::Range kClimberRange() {
44 return ::frc971::constants::Range{
Henry Speiser55aa3ba2022-02-21 23:21:12 -080045 .lower_hard = -0.01, .upper_hard = 0.6, .lower = 0.0, .upper = 0.5};
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080046 }
47 static constexpr double kClimberPotMetersPerRevolution() {
48 return 22 * 0.25 * 0.0254;
49 }
50 static constexpr double kClimberPotRatio() { return 1.0; }
Henry Speiser0b9b0052022-03-02 23:07:40 -080051 // TODO(milind): figure this out
52 // Climber position when it's comfortably above the mid rung.
53 static constexpr double kClimberMidRungHeight() { return 1.0; }
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080054
55 struct PotConstants {
56 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
57 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
58 subsystem_params;
59 double potentiometer_offset;
60 };
61
62 PotConstants climber;
Milo Lin6b5e4582022-01-29 14:51:37 -080063
64 // Intake
65 // two encoders with same gear ratio for intake
Henry Speiser55aa3ba2022-02-21 23:21:12 -080066 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
Milo Lin6b5e4582022-01-29 14:51:37 -080067
68 static constexpr double kIntakeEncoderRatio() {
Austin Schuh275f9812022-03-05 14:02:37 -080069 return (16.0 / 64.0) * (18.0 / 62.0);
Milo Lin6b5e4582022-01-29 14:51:37 -080070 }
71
Henry Speiser55aa3ba2022-02-21 23:21:12 -080072 static constexpr double kIntakePotRatio() { return 16.0 / 64.0; }
73
74 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
75 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
76 control_loops::superstructure::intake::kOutputRatio /
77 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
78 }
79
80 struct PotAndAbsEncoderConstants {
81 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
82 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
83 subsystem_params;
84 double potentiometer_offset;
85 };
86
87 PotAndAbsEncoderConstants intake_front;
88 PotAndAbsEncoderConstants intake_back;
89
90 // TODO (Yash): Constants need to be tuned
91 static constexpr ::frc971::constants::Range kIntakeRange() {
92 return ::frc971::constants::Range{
Austin Schuh465a2882022-03-05 15:39:04 -080093 .lower_hard = -0.85, // Back Hard
94 .upper_hard = 1.85, // Front Hard
95 .lower = -0.400, // Back Soft
96 .upper = 1.57 // Front Soft
Henry Speiser55aa3ba2022-02-21 23:21:12 -080097 };
98 }
99
Henry Speiser0b9b0052022-03-02 23:07:40 -0800100 // When the intake is atleast this much out, always spin the rollers
101 static constexpr double kIntakeSlightlyOutPosition() {
102 return kIntakeRange().middle();
103 }
104 static constexpr double kIntakeOutPosition() { return 1.24; }
105
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800106 // 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 Speiser0b9b0052022-03-02 23:07:40 -0800116 // Minimum roller speed when the intake is slightly out
117 static constexpr double kMinIntakeSlightlyOutRollerSpeed() { return 6.0; }
118 // Roller speeds when intake is out
119 static constexpr double kIntakeOutRollerSpeed() { return 7.0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800120
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800121 // Turret
122 PotAndAbsEncoderConstants turret;
123
124 // TODO (Yash): Constants need to be tuned
125 static constexpr ::frc971::constants::Range kTurretRange() {
126 return ::frc971::constants::Range{
Austin Schuhcddd9042022-03-05 17:10:07 -0800127 .lower_hard = -6.0, // Back Hard
128 .upper_hard = 4.0, // Front Hard
129 .lower = -5.0, // Back Soft
130 .upper = 3.7 // Front Soft
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800131 };
132 }
133
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800134 static constexpr double kTurretBackIntakePos() { return M_PI; }
135 static constexpr double kTurretFrontIntakePos() { return 0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800136
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800137 static constexpr double kTurretPotRatio() { return 27.0 / 110.0; }
138 static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); }
139 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
140
141 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
142 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
143 control_loops::superstructure::turret::kOutputRatio /
144 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
145 }
Griffin Buibcbef482022-02-23 15:32:10 -0800146
147 // Flipper arms
milind-u37dc40b2022-03-08 19:51:27 -0800148 static constexpr double kFlipperArmSupplyCurrentLimit() { return 40.0; }
149 static constexpr double kFlipperArmStatorCurrentLimit() { return 60.0; }
Griffin Buibcbef482022-02-23 15:32:10 -0800150
Ravago Jones5da06352022-03-04 20:26:24 -0800151 // Voltage to open the flippers for firing
152 static constexpr double kFlipperOpenVoltage() { return 3.0; }
153 // Voltage to keep the flippers open for firing once they already are
Austin Schuh465a2882022-03-05 15:39:04 -0800154 static constexpr double kFlipperHoldVoltage() { return 2.5; }
Ravago Jones5da06352022-03-04 20:26:24 -0800155 // Voltage to feed a ball from the transfer rollers to the catpult with the
156 // flippers
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800157 static constexpr double kFlipperFeedVoltage() { return -12.0; }
Ravago Jones5da06352022-03-04 20:26:24 -0800158
159 // Ball is fed into catapult for atleast this time no matter what
160 static constexpr std::chrono::milliseconds kExtraLoadingTime() {
161 return std::chrono::milliseconds(100);
162 }
163 // If we have been trying to transfer the ball for this amount of time, it
164 // probably got lost so abort
165 static constexpr std::chrono::seconds kBallLostTime() {
166 return std::chrono::seconds(2);
167 }
168 // If the flippers took more than this amount of time to open for firing,
169 // reseat the ball
170 static constexpr std::chrono::milliseconds kFlipperOpeningTimeout() {
milind-u37dc40b2022-03-08 19:51:27 -0800171 return std::chrono::milliseconds(1000);
Ravago Jones5da06352022-03-04 20:26:24 -0800172 }
173 // Don't use flipper velocity readings more than this amount of time in the
174 // past
175 static constexpr std::chrono::milliseconds kFlipperVelocityValidTime() {
176 return std::chrono::milliseconds(100);
177 }
178
Griffin Buibcbef482022-02-23 15:32:10 -0800179 // TODO: (Griffin) this needs to be set
180 static constexpr ::frc971::constants::Range kFlipperArmRange() {
181 return ::frc971::constants::Range{
Austin Schuh465a2882022-03-05 15:39:04 -0800182 .lower_hard = -0.01, .upper_hard = 0.4, .lower = 0.0, .upper = 0.5};
Griffin Buibcbef482022-02-23 15:32:10 -0800183 }
Ravago Jones5da06352022-03-04 20:26:24 -0800184 // Position of the flippers when they are open
Austin Schuh465a2882022-03-05 15:39:04 -0800185 static constexpr double kFlipperOpenPosition() { return 0.15; }
Ravago Jones5da06352022-03-04 20:26:24 -0800186 // If the flippers were open but now moved back, reseat the ball if they go
187 // below this position
Austin Schuh465a2882022-03-05 15:39:04 -0800188 static constexpr double kReseatFlipperPosition() { return 0.1; }
Griffin Buibcbef482022-02-23 15:32:10 -0800189
190 static constexpr double kFlipperArmsPotRatio() { return 16.0 / 36.0; }
191
192 PotConstants flipper_arm_left;
193 PotConstants flipper_arm_right;
Austin Schuh39f26f62022-02-24 21:34:46 -0800194
195 // Catapult.
196 static constexpr double kCatapultPotRatio() { return (12.0 / 33.0); }
197 static constexpr double kCatapultEncoderRatio() {
198 return kCatapultPotRatio();
199 }
200 static constexpr double kCatapultEncoderCountsPerRevolution() {
201 return 4096.0;
202 }
Henry Speiser0b9b0052022-03-02 23:07:40 -0800203 static constexpr double kDefaultCatapultShotPosition() { return 3.0; }
204 static constexpr double kDefaultCatapultShotVelocity() { return 3.0; }
205 static constexpr double kCatapultReturnPosition() { return -0.85; }
Austin Schuh39f26f62022-02-24 21:34:46 -0800206
207 static constexpr double kMaxCatapultEncoderPulsesPerSecond() {
208 return control_loops::superstructure::catapult::kFreeSpeed / (2.0 * M_PI) *
209 control_loops::superstructure::catapult::kOutputRatio /
210 kCatapultEncoderRatio() * kCatapultEncoderCountsPerRevolution();
211 }
212 static constexpr ::frc971::constants::Range kCatapultRange() {
213 return ::frc971::constants::Range{
Milind Upadhyay47e0d032022-03-05 23:06:25 -0800214 .lower_hard = -1.0,
Austin Schuh39f26f62022-02-24 21:34:46 -0800215 .upper_hard = 2.0,
milind-u37dc40b2022-03-08 19:51:27 -0800216 .lower = -0.91,
Austin Schuh39f26f62022-02-24 21:34:46 -0800217 .upper = 1.57,
218 };
219 }
220
221 PotAndAbsEncoderConstants catapult;
milind-ucafdd5d2022-03-01 19:58:57 -0800222
223 // TODO(milind): set this
224 static constexpr double kImuHeight() { return 0.0; }
milind-u086d7262022-01-19 20:44:18 -0800225};
226
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800227// Creates and returns a Values instance for the constants.
228// Should be called before realtime because this allocates memory.
229// Only the first call to either of these will be used.
230Values MakeValues(uint16_t team);
milind-u086d7262022-01-19 20:44:18 -0800231
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800232// Calls MakeValues with aos::network::GetTeamNumber()
233Values MakeValues();
milind-u086d7262022-01-19 20:44:18 -0800234
235} // namespace constants
236} // namespace y2022
237
238#endif // Y2022_CONSTANTS_H_