blob: dd7a8ac12813acf5916660301975b36c62551c31 [file] [log] [blame]
milind-u086d7262022-01-19 20:44:18 -08001#include "y2022/constants.h"
2
3#include <cinttypes>
4#include <map>
5
6#if __has_feature(address_sanitizer)
7#include "sanitizer/lsan_interface.h"
8#endif
9
10#include "absl/base/call_once.h"
11#include "aos/mutex/mutex.h"
12#include "aos/network/team_number.h"
13#include "glog/logging.h"
Austin Schuh39f26f62022-02-24 21:34:46 -080014#include "y2022/control_loops/superstructure/catapult/integral_catapult_plant.h"
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080015#include "y2022/control_loops/superstructure/climber/integral_climber_plant.h"
Henry Speiser55aa3ba2022-02-21 23:21:12 -080016#include "y2022/control_loops/superstructure/intake/integral_intake_plant.h"
17#include "y2022/control_loops/superstructure/turret/integral_turret_plant.h"
milind-u086d7262022-01-19 20:44:18 -080018
19namespace y2022 {
20namespace constants {
21
22const int Values::kZeroingSampleSize;
23
24namespace {
25
26const uint16_t kCompTeamNumber = 971;
27const uint16_t kPracticeTeamNumber = 9971;
28const uint16_t kCodingRobotTeamNumber = 7971;
29
Henry Speiser55aa3ba2022-02-21 23:21:12 -080030} // namespace
31
32Values MakeValues(uint16_t team) {
33 LOG(INFO) << "creating a Constants for team: " << team;
34
35 Values r;
milind-u086d7262022-01-19 20:44:18 -080036
Yash Chainani997a7492022-01-29 15:48:56 -080037 // TODO(Yash): Set constants
38 // Intake constants.
Henry Speiser55aa3ba2022-02-21 23:21:12 -080039 auto *const intake_front = &r.intake_front;
40 auto *const intake_back = &r.intake_back;
Yash Chainani997a7492022-01-29 15:48:56 -080041
Henry Speiser55aa3ba2022-02-21 23:21:12 -080042 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
43 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
44 intake_params;
45
46 intake_params.zeroing_voltage = 3.0;
47 intake_params.operating_voltage = 12.0;
48 intake_params.zeroing_profile_params = {0.5, 3.0};
49 intake_params.default_profile_params = {6.0, 30.0};
50 intake_params.range = Values::kIntakeRange();
51 intake_params.make_integral_loop =
Yash Chainani997a7492022-01-29 15:48:56 -080052 control_loops::superstructure::intake::MakeIntegralIntakeLoop;
Henry Speiser55aa3ba2022-02-21 23:21:12 -080053 intake_params.zeroing_constants.average_filter_size =
54 Values::kZeroingSampleSize;
55 intake_params.zeroing_constants.one_revolution_distance =
Yash Chainani997a7492022-01-29 15:48:56 -080056 M_PI * 2.0 * constants::Values::kIntakeEncoderRatio();
Henry Speiser55aa3ba2022-02-21 23:21:12 -080057 intake_params.zeroing_constants.zeroing_threshold = 0.0005;
58 intake_params.zeroing_constants.moving_buffer_size = 20;
59 intake_params.zeroing_constants.allowable_encoder_error = 0.9;
60 intake_params.zeroing_constants.measured_absolute_position = 0.0;
Yash Chainani997a7492022-01-29 15:48:56 -080061
Henry Speiser55aa3ba2022-02-21 23:21:12 -080062 intake_front->subsystem_params = intake_params;
63 intake_back->subsystem_params = intake_params;
Yash Chainani997a7492022-01-29 15:48:56 -080064
Henry Speiser55aa3ba2022-02-21 23:21:12 -080065 // TODO(Yash): Set constants
66 // Turret constants.
67 auto *const turret = &r.turret;
68 auto *const turret_params = &turret->subsystem_params;
Yash Chainani997a7492022-01-29 15:48:56 -080069
Henry Speiser55aa3ba2022-02-21 23:21:12 -080070 turret_params->zeroing_voltage = 4.0;
Austin Schuh798be922022-03-12 12:00:41 -080071 turret_params->operating_voltage = 12.0;
Henry Speiser55aa3ba2022-02-21 23:21:12 -080072 turret_params->zeroing_profile_params = {0.5, 2.0};
Austin Schuh42d7e5f2022-03-16 23:35:09 -070073 turret_params->default_profile_params = {15.0, 20.0};
Henry Speiser55aa3ba2022-02-21 23:21:12 -080074 turret_params->range = Values::kTurretRange();
75 turret_params->make_integral_loop =
76 control_loops::superstructure::turret::MakeIntegralTurretLoop;
77 turret_params->zeroing_constants.average_filter_size =
78 Values::kZeroingSampleSize;
79 turret_params->zeroing_constants.one_revolution_distance =
80 M_PI * 2.0 * constants::Values::kTurretEncoderRatio();
81 turret_params->zeroing_constants.zeroing_threshold = 0.0005;
82 turret_params->zeroing_constants.moving_buffer_size = 20;
83 turret_params->zeroing_constants.allowable_encoder_error = 0.9;
84 turret_params->zeroing_constants.measured_absolute_position = 0.0;
Yash Chainani997a7492022-01-29 15:48:56 -080085
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080086 // Climber constants
Henry Speiser55aa3ba2022-02-21 23:21:12 -080087 auto *const climber = &r.climber;
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080088 climber->subsystem_params.zeroing_voltage = 3.0;
89 climber->subsystem_params.operating_voltage = 12.0;
90 climber->subsystem_params.zeroing_profile_params = {0.5, 0.1};
Austin Schuh8507c9f2022-03-13 18:08:28 -070091 climber->subsystem_params.default_profile_params = {5.0, 1.0};
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080092 climber->subsystem_params.range = Values::kClimberRange();
93 climber->subsystem_params.make_integral_loop =
94 control_loops::superstructure::climber::MakeIntegralClimberLoop;
95
Griffin Buibcbef482022-02-23 15:32:10 -080096 // Flipper arm constants
97 Values::PotConstants flipper_arms;
98 flipper_arms.subsystem_params.zeroing_voltage = 3.0;
99 flipper_arms.subsystem_params.operating_voltage = 12.0;
100 flipper_arms.subsystem_params.zeroing_profile_params = {0.5, 0.1};
101 flipper_arms.subsystem_params.default_profile_params = {6.0, 1.0};
102 flipper_arms.subsystem_params.range = Values::kFlipperArmRange();
103
Austin Schuhe18df6d2022-03-05 14:02:03 -0800104 auto *const flipper_arm_right = &r.flipper_arm_right;
105 auto *const flipper_arm_left = &r.flipper_arm_left;
Griffin Buibcbef482022-02-23 15:32:10 -0800106
107 *flipper_arm_right = flipper_arms;
108 *flipper_arm_left = flipper_arms;
109
110 // No integral loops for flipper arms
111
Austin Schuh39f26f62022-02-24 21:34:46 -0800112 // Catapult
113 Values::PotAndAbsEncoderConstants *const catapult = &r.catapult;
114 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
115 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
116 *const catapult_params = &catapult->subsystem_params;
117
118 catapult_params->zeroing_voltage = 4.0;
119 catapult_params->operating_voltage = 12.0;
120 catapult_params->zeroing_profile_params = {0.5, 2.0};
121 catapult_params->default_profile_params = {15.0, 40.0};
122 catapult_params->range = Values::kCatapultRange();
123 catapult_params->make_integral_loop =
124 &control_loops::superstructure::catapult::MakeIntegralCatapultLoop;
125 catapult_params->zeroing_constants.average_filter_size =
126 Values::kZeroingSampleSize;
127 catapult_params->zeroing_constants.one_revolution_distance =
128 M_PI * 2.0 * constants::Values::kCatapultEncoderRatio();
129 catapult_params->zeroing_constants.zeroing_threshold = 0.0005;
130 catapult_params->zeroing_constants.moving_buffer_size = 20;
131 catapult_params->zeroing_constants.allowable_encoder_error = 0.9;
132
Ravago Jones3283ce02022-03-09 19:31:29 -0800133 // Interpolation table for comp and practice robots
134 r.shot_interpolation_table = InterpolationTable<Values::ShotParams>({
Austin Schuh1ed66ab2022-04-02 22:39:17 -0700135 {1.0, {0.0, 19.0}},
136 {1.6, {0.0, 19.0}},
137 {1.9, {0.1, 19.0}},
138 {2.12, {0.15, 18.8}},
139 {2.9, {0.25, 19.2}},
Henry Speisere23d4de2022-04-05 16:47:47 -0700140 {3.2, {0.28, 20.3}},
Austin Schuh1ed66ab2022-04-02 22:39:17 -0700141
Henry Speisere23d4de2022-04-05 16:47:47 -0700142 {3.60, {0.33, 20.3}},
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700143 {4.9, {0.4, 21.9}},
144 {5.4, {0.4, 23.9}},
145 {6.0, {0.40, 25.0}},
146 {7.0, {0.37, 27.1}},
Austin Schuh1ed66ab2022-04-02 22:39:17 -0700147
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700148 {7.8, {0.35, 28.0}},
149 {10.0, {0.35, 28.0}},
Ravago Jones3283ce02022-03-09 19:31:29 -0800150 });
151
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700152 if (false) {
153 // 1.5 meters -> 2.7
154 // 2.3 meters -> 4.7
155 // 4.5 meters -> 7.0
156 // 7.0 meters -> 9.0
157
158 constexpr double kShotVelocity = 9.0;
159 r.shot_velocity_interpolation_table =
160 InterpolationTable<Values::ShotVelocityParams>({
161 {1.0, {kShotVelocity}},
162 {10.0, {kShotVelocity}},
163 });
164 } else {
165 r.shot_velocity_interpolation_table =
166 InterpolationTable<Values::ShotVelocityParams>({
167 {1.0, {2.7}},
168 {1.5, {2.7}},
169 {2.3, {4.7}},
170 {4.5, {7.0}},
171 {7.0, {9.0}},
172 {10.0, {9.0}},
173 });
174 }
175
milind-u086d7262022-01-19 20:44:18 -0800176 switch (team) {
177 // A set of constants for tests.
178 case 1:
Ravago Jones3283ce02022-03-09 19:31:29 -0800179 r.shot_interpolation_table = InterpolationTable<Values::ShotParams>({
180 {2, {0.08, 8.0}},
181 {5, {0.6, 10.0}},
182 });
183
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700184 r.shot_velocity_interpolation_table =
185 InterpolationTable<Values::ShotVelocityParams>({
186 {2, {2.0}},
187 {5, {4.0}},
188 });
189
Siddhant Kanwar0e37f592022-02-21 19:26:50 -0800190 climber->potentiometer_offset = 0.0;
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800191 intake_front->potentiometer_offset = 0.0;
192 intake_front->subsystem_params.zeroing_constants
193 .measured_absolute_position = 0.0;
194 intake_back->potentiometer_offset = 0.0;
195 intake_back->subsystem_params.zeroing_constants
196 .measured_absolute_position = 0.0;
197 turret->potentiometer_offset = 0.0;
198 turret->subsystem_params.zeroing_constants.measured_absolute_position =
199 0.0;
Griffin Buibcbef482022-02-23 15:32:10 -0800200 flipper_arm_left->potentiometer_offset = 0.0;
201 flipper_arm_right->potentiometer_offset = 0.0;
Austin Schuh39f26f62022-02-24 21:34:46 -0800202
203 catapult_params->zeroing_constants.measured_absolute_position = 0.0;
204 catapult->potentiometer_offset = 0.0;
milind-u086d7262022-01-19 20:44:18 -0800205 break;
206
207 case kCompTeamNumber:
milind-u6e7d8d42022-04-06 18:30:43 -0700208 climber->potentiometer_offset = -0.0463847608752 - 0.0376876182111 +
209 0.0629263851579 - 0.00682128836400001 +
210 0.0172237531191;
Austin Schuh39f26f62022-02-24 21:34:46 -0800211
Austin Schuh41ebf1e2022-03-27 14:12:49 -0700212 intake_front->potentiometer_offset =
Austin Schuhc563dd72022-04-02 21:11:55 -0700213 2.79628370453323 - 0.0250288114832881 + 0.577152542437606;
Austin Schuh275f9812022-03-05 14:02:37 -0800214 intake_front->subsystem_params.zeroing_constants
Austin Schuhc563dd72022-04-02 21:11:55 -0700215 .measured_absolute_position = 0.26963366701647;
Austin Schuh275f9812022-03-05 14:02:37 -0800216
Austin Schuhc563dd72022-04-02 21:11:55 -0700217 intake_back->potentiometer_offset =
218 3.1409576474047 + 0.278653334013286 + 0.00879137908308503;
Austin Schuh275f9812022-03-05 14:02:37 -0800219 intake_back->subsystem_params.zeroing_constants
Austin Schuhc563dd72022-04-02 21:11:55 -0700220 .measured_absolute_position = 0.242434593996789;
Austin Schuh275f9812022-03-05 14:02:37 -0800221
Austin Schuhff0b05c2022-03-12 17:47:51 -0800222 turret->potentiometer_offset = -9.99970387166721 + 0.06415943 +
Austin Schuh41ebf1e2022-03-27 14:12:49 -0700223 0.073290115367682 - 0.0634440443622909 +
milind-u6e7d8d42022-04-06 18:30:43 -0700224 0.213601224728352 + 0.0657973101027296 -
225 0.114726411377978;
Austin Schuh275f9812022-03-05 14:02:37 -0800226 turret->subsystem_params.zeroing_constants.measured_absolute_position =
milind-u6e7d8d42022-04-06 18:30:43 -0700227 0.39190961531060;
Austin Schuh275f9812022-03-05 14:02:37 -0800228
229 flipper_arm_left->potentiometer_offset = -6.4;
Austin Schuh6b1e4d92022-03-12 12:02:46 -0800230 flipper_arm_right->potentiometer_offset = 5.56;
Austin Schuh275f9812022-03-05 14:02:37 -0800231
232 catapult_params->zeroing_constants.measured_absolute_position =
233 1.71723370408082;
234 catapult->potentiometer_offset = -2.03383240293769;
milind-u086d7262022-01-19 20:44:18 -0800235 break;
236
237 case kPracticeTeamNumber:
Siddhant Kanwar0e37f592022-02-21 19:26:50 -0800238 climber->potentiometer_offset = 0.0;
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800239 intake_front->potentiometer_offset = 0.0;
240 intake_front->subsystem_params.zeroing_constants
241 .measured_absolute_position = 0.0;
242 intake_back->potentiometer_offset = 0.0;
243 intake_back->subsystem_params.zeroing_constants
244 .measured_absolute_position = 0.0;
245 turret->potentiometer_offset = 0.0;
246 turret->subsystem_params.zeroing_constants.measured_absolute_position =
247 0.0;
Griffin Buibcbef482022-02-23 15:32:10 -0800248 flipper_arm_left->potentiometer_offset = 0.0;
249 flipper_arm_right->potentiometer_offset = 0.0;
Austin Schuh39f26f62022-02-24 21:34:46 -0800250
251 catapult_params->zeroing_constants.measured_absolute_position = 0.0;
252 catapult->potentiometer_offset = 0.0;
milind-u086d7262022-01-19 20:44:18 -0800253 break;
254
255 case kCodingRobotTeamNumber:
Ravago Jones3283ce02022-03-09 19:31:29 -0800256 r.shot_interpolation_table = InterpolationTable<Values::ShotParams>({
257 {2, {0.08, 8.0}},
258 {5, {0.6, 10.0}},
259 });
260
James Kuszmaulb9ba9a52022-03-31 22:16:01 -0700261 r.shot_velocity_interpolation_table =
262 InterpolationTable<Values::ShotVelocityParams>({
263 {2, {2.0}},
264 {5, {4.0}},
265 });
266
Siddhant Kanwar0e37f592022-02-21 19:26:50 -0800267 climber->potentiometer_offset = 0.0;
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800268 intake_front->potentiometer_offset = 0.0;
269 intake_front->subsystem_params.zeroing_constants
270 .measured_absolute_position = 0.0;
271 intake_back->potentiometer_offset = 0.0;
272 intake_back->subsystem_params.zeroing_constants
273 .measured_absolute_position = 0.0;
274 turret->potentiometer_offset = 0.0;
275 turret->subsystem_params.zeroing_constants.measured_absolute_position =
276 0.0;
Griffin Buibcbef482022-02-23 15:32:10 -0800277 flipper_arm_left->potentiometer_offset = 0.0;
278 flipper_arm_right->potentiometer_offset = 0.0;
Austin Schuh39f26f62022-02-24 21:34:46 -0800279
280 catapult_params->zeroing_constants.measured_absolute_position = 0.0;
281 catapult->potentiometer_offset = 0.0;
milind-u086d7262022-01-19 20:44:18 -0800282 break;
283
284 default:
285 LOG(FATAL) << "unknown team: " << team;
286 }
287
288 return r;
289}
290
Henry Speiser55aa3ba2022-02-21 23:21:12 -0800291Values MakeValues() { return MakeValues(aos::network::GetTeamNumber()); }
milind-u086d7262022-01-19 20:44:18 -0800292
293} // namespace constants
294} // namespace y2022