@@ -192,199 +192,17 @@ std::optional<RobotIntent> Offense::state_to_task(RobotIntent intent) {
192
192
intent.motion_command = empty_motion_cmd;
193
193
return intent;
194
194
} else if (current_state_ == SEEKING) {
195
- // Determine target position for seeking
196
- rj_geometry::Point current_loc =
197
- last_world_state_->get_robot (true , robot_id_).pose .position ();
198
- rj_geometry::Point curr_target = intent.motion_command .target .position ;
199
- // Only look for a new position if we are done with current movement
200
- if (check_is_done () || target_pt == rj_geometry::Point {0 , 0 }) {
201
- target_pt = get_open_point (last_world_state_, current_loc, field_dimensions_);
195
+ // Only get a new target position if we have reached our target
196
+ if (check_is_done () || last_world_state_->get_robot (true , robot_id_).velocity .linear ().mag () <= 0.01 ) {
197
+ Seeking seeker{robot_id_};
198
+ return seeker.get_task (intent, last_world_state_, this ->field_dimensions_ );
202
199
}
203
- planning::PathTargetFaceOption face_option = planning::FaceBall{};
204
- bool ignore_ball = false ;
205
- planning::LinearMotionInstant goal{target_pt, rj_geometry::Point {0.0 , 0.0 }};
206
- intent.motion_command =
207
- planning::MotionCommand{" path_target" , goal, face_option, ignore_ball};
208
- return intent;
209
200
}
210
201
211
202
// should be impossible to reach, but this is an EmptyMotionCommand
212
203
return std::nullopt;
213
204
}
214
205
215
- rj_geometry::Point Offense::get_open_point (const WorldState* world_state,
216
- rj_geometry::Point current_loc,
217
- FieldDimensions field_dimensions) {
218
- return Offense::calculate_open_point (3.0 , .2 , current_loc, world_state, field_dimensions);
219
- }
220
-
221
- rj_geometry::Point Offense::calculate_open_point (double current_prec, double min_prec,
222
- rj_geometry::Point current_point,
223
- const WorldState* world_state,
224
- FieldDimensions field_dimensions) {
225
- while (current_prec > min_prec) {
226
- rj_geometry::Point ball_pos = world_state->ball .position ;
227
- rj_geometry::Point min = current_point;
228
- double min_val = max_los (ball_pos, current_point, world_state);
229
- double curr_val{};
230
- // Points in a current_prec radius of the current point, at 45 degree intervals
231
- std::vector<rj_geometry::Point > check_points{
232
- correct_point (current_point + rj_geometry::Point {current_prec, 0 }, field_dimensions),
233
- correct_point (current_point + rj_geometry::Point {-current_prec, 0 }, field_dimensions),
234
- correct_point (current_point + rj_geometry::Point {0 , current_prec}, field_dimensions),
235
- correct_point (current_point + rj_geometry::Point {0 , -current_prec}, field_dimensions),
236
- correct_point (
237
- current_point + rj_geometry::Point {current_prec * 0.707 , current_prec * 0.707 },
238
- field_dimensions),
239
- correct_point (
240
- current_point + rj_geometry::Point {current_prec * 0.707 , -current_prec * 0.707 },
241
- field_dimensions),
242
- correct_point (
243
- current_point + rj_geometry::Point {-current_prec * 0.707 , current_prec * 0.707 },
244
- field_dimensions),
245
- correct_point (
246
- current_point + rj_geometry::Point {-current_prec * 0.707 , -current_prec * 0.707 },
247
- field_dimensions)};
248
-
249
- for (auto point : check_points) {
250
- curr_val = max_los (ball_pos, point, world_state);
251
- if (curr_val < min_val) {
252
- min_val = curr_val;
253
- min = point;
254
- }
255
- }
256
- current_prec *= 0.5 ;
257
- current_point = min;
258
- }
259
- return current_point;
260
- }
261
-
262
- rj_geometry::Point Offense::random_noise (double prec) {
263
- double x = (double )rand () / RAND_MAX * prec;
264
- double y = (double )rand () / RAND_MAX * prec;
265
- return rj_geometry::Point {x, y};
266
- }
267
-
268
- rj_geometry::Point Offense::correct_point (rj_geometry::Point p, FieldDimensions field_dimensions) {
269
- double BORDER_BUFFER = .2 ;
270
- double x = p.x ();
271
- double y = p.y ();
272
-
273
- // X Border
274
- if (p.x () > field_dimensions.field_x_right_coord () - BORDER_BUFFER) {
275
- x = field_dimensions.field_x_right_coord () - BORDER_BUFFER;
276
- } else if (p.x () < field_dimensions.field_x_left_coord () + BORDER_BUFFER) {
277
- x = field_dimensions.field_x_left_coord () + BORDER_BUFFER;
278
- }
279
-
280
- // Y Border
281
- if (p.y () > field_dimensions.their_goal_loc ().y () - BORDER_BUFFER) {
282
- y = field_dimensions.their_goal_loc ().y () - BORDER_BUFFER;
283
- } else if (p.y () < field_dimensions.our_goal_loc ().y () + BORDER_BUFFER) {
284
- y = field_dimensions.our_goal_loc ().y () + BORDER_BUFFER;
285
- }
286
-
287
- // Goalie Boxes
288
- if ((y < 1.2 || y > 7.8 ) && fabs (x) < 1.2 ) {
289
- if (y > 4.5 ) {
290
- y = 8.0 - BORDER_BUFFER;
291
- } else {
292
- y = 1.0 + BORDER_BUFFER;
293
- }
294
-
295
- if (x > .5 ) {
296
- x = 1.0 + BORDER_BUFFER;
297
- } else {
298
- x = -1.0 - BORDER_BUFFER;
299
- }
300
- }
301
-
302
- // Assigns robots to horizontal thirds
303
- if (robot_id_ == 1 ) {
304
- // Assign left
305
- if (x > field_dimensions.field_x_left_coord () + field_dimensions.width () / 2 ) {
306
- x = field_dimensions.field_x_left_coord () + field_dimensions.width () / 2 -
307
- BORDER_BUFFER;
308
- }
309
- } else if (robot_id_ == 2 ) {
310
- // Assign right
311
- if (x < field_dimensions.field_x_right_coord () - field_dimensions.width () / 2 ) {
312
- x = field_dimensions.field_x_right_coord () - field_dimensions.width () / 2 +
313
- BORDER_BUFFER;
314
- }
315
- } else {
316
- // Assign middle
317
- if (x < field_dimensions.field_x_left_coord () + field_dimensions.width () / 3 ) {
318
- x = field_dimensions.field_x_left_coord () + field_dimensions.width () / 3 +
319
- BORDER_BUFFER;
320
- } else if (x > field_dimensions.field_x_right_coord () - field_dimensions.width () / 3 ) {
321
- x = field_dimensions.field_x_right_coord () - field_dimensions.width () / 3 -
322
- BORDER_BUFFER;
323
- }
324
- }
325
-
326
- return rj_geometry::Point (x, y);
327
- }
328
-
329
- double Offense::max_los (rj_geometry::Point ball_pos, rj_geometry::Point current_point,
330
- const WorldState* world_state) {
331
- // Determines 'how good' a point is
332
- // A higher value is a worse point
333
-
334
- // Does not go into the goalie boxes
335
- rj_geometry::Rect goal_box{rj_geometry::Point {1 , 8 }, rj_geometry::Point {-1 , 9 }};
336
- if (goal_box.contains_point (current_point)) {
337
- return 10000000 ;
338
- }
339
-
340
- // Line of Sight Heuristic
341
- double max = 0 ;
342
- double curr_dp;
343
- for (auto robot : world_state->their_robots ) {
344
- curr_dp = (current_point).norm ().dot ((robot.pose .position () - ball_pos).norm ());
345
- curr_dp *= curr_dp;
346
- if (curr_dp > max) {
347
- max = curr_dp;
348
- }
349
- }
350
-
351
- // Whether the path from ball to the point is blocked
352
- // Same logic in passing to check if target is open
353
- rj_geometry::Segment pass_path{ball_pos, current_point};
354
- double min_robot_dist = 10000 ;
355
- float min_path_dist = 10000 ;
356
- for (auto bot : world_state->their_robots ) {
357
- rj_geometry::Point opp_pos = bot.pose .position ();
358
- min_robot_dist = std::min (min_robot_dist, current_point.dist_to (opp_pos));
359
- min_path_dist = std::min (min_path_dist, pass_path.dist_to (opp_pos));
360
- }
361
-
362
- for (auto bot : world_state->our_robots ) {
363
- rj_geometry::Point ally_pos = bot.pose .position ();
364
- min_robot_dist = std::min (min_robot_dist, current_point.dist_to (ally_pos));
365
- min_path_dist = std::min (min_path_dist, pass_path.dist_to (ally_pos));
366
- }
367
-
368
- min_path_dist = 0.1 / min_path_dist;
369
- min_robot_dist = 0.1 / min_robot_dist;
370
-
371
- // More Line of Sight Heuristics
372
- for (auto robot : world_state->our_robots ) {
373
- curr_dp = (current_point - ball_pos).norm ().dot ((robot.pose .position () - ball_pos).norm ());
374
- curr_dp *= curr_dp;
375
- if (curr_dp > max) {
376
- max = curr_dp;
377
- }
378
- }
379
-
380
- // Additional heuristics for calculating optimal point
381
- double ball_proximity_loss = (current_point - ball_pos).mag () * .002 ;
382
- double goal_distance_loss = (9.0 - current_point.y ()) * .008 ;
383
-
384
- // Final evaluation
385
- return max + ball_proximity_loss + goal_distance_loss + min_path_dist + min_robot_dist;
386
- }
387
-
388
206
void Offense::receive_communication_response (communication::AgentPosResponseWrapper response) {
389
207
Position::receive_communication_response (response);
390
208
0 commit comments