blob: 10582edf95d860d8032132b6e3a67b962f33fb4a [file] [log] [blame]
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08001#include "y2019/constants.h"
2
Tyler Chatowbf0609c2021-07-31 16:13:27 -07003#include <cinttypes>
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08004#include <map>
5
6#if __has_feature(address_sanitizer)
7#include "sanitizer/lsan_interface.h"
8#endif
9
John Parkb859cf02019-11-20 19:52:05 -080010#include "absl/base/call_once.h"
Philipp Schrader790cb542023-07-05 21:06:52 -070011#include "glog/logging.h"
12
Brian Silverman1463c092020-10-30 17:28:24 -070013#include "aos/network/team_number.h"
14#include "aos/stl_mutex/stl_mutex.h"
Theo Bafrali00e42272019-02-12 01:07:46 -080015#include "y2019/control_loops/superstructure/elevator/integral_elevator_plant.h"
16#include "y2019/control_loops/superstructure/intake/integral_intake_plant.h"
17#include "y2019/control_loops/superstructure/stilts/integral_stilts_plant.h"
18#include "y2019/control_loops/superstructure/wrist/integral_wrist_plant.h"
James Kuszmaule2c71ea2019-03-04 08:14:21 -080019#include "y2019/vision/constants.h"
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080020
21namespace y2019 {
22namespace constants {
23
Theo Bafrali00e42272019-02-12 01:07:46 -080024using ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator;
25
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080026const int Values::kZeroingSampleSize;
James Kuszmaul09f564a2019-02-18 17:37:09 -080027constexpr size_t Values::kNumCameras;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080028
29namespace {
30
31const uint16_t kCompTeamNumber = 971;
32const uint16_t kPracticeTeamNumber = 9971;
Alex Perry5fb5ff22019-02-09 21:53:17 -080033const uint16_t kCodingRobotTeamNumber = 7971;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080034
Tyler Chatowa109af62019-10-23 21:19:52 -070035constexpr double FeetToMeters(double ft) { return 0.3048 * ft; }
36constexpr double InchToMeters(double in) { return 0.0254 * in; }
37constexpr double DegToRad(double deg) { return deg * M_PI / 180.0; }
James Kuszmaul22c5ab32019-02-09 14:45:58 -080038
James Kuszmaule2c71ea2019-03-04 08:14:21 -080039// Populates camera Pose information from the calibrated vision constants.
40void FillCameraPoses(
41 uint32_t teensy_processor_id,
42 ::std::array<Values::CameraCalibration, Values::kNumCameras> *cameras) {
43 ::std::array<int, 5> camera_ids =
44 vision::CameraSerialNumbers(teensy_processor_id);
45 for (size_t ii = 0; ii < camera_ids.size(); ++ii) {
46 const vision::CameraCalibration *calibration =
47 vision::GetCamera(camera_ids[ii]);
48 if (calibration != nullptr) {
49 vision::CameraGeometry geometry = calibration->geometry;
50 *cameras->at(ii).pose.mutable_pos() << geometry.location[0],
51 geometry.location[1], geometry.location[2];
52 cameras->at(ii).pose.set_theta(geometry.heading);
53 }
54 }
55}
56
Tyler Chatow37ecdcd2019-01-26 20:18:42 -080057const Values *DoGetValuesForTeam(uint16_t team) {
58 Values *const r = new Values();
Alex Perry5fb5ff22019-02-09 21:53:17 -080059 Values::PotAndAbsConstants *const elevator = &r->elevator;
Theo Bafrali00e42272019-02-12 01:07:46 -080060 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
61 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
62 *const elevator_params = &(elevator->subsystem_params);
Alex Perry5fb5ff22019-02-09 21:53:17 -080063 Values::PotAndAbsConstants *const stilts = &r->stilts;
Theo Bafrali00e42272019-02-12 01:07:46 -080064 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
65 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
66 *const stilts_params = &(stilts->subsystem_params);
Alex Perry5fb5ff22019-02-09 21:53:17 -080067 Values::PotAndAbsConstants *const wrist = &r->wrist;
Theo Bafrali00e42272019-02-12 01:07:46 -080068 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
69 ::frc971::zeroing::PotAndAbsoluteEncoderZeroingEstimator>
70 *const wrist_params = &(wrist->subsystem_params);
71 ::frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemParams<
72 ::frc971::zeroing::AbsoluteEncoderZeroingEstimator> *const intake =
73 &r->intake;
Alex Perry5fb5ff22019-02-09 21:53:17 -080074
Theo Bafrali00e42272019-02-12 01:07:46 -080075 // Elevator constants.
Austin Schuh7f87b472019-02-15 23:20:57 -080076 elevator_params->zeroing_voltage = 3.0;
Theo Bafrali00e42272019-02-12 01:07:46 -080077 elevator_params->operating_voltage = 12.0;
78 elevator_params->zeroing_profile_params = {0.1, 1.0};
Sabina Davis810ed4c2019-03-08 21:13:20 -080079 elevator_params->default_profile_params = {4.0, 13.0};
Theo Bafrali00e42272019-02-12 01:07:46 -080080 elevator_params->range = Values::kElevatorRange();
81 elevator_params->make_integral_loop =
82 &control_loops::superstructure::elevator::MakeIntegralElevatorLoop;
83 elevator_params->zeroing_constants.average_filter_size =
84 Values::kZeroingSampleSize;
85 elevator_params->zeroing_constants.one_revolution_distance =
Alex Perry5fb5ff22019-02-09 21:53:17 -080086 M_PI * 2.0 * constants::Values::kElevatorEncoderRatio();
Theo Bafrali00e42272019-02-12 01:07:46 -080087 elevator_params->zeroing_constants.zeroing_threshold = 0.005;
88 elevator_params->zeroing_constants.moving_buffer_size = 20;
89 elevator_params->zeroing_constants.allowable_encoder_error = 0.9;
Alex Perry5fb5ff22019-02-09 21:53:17 -080090
Theo Bafrali00e42272019-02-12 01:07:46 -080091 // Wrist constants.
92 wrist_params->zeroing_voltage = 4.0;
93 wrist_params->operating_voltage = 12.0;
94 wrist_params->zeroing_profile_params = {0.5, 2.0};
Austin Schuh7f87b472019-02-15 23:20:57 -080095 wrist_params->default_profile_params = {10.0, 40.0};
Theo Bafrali00e42272019-02-12 01:07:46 -080096 wrist_params->range = Values::kWristRange();
97 wrist_params->make_integral_loop =
98 &control_loops::superstructure::wrist::MakeIntegralWristLoop;
99 wrist_params->zeroing_constants.average_filter_size =
100 Values::kZeroingSampleSize;
101 wrist_params->zeroing_constants.one_revolution_distance =
Alex Perry5fb5ff22019-02-09 21:53:17 -0800102 M_PI * 2.0 * constants::Values::kWristEncoderRatio();
Theo Bafrali00e42272019-02-12 01:07:46 -0800103 wrist_params->zeroing_constants.zeroing_threshold = 0.0005;
104 wrist_params->zeroing_constants.moving_buffer_size = 20;
105 wrist_params->zeroing_constants.allowable_encoder_error = 0.9;
106
107 // Intake constants.
Austin Schuh7f87b472019-02-15 23:20:57 -0800108 intake->zeroing_voltage = 3.0;
Theo Bafrali00e42272019-02-12 01:07:46 -0800109 intake->operating_voltage = 12.0;
110 intake->zeroing_profile_params = {0.5, 3.0};
Austin Schuh7f87b472019-02-15 23:20:57 -0800111 intake->default_profile_params = {6.0, 30.0};
Theo Bafrali00e42272019-02-12 01:07:46 -0800112 intake->range = Values::kIntakeRange();
113 intake->make_integral_loop =
114 control_loops::superstructure::intake::MakeIntegralIntakeLoop;
115 intake->zeroing_constants.average_filter_size = Values::kZeroingSampleSize;
116 intake->zeroing_constants.one_revolution_distance =
117 M_PI * 2.0 * constants::Values::kIntakeEncoderRatio();
118 intake->zeroing_constants.zeroing_threshold = 0.0005;
119 intake->zeroing_constants.moving_buffer_size = 20;
120 intake->zeroing_constants.allowable_encoder_error = 0.9;
Austin Schuhc9c157a2019-02-19 13:36:22 -0800121 intake->zeroing_constants.middle_position = Values::kIntakeRange().middle();
Theo Bafrali00e42272019-02-12 01:07:46 -0800122
123 // Stilts constants.
Austin Schuh7f87b472019-02-15 23:20:57 -0800124 stilts_params->zeroing_voltage = 3.0;
Theo Bafrali00e42272019-02-12 01:07:46 -0800125 stilts_params->operating_voltage = 12.0;
Austin Schuh7f87b472019-02-15 23:20:57 -0800126 stilts_params->zeroing_profile_params = {0.1, 0.5};
Austin Schuh08bd22d2019-02-22 20:48:20 -0800127 stilts_params->default_profile_params = {0.15, 0.5};
Theo Bafrali00e42272019-02-12 01:07:46 -0800128 stilts_params->range = Values::kStiltsRange();
129 stilts_params->make_integral_loop =
130 &control_loops::superstructure::stilts::MakeIntegralStiltsLoop;
131 stilts_params->zeroing_constants.average_filter_size =
132 Values::kZeroingSampleSize;
133 stilts_params->zeroing_constants.one_revolution_distance =
134 M_PI * 2.0 * constants::Values::kStiltsEncoderRatio();
135 stilts_params->zeroing_constants.zeroing_threshold = 0.0005;
136 stilts_params->zeroing_constants.moving_buffer_size = 20;
137 stilts_params->zeroing_constants.allowable_encoder_error = 0.9;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800138
James Kuszmaul09f564a2019-02-18 17:37:09 -0800139 r->camera_noise_parameters = {.max_viewable_distance = 10.0,
James Kuszmaul074429e2019-03-23 16:01:49 -0700140 .heading_noise = 0.1,
141 .nominal_distance_noise = 0.15,
James Kuszmaul7f1a4082019-04-14 10:50:44 -0700142 .nominal_skew_noise = 0.75,
James Kuszmaul09f564a2019-02-18 17:37:09 -0800143 .nominal_height_noise = 0.01};
144
James Kuszmaule2c71ea2019-03-04 08:14:21 -0800145 // Deliberately make FOV a bit large so that we are overly conservative in
146 // our EKF.
147 for (auto &camera : r->cameras) {
James Kuszmaul074429e2019-03-23 16:01:49 -0700148 camera.fov = M_PI_2 * 1.5;
James Kuszmaule2c71ea2019-03-04 08:14:21 -0800149 }
150
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800151 switch (team) {
152 // A set of constants for tests.
153 case 1:
Theo Bafrali00e42272019-02-12 01:07:46 -0800154 elevator_params->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800155 elevator->potentiometer_offset = 0.0;
156
Theo Bafrali00e42272019-02-12 01:07:46 -0800157 intake->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800158
Theo Bafrali00e42272019-02-12 01:07:46 -0800159 wrist_params->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800160 wrist->potentiometer_offset = 0.0;
Theo Bafrali00e42272019-02-12 01:07:46 -0800161
162 stilts_params->zeroing_constants.measured_absolute_position = 0.0;
163 stilts->potentiometer_offset = 0.0;
James Kuszmaul09f564a2019-02-18 17:37:09 -0800164
James Kuszmaule2c71ea2019-03-04 08:14:21 -0800165 // For the simulation, just place cameras at the center of the robot with
166 // nominal angles (back/sides + 15 degree offset front cameras).
James Kuszmaul09f564a2019-02-18 17:37:09 -0800167 r->cameras[0].pose.set_theta(M_PI);
168 r->cameras[1].pose.set_theta(0.26);
169 r->cameras[2].pose.set_theta(-0.26);
170 r->cameras[3].pose.set_theta(M_PI_2);
171 r->cameras[4].pose.set_theta(-M_PI_2);
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800172 break;
173
174 case kCompTeamNumber:
Austin Schuh13d58302019-05-08 20:10:20 -0700175 elevator_params->zeroing_constants.measured_absolute_position = 0.145498;
Austin Schuh37c102e2019-03-17 18:13:50 -0700176 elevator->potentiometer_offset =
177 -0.075017 + 0.015837 + 0.009793 - 0.012017 + 0.019915 + 0.010126 +
Austin Schuh13d58302019-05-08 20:10:20 -0700178 0.005541 + 0.006088 - 0.039687 + 0.005843 + 0.009007 + 0.008604 -
179 0.004621 + 0.003305;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800180
Austin Schuh85d758b2019-06-29 17:35:26 -0700181 intake->zeroing_constants.measured_absolute_position = 1.273143;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800182
Austin Schuh85d758b2019-06-29 17:35:26 -0700183 wrist_params->zeroing_constants.measured_absolute_position = 0.155868;
Austin Schuh588e10b2021-06-20 14:52:33 -0700184 wrist->potentiometer_offset =
185 -4.257454 - 0.058039 + 0.270233 - 0.661464 + 0.872911951453577;
Theo Bafrali00e42272019-02-12 01:07:46 -0800186
Austin Schuh37c102e2019-03-17 18:13:50 -0700187 stilts_params->zeroing_constants.measured_absolute_position = 0.066843;
188 stilts->potentiometer_offset = -0.015760 + 0.011604 - 0.061213 + 0.006690;
Austin Schuh48d3a962019-03-17 18:12:32 -0700189 FillCameraPoses(vision::CompBotTeensyId(), &r->cameras);
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800190 break;
191
192 case kPracticeTeamNumber:
Tyler Chatowa109af62019-10-23 21:19:52 -0700193 elevator_params->zeroing_constants.measured_absolute_position = 0.131568;
194 elevator->potentiometer_offset = -0.022320 + 0.020567 - 0.022355 -
195 0.006497 + 0.019690 + 0.009151 -
196 0.007513 + 0.007311;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800197
Tyler Chatowa109af62019-10-23 21:19:52 -0700198 intake->zeroing_constants.measured_absolute_position =
199 1.928755 + 0.205352;
Austin Schuhed7f8632019-02-15 23:12:20 -0800200
Tyler Chatowa109af62019-10-23 21:19:52 -0700201 wrist_params->zeroing_constants.measured_absolute_position = 0.180039;
Sabina Davisfe2e7122019-03-08 20:45:54 -0800202 wrist->potentiometer_offset = -4.200894 - 0.187134;
Austin Schuhed7f8632019-02-15 23:12:20 -0800203
Tyler Chatowa109af62019-10-23 21:19:52 -0700204 stilts_params->zeroing_constants.measured_absolute_position = 0.050556;
205 stilts->potentiometer_offset =
206 -0.093820 + 0.0124 - 0.008334 + 0.004507 - 0.007973 + -0.001221;
James Kuszmaulfedc4612019-03-10 11:24:51 -0700207
208 FillCameraPoses(vision::PracticeBotTeensyId(), &r->cameras);
Alex Perry5fb5ff22019-02-09 21:53:17 -0800209 break;
210
211 case kCodingRobotTeamNumber:
Theo Bafrali00e42272019-02-12 01:07:46 -0800212 elevator_params->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800213 elevator->potentiometer_offset = 0.0;
214
Theo Bafrali00e42272019-02-12 01:07:46 -0800215 intake->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800216
Theo Bafrali00e42272019-02-12 01:07:46 -0800217 wrist_params->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800218 wrist->potentiometer_offset = 0.0;
Theo Bafrali00e42272019-02-12 01:07:46 -0800219
220 stilts_params->zeroing_constants.measured_absolute_position = 0.0;
221 stilts->potentiometer_offset = 0.0;
James Kuszmaul81df16a2019-03-03 17:17:34 -0800222
James Kuszmaule2c71ea2019-03-04 08:14:21 -0800223 FillCameraPoses(vision::CodeBotTeensyId(), &r->cameras);
224
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800225 break;
226
227 default:
Brian Silvermanf4d329c2021-11-04 19:32:10 -0700228 LOG(FATAL) << "unknown team: " << team;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800229 }
230
231 return r;
232}
233
Brian Silverman1463c092020-10-30 17:28:24 -0700234void DoGetValues(const Values **result) {
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800235 uint16_t team = ::aos::network::GetTeamNumber();
Brian Silvermanf4d329c2021-11-04 19:32:10 -0700236 LOG(INFO) << "creating a Constants for team: " << team;
John Parkb859cf02019-11-20 19:52:05 -0800237 *result = DoGetValuesForTeam(team);
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800238}
239
240} // namespace
241
242const Values &GetValues() {
John Park9372a682019-11-27 18:07:48 -0800243 static absl::once_flag once;
Brian Silverman1463c092020-10-30 17:28:24 -0700244 static const Values *result;
John Park9372a682019-11-27 18:07:48 -0800245 absl::call_once(once, DoGetValues, &result);
John Parkb859cf02019-11-20 19:52:05 -0800246 return *result;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800247}
248
249const Values &GetValuesForTeam(uint16_t team_number) {
Brian Silverman1463c092020-10-30 17:28:24 -0700250 static aos::stl_mutex mutex;
251 std::unique_lock<aos::stl_mutex> locker(mutex);
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800252
253 // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
254 // race conditions.
255 static ::std::map<uint16_t, const Values *> values;
256
257 if (values.count(team_number) == 0) {
258 values[team_number] = DoGetValuesForTeam(team_number);
259#if __has_feature(address_sanitizer)
260 __lsan_ignore_object(values[team_number]);
261#endif
262 }
263 return *values[team_number];
264}
265
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800266constexpr size_t Field::kNumTargets;
267constexpr size_t Field::kNumObstacles;
268
269Field::Field() {
270 // TODO(james): These values need to re-verified. I got them by skimming the
271 // manual and they all seem to be pretty much correct.
272 //
273 // Note: Per //frc971/control_loops/pose.h, coordinate system is:
274 // -In meters
275 // -Origin at center of our driver's station wall
276 // -Positive X-axis pointing straight out from driver's station
277 // -Positive Y-axis pointing straight left from the driver's perspective
278 // -Positive Z-axis is straight up.
279 // -The angle of the target is such that the angle is the angle you would
280 // need to be facing to see it straight-on. I.e., if the target angle is
281 // pi / 2.0, then you would be able to see it face on by facing straight
282 // left from the driver's point of view (if you were standing in the right
283 // spot).
284 constexpr double kCenterFieldX = FeetToMeters(27.0) + InchToMeters(1.125);
285
Tyler Chatowa109af62019-10-23 21:19:52 -0700286 constexpr double kFarSideCargoBayX = kCenterFieldX - InchToMeters(20.875);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800287 constexpr double kMidSideCargoBayX = kFarSideCargoBayX - InchToMeters(21.75);
288 constexpr double kNearSideCargoBayX = kMidSideCargoBayX - InchToMeters(21.75);
289 constexpr double kSideCargoBayY = InchToMeters(24 + 3 + 0.875);
290 constexpr double kSideCargoBayTheta = -M_PI_2;
291
292 constexpr double kFaceCargoBayX =
293 kCenterFieldX - InchToMeters(7 * 12 + 11.75 + 9);
294 constexpr double kFaceCargoBayY = InchToMeters(10.875);
295 constexpr double kFaceCargoBayTheta = 0.0;
296
297 constexpr double kRocketX = kCenterFieldX - FeetToMeters(8);
298 constexpr double kRocketY = InchToMeters((26 * 12 + 10.5) / 2.0);
299
300 constexpr double kRocketPortX = kRocketX;
301 constexpr double kRocketPortY = kRocketY - 0.70;
302 constexpr double kRocketPortTheta = M_PI_2;
303
304 // Half of portal + guess at width * cos(61.5 deg)
305 const double kRocketHatchXOffset = InchToMeters(14.634);
306 const double kRocketHatchY = kRocketPortY + InchToMeters(9.326);
307 const double kRocketNearX = kRocketX - kRocketHatchXOffset;
308 const double kRocketFarX = kRocketX + kRocketHatchXOffset;
309 constexpr double kRocketNearTheta = DegToRad(28.5);
310 constexpr double kRocketFarTheta = M_PI - kRocketNearTheta;
311
312 constexpr double kHpSlotY = InchToMeters((26 * 12 + 10.5) / 2.0 - 25.9);
313 constexpr double kHpSlotTheta = M_PI;
314
James Kuszmaule093f512019-03-20 06:14:05 -0700315 constexpr double kNormalZ = 0.80;
316 constexpr double kPortZ = 1.00;
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800317
James Kuszmaule093f512019-03-20 06:14:05 -0700318 constexpr double kDiscRadius = InchToMeters(19.0 / 2.0);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800319
James Kuszmaule093f512019-03-20 06:14:05 -0700320 constexpr Target::GoalType kBothGoal = Target::GoalType::kBoth;
321 constexpr Target::GoalType kBallGoal = Target::GoalType::kBalls;
322 constexpr Target::GoalType kDiscGoal = Target::GoalType::kHatches;
323 constexpr Target::GoalType kNoneGoal = Target::GoalType::kNone;
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700324 using TargetType = Target::TargetType;
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800325
James Kuszmaule093f512019-03-20 06:14:05 -0700326 const Target far_side_cargo_bay(
327 {{kFarSideCargoBayX, kSideCargoBayY, kNormalZ}, kSideCargoBayTheta},
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700328 kDiscRadius, TargetType::kFarSideCargoBay, kBothGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700329 const Target mid_side_cargo_bay(
330 {{kMidSideCargoBayX, kSideCargoBayY, kNormalZ}, kSideCargoBayTheta},
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700331 kDiscRadius, TargetType::kMidSideCargoBay, kBothGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700332 const Target near_side_cargo_bay(
333 {{kNearSideCargoBayX, kSideCargoBayY, kNormalZ}, kSideCargoBayTheta},
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700334 kDiscRadius, TargetType::kNearSideCargoBay, kBothGoal);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800335
James Kuszmaule093f512019-03-20 06:14:05 -0700336 const Target face_cargo_bay(
337 {{kFaceCargoBayX, kFaceCargoBayY, kNormalZ}, kFaceCargoBayTheta},
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700338 kDiscRadius, TargetType::kFaceCargoBay, kBothGoal);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800339
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700340 // The rocket port, since it is only for balls, has no meaningful radius
341 // to work with (and is over-ridden with zero in target_selector).
James Kuszmaule093f512019-03-20 06:14:05 -0700342 const Target rocket_port(
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700343 {{kRocketPortX, kRocketPortY, kPortZ}, kRocketPortTheta}, 0.0,
344 TargetType::kRocketPortal, kBallGoal);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800345
James Kuszmaule093f512019-03-20 06:14:05 -0700346 const Target rocket_near(
347 {{kRocketNearX, kRocketHatchY, kNormalZ}, kRocketNearTheta}, kDiscRadius,
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700348 TargetType::kNearRocket, kDiscGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700349 const Target rocket_far(
350 {{kRocketFarX, kRocketHatchY, kNormalZ}, kRocketFarTheta}, kDiscRadius,
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700351 TargetType::kFarRocket, kDiscGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700352
James Kuszmaul074429e2019-03-23 16:01:49 -0700353 const Target hp_slot({{0.0, kHpSlotY, kNormalZ}, kHpSlotTheta}, 0.00,
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700354 TargetType::kHPSlot, kBothGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700355
356 const ::std::array<Target, 8> quarter_field_targets{
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800357 {far_side_cargo_bay, mid_side_cargo_bay, near_side_cargo_bay,
358 face_cargo_bay, rocket_port, rocket_near, rocket_far, hp_slot}};
359
360 // Mirror across center field mid-line (short field axis):
James Kuszmaule093f512019-03-20 06:14:05 -0700361 ::std::array<Target, 16> half_field_targets;
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800362 ::std::copy(quarter_field_targets.begin(), quarter_field_targets.end(),
363 half_field_targets.begin());
364 for (int ii = 0; ii < 8; ++ii) {
365 const int jj = ii + 8;
366 half_field_targets[jj] = quarter_field_targets[ii];
James Kuszmaule093f512019-03-20 06:14:05 -0700367 half_field_targets[jj].mutable_pose()->mutable_pos()->x() =
368 2.0 * kCenterFieldX - half_field_targets[jj].pose().rel_pos().x();
369 half_field_targets[jj].mutable_pose()->set_theta(aos::math::NormalizeAngle(
370 M_PI - half_field_targets[jj].pose().rel_theta()));
371 // Targets on the opposite side of the field can't be driven to.
372 half_field_targets[jj].set_goal_type(kNoneGoal);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800373 }
374
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800375 // Mirror across x-axis (long field axis):
376 ::std::copy(half_field_targets.begin(), half_field_targets.end(),
James Kuszmaule093f512019-03-20 06:14:05 -0700377 targets_.begin());
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800378 for (int ii = 0; ii < 16; ++ii) {
379 const int jj = ii + 16;
James Kuszmaule093f512019-03-20 06:14:05 -0700380 targets_[jj] = half_field_targets[ii];
381 targets_[jj].mutable_pose()->mutable_pos()->y() *= -1;
382 targets_[jj].mutable_pose()->set_theta(-targets_[jj].pose().rel_theta());
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800383 }
384
385 // Define rocket obstacles as just being a single line that should block any
386 // cameras trying to see through the rocket up and down the field.
387 // This line is parallel to the driver's station wall and extends behind
388 // the portal.
389 Obstacle rocket_obstacle({{kRocketPortX, kRocketY, 0.0}, 0.0},
390 {{kRocketPortX, kRocketPortY + 0.01, 0.0}, 0.0});
391 // First, we mirror rocket obstacles across x-axis:
392 Obstacle rocket_obstacle2({{kRocketPortX, -kRocketY, 0.0}, 0.0},
393 {{kRocketPortX, -kRocketPortY - 0.01, 0.0}, 0.0});
394
395 // Define an obstacle for the Hab that extends striaght out a few feet from
396 // the driver's station wall.
397 // TODO(james): Does this actually block our view?
398 const double kHabL3X = FeetToMeters(4.0);
399 Obstacle hab_obstacle({}, {{kHabL3X, 0.0, 0.0}, 0.0});
400 ::std::array<Obstacle, 3> half_obstacles{
401 {rocket_obstacle, rocket_obstacle2, hab_obstacle}};
402 ::std::copy(half_obstacles.begin(), half_obstacles.end(), obstacles_.begin());
403
404 // Next, we mirror across the mid-line (short axis) to duplicate the
405 // rockets and hab to opposite side of the field.
406 for (int ii = 0; ii < 3; ++ii) {
407 const int jj = ii + 3;
408 obstacles_[jj] = half_obstacles[ii];
409 obstacles_[jj].mutable_pose1()->mutable_pos()->x() =
410 2.0 * kCenterFieldX - obstacles_[jj].mutable_pose1()->rel_pos().x();
411 obstacles_[jj].mutable_pose2()->mutable_pos()->x() =
412 2.0 * kCenterFieldX - obstacles_[jj].mutable_pose2()->rel_pos().x();
413 }
414
415 // Finally, define a rectangular cargo ship.
416 const double kCargoCornerX = kFaceCargoBayX + 0.1;
417 const double kCargoCornerY = kSideCargoBayY - 0.1;
418 ::std::array<Pose, 4> cargo_corners{
419 {{{kCargoCornerX, kCargoCornerY, 0.0}, 0.0},
420 {{kCargoCornerX, -kCargoCornerY, 0.0}, 0.0},
421 {{2.0 * kCenterFieldX - kCargoCornerX, -kCargoCornerY, 0.0}, 0.0},
422 {{2.0 * kCenterFieldX - kCargoCornerX, kCargoCornerY, 0.0}, 0.0}}};
423 for (int ii = 6; ii < 10; ++ii) {
424 obstacles_[ii] = Obstacle(cargo_corners[ii % cargo_corners.size()],
425 cargo_corners[(ii + 1) % cargo_corners.size()]);
426 }
427}
428
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800429} // namespace constants
430} // namespace y2019