blob: d5b0c095bcd3324dff346d857a21bfdfdf78519a [file] [log] [blame]
Tyler Chatow37ecdcd2019-01-26 20:18:42 -08001#include "y2019/constants.h"
2
3#include <inttypes.h>
4
5#include <map>
6
7#if __has_feature(address_sanitizer)
8#include "sanitizer/lsan_interface.h"
9#endif
10
11#include "aos/logging/logging.h"
12#include "aos/mutex/mutex.h"
13#include "aos/network/team_number.h"
John Parkb859cf02019-11-20 19:52:05 -080014#include "absl/base/call_once.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;
184 wrist->potentiometer_offset = -4.257454 - 0.058039 + 0.270233 - 0.661464;
Theo Bafrali00e42272019-02-12 01:07:46 -0800185
Austin Schuh37c102e2019-03-17 18:13:50 -0700186 stilts_params->zeroing_constants.measured_absolute_position = 0.066843;
187 stilts->potentiometer_offset = -0.015760 + 0.011604 - 0.061213 + 0.006690;
Austin Schuh48d3a962019-03-17 18:12:32 -0700188 FillCameraPoses(vision::CompBotTeensyId(), &r->cameras);
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800189 break;
190
191 case kPracticeTeamNumber:
Tyler Chatowa109af62019-10-23 21:19:52 -0700192 elevator_params->zeroing_constants.measured_absolute_position = 0.131568;
193 elevator->potentiometer_offset = -0.022320 + 0.020567 - 0.022355 -
194 0.006497 + 0.019690 + 0.009151 -
195 0.007513 + 0.007311;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800196
Tyler Chatowa109af62019-10-23 21:19:52 -0700197 intake->zeroing_constants.measured_absolute_position =
198 1.928755 + 0.205352;
Austin Schuhed7f8632019-02-15 23:12:20 -0800199
Tyler Chatowa109af62019-10-23 21:19:52 -0700200 wrist_params->zeroing_constants.measured_absolute_position = 0.180039;
Sabina Davisfe2e7122019-03-08 20:45:54 -0800201 wrist->potentiometer_offset = -4.200894 - 0.187134;
Austin Schuhed7f8632019-02-15 23:12:20 -0800202
Tyler Chatowa109af62019-10-23 21:19:52 -0700203 stilts_params->zeroing_constants.measured_absolute_position = 0.050556;
204 stilts->potentiometer_offset =
205 -0.093820 + 0.0124 - 0.008334 + 0.004507 - 0.007973 + -0.001221;
James Kuszmaulfedc4612019-03-10 11:24:51 -0700206
207 FillCameraPoses(vision::PracticeBotTeensyId(), &r->cameras);
Alex Perry5fb5ff22019-02-09 21:53:17 -0800208 break;
209
210 case kCodingRobotTeamNumber:
Theo Bafrali00e42272019-02-12 01:07:46 -0800211 elevator_params->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800212 elevator->potentiometer_offset = 0.0;
213
Theo Bafrali00e42272019-02-12 01:07:46 -0800214 intake->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800215
Theo Bafrali00e42272019-02-12 01:07:46 -0800216 wrist_params->zeroing_constants.measured_absolute_position = 0.0;
Alex Perry5fb5ff22019-02-09 21:53:17 -0800217 wrist->potentiometer_offset = 0.0;
Theo Bafrali00e42272019-02-12 01:07:46 -0800218
219 stilts_params->zeroing_constants.measured_absolute_position = 0.0;
220 stilts->potentiometer_offset = 0.0;
James Kuszmaul81df16a2019-03-03 17:17:34 -0800221
James Kuszmaule2c71ea2019-03-04 08:14:21 -0800222 FillCameraPoses(vision::CodeBotTeensyId(), &r->cameras);
223
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800224 break;
225
226 default:
Austin Schuhf257f3c2019-10-27 21:00:43 -0700227 AOS_LOG(FATAL, "unknown team #%" PRIu16 "\n", team);
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800228 }
229
230 return r;
231}
232
John Parkb859cf02019-11-20 19:52:05 -0800233void DoGetValues(const Values** result) {
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800234 uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700235 AOS_LOG(INFO, "creating a Constants for team %" PRIu16 "\n", team);
John Parkb859cf02019-11-20 19:52:05 -0800236 *result = DoGetValuesForTeam(team);
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800237}
238
239} // namespace
240
241const Values &GetValues() {
John Park9372a682019-11-27 18:07:48 -0800242 static absl::once_flag once;
John Parkb859cf02019-11-20 19:52:05 -0800243 static const Values* result;
John Park9372a682019-11-27 18:07:48 -0800244 absl::call_once(once, DoGetValues, &result);
John Parkb859cf02019-11-20 19:52:05 -0800245 return *result;
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800246}
247
248const Values &GetValuesForTeam(uint16_t team_number) {
249 static ::aos::Mutex mutex;
250 ::aos::MutexLocker locker(&mutex);
251
252 // IMPORTANT: This declaration has to stay after the mutex is locked to avoid
253 // race conditions.
254 static ::std::map<uint16_t, const Values *> values;
255
256 if (values.count(team_number) == 0) {
257 values[team_number] = DoGetValuesForTeam(team_number);
258#if __has_feature(address_sanitizer)
259 __lsan_ignore_object(values[team_number]);
260#endif
261 }
262 return *values[team_number];
263}
264
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800265constexpr size_t Field::kNumTargets;
266constexpr size_t Field::kNumObstacles;
267
268Field::Field() {
269 // TODO(james): These values need to re-verified. I got them by skimming the
270 // manual and they all seem to be pretty much correct.
271 //
272 // Note: Per //frc971/control_loops/pose.h, coordinate system is:
273 // -In meters
274 // -Origin at center of our driver's station wall
275 // -Positive X-axis pointing straight out from driver's station
276 // -Positive Y-axis pointing straight left from the driver's perspective
277 // -Positive Z-axis is straight up.
278 // -The angle of the target is such that the angle is the angle you would
279 // need to be facing to see it straight-on. I.e., if the target angle is
280 // pi / 2.0, then you would be able to see it face on by facing straight
281 // left from the driver's point of view (if you were standing in the right
282 // spot).
283 constexpr double kCenterFieldX = FeetToMeters(27.0) + InchToMeters(1.125);
284
Tyler Chatowa109af62019-10-23 21:19:52 -0700285 constexpr double kFarSideCargoBayX = kCenterFieldX - InchToMeters(20.875);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800286 constexpr double kMidSideCargoBayX = kFarSideCargoBayX - InchToMeters(21.75);
287 constexpr double kNearSideCargoBayX = kMidSideCargoBayX - InchToMeters(21.75);
288 constexpr double kSideCargoBayY = InchToMeters(24 + 3 + 0.875);
289 constexpr double kSideCargoBayTheta = -M_PI_2;
290
291 constexpr double kFaceCargoBayX =
292 kCenterFieldX - InchToMeters(7 * 12 + 11.75 + 9);
293 constexpr double kFaceCargoBayY = InchToMeters(10.875);
294 constexpr double kFaceCargoBayTheta = 0.0;
295
296 constexpr double kRocketX = kCenterFieldX - FeetToMeters(8);
297 constexpr double kRocketY = InchToMeters((26 * 12 + 10.5) / 2.0);
298
299 constexpr double kRocketPortX = kRocketX;
300 constexpr double kRocketPortY = kRocketY - 0.70;
301 constexpr double kRocketPortTheta = M_PI_2;
302
303 // Half of portal + guess at width * cos(61.5 deg)
304 const double kRocketHatchXOffset = InchToMeters(14.634);
305 const double kRocketHatchY = kRocketPortY + InchToMeters(9.326);
306 const double kRocketNearX = kRocketX - kRocketHatchXOffset;
307 const double kRocketFarX = kRocketX + kRocketHatchXOffset;
308 constexpr double kRocketNearTheta = DegToRad(28.5);
309 constexpr double kRocketFarTheta = M_PI - kRocketNearTheta;
310
311 constexpr double kHpSlotY = InchToMeters((26 * 12 + 10.5) / 2.0 - 25.9);
312 constexpr double kHpSlotTheta = M_PI;
313
James Kuszmaule093f512019-03-20 06:14:05 -0700314 constexpr double kNormalZ = 0.80;
315 constexpr double kPortZ = 1.00;
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800316
James Kuszmaule093f512019-03-20 06:14:05 -0700317 constexpr double kDiscRadius = InchToMeters(19.0 / 2.0);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800318
James Kuszmaule093f512019-03-20 06:14:05 -0700319 constexpr Target::GoalType kBothGoal = Target::GoalType::kBoth;
320 constexpr Target::GoalType kBallGoal = Target::GoalType::kBalls;
321 constexpr Target::GoalType kDiscGoal = Target::GoalType::kHatches;
322 constexpr Target::GoalType kNoneGoal = Target::GoalType::kNone;
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700323 using TargetType = Target::TargetType;
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800324
James Kuszmaule093f512019-03-20 06:14:05 -0700325 const Target far_side_cargo_bay(
326 {{kFarSideCargoBayX, kSideCargoBayY, kNormalZ}, kSideCargoBayTheta},
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700327 kDiscRadius, TargetType::kFarSideCargoBay, kBothGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700328 const Target mid_side_cargo_bay(
329 {{kMidSideCargoBayX, kSideCargoBayY, kNormalZ}, kSideCargoBayTheta},
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700330 kDiscRadius, TargetType::kMidSideCargoBay, kBothGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700331 const Target near_side_cargo_bay(
332 {{kNearSideCargoBayX, kSideCargoBayY, kNormalZ}, kSideCargoBayTheta},
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700333 kDiscRadius, TargetType::kNearSideCargoBay, kBothGoal);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800334
James Kuszmaule093f512019-03-20 06:14:05 -0700335 const Target face_cargo_bay(
336 {{kFaceCargoBayX, kFaceCargoBayY, kNormalZ}, kFaceCargoBayTheta},
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700337 kDiscRadius, TargetType::kFaceCargoBay, kBothGoal);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800338
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700339 // The rocket port, since it is only for balls, has no meaningful radius
340 // to work with (and is over-ridden with zero in target_selector).
James Kuszmaule093f512019-03-20 06:14:05 -0700341 const Target rocket_port(
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700342 {{kRocketPortX, kRocketPortY, kPortZ}, kRocketPortTheta}, 0.0,
343 TargetType::kRocketPortal, kBallGoal);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800344
James Kuszmaule093f512019-03-20 06:14:05 -0700345 const Target rocket_near(
346 {{kRocketNearX, kRocketHatchY, kNormalZ}, kRocketNearTheta}, kDiscRadius,
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700347 TargetType::kNearRocket, kDiscGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700348 const Target rocket_far(
349 {{kRocketFarX, kRocketHatchY, kNormalZ}, kRocketFarTheta}, kDiscRadius,
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700350 TargetType::kFarRocket, kDiscGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700351
James Kuszmaul074429e2019-03-23 16:01:49 -0700352 const Target hp_slot({{0.0, kHpSlotY, kNormalZ}, kHpSlotTheta}, 0.00,
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700353 TargetType::kHPSlot, kBothGoal);
James Kuszmaule093f512019-03-20 06:14:05 -0700354
355 const ::std::array<Target, 8> quarter_field_targets{
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800356 {far_side_cargo_bay, mid_side_cargo_bay, near_side_cargo_bay,
357 face_cargo_bay, rocket_port, rocket_near, rocket_far, hp_slot}};
358
359 // Mirror across center field mid-line (short field axis):
James Kuszmaule093f512019-03-20 06:14:05 -0700360 ::std::array<Target, 16> half_field_targets;
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800361 ::std::copy(quarter_field_targets.begin(), quarter_field_targets.end(),
362 half_field_targets.begin());
363 for (int ii = 0; ii < 8; ++ii) {
364 const int jj = ii + 8;
365 half_field_targets[jj] = quarter_field_targets[ii];
James Kuszmaule093f512019-03-20 06:14:05 -0700366 half_field_targets[jj].mutable_pose()->mutable_pos()->x() =
367 2.0 * kCenterFieldX - half_field_targets[jj].pose().rel_pos().x();
368 half_field_targets[jj].mutable_pose()->set_theta(aos::math::NormalizeAngle(
369 M_PI - half_field_targets[jj].pose().rel_theta()));
370 // Targets on the opposite side of the field can't be driven to.
371 half_field_targets[jj].set_goal_type(kNoneGoal);
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800372 }
373
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800374 // Mirror across x-axis (long field axis):
375 ::std::copy(half_field_targets.begin(), half_field_targets.end(),
James Kuszmaule093f512019-03-20 06:14:05 -0700376 targets_.begin());
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800377 for (int ii = 0; ii < 16; ++ii) {
378 const int jj = ii + 16;
James Kuszmaule093f512019-03-20 06:14:05 -0700379 targets_[jj] = half_field_targets[ii];
380 targets_[jj].mutable_pose()->mutable_pos()->y() *= -1;
381 targets_[jj].mutable_pose()->set_theta(-targets_[jj].pose().rel_theta());
James Kuszmaul22c5ab32019-02-09 14:45:58 -0800382 }
383
384 // Define rocket obstacles as just being a single line that should block any
385 // cameras trying to see through the rocket up and down the field.
386 // This line is parallel to the driver's station wall and extends behind
387 // the portal.
388 Obstacle rocket_obstacle({{kRocketPortX, kRocketY, 0.0}, 0.0},
389 {{kRocketPortX, kRocketPortY + 0.01, 0.0}, 0.0});
390 // First, we mirror rocket obstacles across x-axis:
391 Obstacle rocket_obstacle2({{kRocketPortX, -kRocketY, 0.0}, 0.0},
392 {{kRocketPortX, -kRocketPortY - 0.01, 0.0}, 0.0});
393
394 // Define an obstacle for the Hab that extends striaght out a few feet from
395 // the driver's station wall.
396 // TODO(james): Does this actually block our view?
397 const double kHabL3X = FeetToMeters(4.0);
398 Obstacle hab_obstacle({}, {{kHabL3X, 0.0, 0.0}, 0.0});
399 ::std::array<Obstacle, 3> half_obstacles{
400 {rocket_obstacle, rocket_obstacle2, hab_obstacle}};
401 ::std::copy(half_obstacles.begin(), half_obstacles.end(), obstacles_.begin());
402
403 // Next, we mirror across the mid-line (short axis) to duplicate the
404 // rockets and hab to opposite side of the field.
405 for (int ii = 0; ii < 3; ++ii) {
406 const int jj = ii + 3;
407 obstacles_[jj] = half_obstacles[ii];
408 obstacles_[jj].mutable_pose1()->mutable_pos()->x() =
409 2.0 * kCenterFieldX - obstacles_[jj].mutable_pose1()->rel_pos().x();
410 obstacles_[jj].mutable_pose2()->mutable_pos()->x() =
411 2.0 * kCenterFieldX - obstacles_[jj].mutable_pose2()->rel_pos().x();
412 }
413
414 // Finally, define a rectangular cargo ship.
415 const double kCargoCornerX = kFaceCargoBayX + 0.1;
416 const double kCargoCornerY = kSideCargoBayY - 0.1;
417 ::std::array<Pose, 4> cargo_corners{
418 {{{kCargoCornerX, kCargoCornerY, 0.0}, 0.0},
419 {{kCargoCornerX, -kCargoCornerY, 0.0}, 0.0},
420 {{2.0 * kCenterFieldX - kCargoCornerX, -kCargoCornerY, 0.0}, 0.0},
421 {{2.0 * kCenterFieldX - kCargoCornerX, kCargoCornerY, 0.0}, 0.0}}};
422 for (int ii = 6; ii < 10; ++ii) {
423 obstacles_[ii] = Obstacle(cargo_corners[ii % cargo_corners.size()],
424 cargo_corners[(ii + 1) % cargo_corners.size()]);
425 }
426}
427
Tyler Chatow37ecdcd2019-01-26 20:18:42 -0800428} // namespace constants
429} // namespace y2019