blob: 2c299508ab7471baf2fa47129f2bdbdefecf4d1a [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; }
51
52 struct PotConstants {
53 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
54 ::frc971::zeroing::RelativeEncoderZeroingEstimator>
55 subsystem_params;
56 double potentiometer_offset;
57 };
58
59 PotConstants climber;
Milo Lin6b5e4582022-01-29 14:51:37 -080060
61 // Intake
62 // two encoders with same gear ratio for intake
Henry Speiser55aa3ba2022-02-21 23:21:12 -080063 static constexpr double kIntakeEncoderCountsPerRevolution() { return 4096.0; }
Milo Lin6b5e4582022-01-29 14:51:37 -080064
65 static constexpr double kIntakeEncoderRatio() {
Henry Speiser55aa3ba2022-02-21 23:21:12 -080066 return (16.0 / 64.0) * (20.0 / 50.0);
Milo Lin6b5e4582022-01-29 14:51:37 -080067 }
68
Henry Speiser55aa3ba2022-02-21 23:21:12 -080069 static constexpr double kIntakePotRatio() { return 16.0 / 64.0; }
70
71 static constexpr double kMaxIntakeEncoderPulsesPerSecond() {
72 return control_loops::superstructure::intake::kFreeSpeed / (2.0 * M_PI) *
73 control_loops::superstructure::intake::kOutputRatio /
74 kIntakeEncoderRatio() * kIntakeEncoderCountsPerRevolution();
75 }
76
77 struct PotAndAbsEncoderConstants {
78 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
79 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
80 subsystem_params;
81 double potentiometer_offset;
82 };
83
84 PotAndAbsEncoderConstants intake_front;
85 PotAndAbsEncoderConstants intake_back;
86
87 // TODO (Yash): Constants need to be tuned
88 static constexpr ::frc971::constants::Range kIntakeRange() {
89 return ::frc971::constants::Range{
90 .lower_hard = -0.5, // Back Hard
91 .upper_hard = 2.85 + 0.05, // Front Hard
92 .lower = -0.300, // Back Soft
93 .upper = 2.725 // Front Soft
94 };
95 }
96
97 // Intake rollers
98 static constexpr double kIntakeRollerSupplyCurrentLimit() { return 40.0; }
99 static constexpr double kIntakeRollerStatorCurrentLimit() { return 60.0; }
100
Ravago Jones5da06352022-03-04 20:26:24 -0800101 // Transfer rollers
102 // Positive voltage means front transfer rollers pull in and back spits out,
103 // and vice versa
104 static constexpr double kTransferRollerFrontVoltage() { return 12.0; }
105 static constexpr double kTransferRollerBackVoltage() {
106 return -kTransferRollerFrontVoltage();
107 }
108
109 // Voltage to wiggle the transfer rollers and keep a ball in.
110 static constexpr double kTransferRollerFrontWiggleVoltage() { return 5.0; }
111 static constexpr double kTransferRollerBackWiggleVoltage() {
112 return -kTransferRollerFrontWiggleVoltage();
113 }
114
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800115 // Turret
116 PotAndAbsEncoderConstants turret;
117
118 // TODO (Yash): Constants need to be tuned
119 static constexpr ::frc971::constants::Range kTurretRange() {
120 return ::frc971::constants::Range{
Milind Upadhyay225156b2022-02-25 22:42:12 -0800121 .lower_hard = -0.1, // Back Hard
122 .upper_hard = 4.71, // Front Hard
123 .lower = 0.0, // Back Soft
124 .upper = 3.3 // Front Soft
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800125 };
126 }
127
Ravago Jones5da06352022-03-04 20:26:24 -0800128 static constexpr double kTurretBackIntakePos() { return 0.0; }
129 static constexpr double kTurretFrontIntakePos() { return M_PI; }
130
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800131 static constexpr double kTurretPotRatio() { return 27.0 / 110.0; }
132 static constexpr double kTurretEncoderRatio() { return kTurretPotRatio(); }
133 static constexpr double kTurretEncoderCountsPerRevolution() { return 4096.0; }
134
135 static constexpr double kMaxTurretEncoderPulsesPerSecond() {
136 return control_loops::superstructure::turret::kFreeSpeed / (2.0 * M_PI) *
137 control_loops::superstructure::turret::kOutputRatio /
138 kTurretEncoderRatio() * kTurretEncoderCountsPerRevolution();
139 }
Griffin Buibcbef482022-02-23 15:32:10 -0800140
141 // Flipper arms
142 static constexpr double kFlipperArmSupplyCurrentLimit() { return 30.0; }
143 static constexpr double kFlipperArmStatorCurrentLimit() { return 40.0; }
144
Ravago Jones5da06352022-03-04 20:26:24 -0800145 // Voltage to open the flippers for firing
146 static constexpr double kFlipperOpenVoltage() { return 3.0; }
147 // Voltage to keep the flippers open for firing once they already are
148 static constexpr double kFlipperHoldVoltage() { return 2.0; }
149 // Voltage to feed a ball from the transfer rollers to the catpult with the
150 // flippers
151 static constexpr double kFlipperFeedVoltage() { return -8.0; }
152
153 // Ball is fed into catapult for atleast this time no matter what
154 static constexpr std::chrono::milliseconds kExtraLoadingTime() {
155 return std::chrono::milliseconds(100);
156 }
157 // If we have been trying to transfer the ball for this amount of time, it
158 // probably got lost so abort
159 static constexpr std::chrono::seconds kBallLostTime() {
160 return std::chrono::seconds(2);
161 }
162 // If the flippers took more than this amount of time to open for firing,
163 // reseat the ball
164 static constexpr std::chrono::milliseconds kFlipperOpeningTimeout() {
165 return std::chrono::milliseconds(250);
166 }
167 // Don't use flipper velocity readings more than this amount of time in the
168 // past
169 static constexpr std::chrono::milliseconds kFlipperVelocityValidTime() {
170 return std::chrono::milliseconds(100);
171 }
172
Griffin Buibcbef482022-02-23 15:32:10 -0800173 // TODO: (Griffin) this needs to be set
174 static constexpr ::frc971::constants::Range kFlipperArmRange() {
175 return ::frc971::constants::Range{
176 .lower_hard = -0.01, .upper_hard = 0.6, .lower = 0.0, .upper = 0.5};
177 }
Ravago Jones5da06352022-03-04 20:26:24 -0800178 // Position of the flippers when they are open
179 static constexpr double kFlipperOpenPosition() { return 0.4; }
180 // If the flippers were open but now moved back, reseat the ball if they go
181 // below this position
182 static constexpr double kReseatFlipperPosition() { return 0.3; }
Griffin Buibcbef482022-02-23 15:32:10 -0800183
184 static constexpr double kFlipperArmsPotRatio() { return 16.0 / 36.0; }
185
186 PotConstants flipper_arm_left;
187 PotConstants flipper_arm_right;
Austin Schuh39f26f62022-02-24 21:34:46 -0800188
189 // Catapult.
190 static constexpr double kCatapultPotRatio() { return (12.0 / 33.0); }
191 static constexpr double kCatapultEncoderRatio() {
192 return kCatapultPotRatio();
193 }
194 static constexpr double kCatapultEncoderCountsPerRevolution() {
195 return 4096.0;
196 }
197
198 static constexpr double kMaxCatapultEncoderPulsesPerSecond() {
199 return control_loops::superstructure::catapult::kFreeSpeed / (2.0 * M_PI) *
200 control_loops::superstructure::catapult::kOutputRatio /
201 kCatapultEncoderRatio() * kCatapultEncoderCountsPerRevolution();
202 }
203 static constexpr ::frc971::constants::Range kCatapultRange() {
204 return ::frc971::constants::Range{
205 .lower_hard = -1.2,
206 .upper_hard = 2.0,
207 .lower = -1.00,
208 .upper = 1.57,
209 };
210 }
211
212 PotAndAbsEncoderConstants catapult;
milind-u086d7262022-01-19 20:44:18 -0800213};
214
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800215// Creates and returns a Values instance for the constants.
216// Should be called before realtime because this allocates memory.
217// Only the first call to either of these will be used.
218Values MakeValues(uint16_t team);
milind-u086d7262022-01-19 20:44:18 -0800219
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800220// Calls MakeValues with aos::network::GetTeamNumber()
221Values MakeValues();
milind-u086d7262022-01-19 20:44:18 -0800222
223} // namespace constants
224} // namespace y2022
225
226#endif // Y2022_CONSTANTS_H_