Skip to content

Commit d85565e

Browse files
committed
Dynamic rally points
1 parent 3190785 commit d85565e

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

terrain_planner_benchmark/src/run_dynamic_rallypoints.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ int main(int argc, char** argv) {
428428
/// Visualize Geofence
429429
publishGeoFence(geofence_pub, geofence_polygon);
430430

431-
///TODO: Parse mission to generate reference path
431+
// Parse mission to generate reference path
432432
std::vector<Eigen::Vector3d> waypoint_list;
433433
json mission = data["mission"]["items"];
434434
for (auto mission_item : mission) {
@@ -440,7 +440,6 @@ int main(int argc, char** argv) {
440440
const double waypoint_lat = mission_item["params"][4];
441441
const double waypoint_lon = mission_item["params"][5];
442442
const double waypoint_relative_alt = mission_item["params"][6];
443-
Eigen::Vector3d waypoint_wgs84(waypoint_lat, waypoint_lon, waypoint_relative_alt);
444443
Eigen::Vector3d waypoint_lv03;
445444
GeoConversions::forward(waypoint_lat, waypoint_lon, 0.0, waypoint_lv03.x(), waypoint_lv03.y(),
446445
waypoint_lv03.z()); /// FIXME: Assuming zero AMSL
@@ -457,6 +456,30 @@ int main(int argc, char** argv) {
457456

458457
publishWaypoints(waypoint_pub, waypoint_list);
459458

459+
/// Parse rally points from mission file
460+
std::vector<Eigen::Vector3d> rallypoint_list;
461+
const double map_width_x = terrain_map->getGridMap().getLength().x();
462+
const double map_width_y = terrain_map->getGridMap().getLength().y();
463+
const Eigen::Vector2d map_pos = terrain_map->getGridMap().getPosition();
464+
465+
json mission_rallypoints = data["rallyPoints"]["points"];
466+
for (auto rallypoint : mission_rallypoints) {
467+
std::cout << " - Rallypoint: " << rallypoint << std::endl;
468+
const double rallypoint_lat = rallypoint[0];
469+
const double rallypoint_lon = rallypoint[1];
470+
const double rallypoint_relative_alt = rallypoint[2];
471+
Eigen::Vector3d rallypoint_lv03;
472+
GeoConversions::forward(rallypoint_lat, rallypoint_lon, 0.0, rallypoint_lv03.x(), rallypoint_lv03.y(),
473+
rallypoint_lv03.z()); /// FIXME: Assuming zero AMSL
474+
ESPG map_coordinate;
475+
Eigen::Vector3d map_origin;
476+
terrain_map->getGlobalOrigin(map_coordinate, map_origin);
477+
Eigen::Vector3d rallypoint_local = rallypoint_lv03 - map_origin;
478+
rallypoint_local.z() = terrain_map->getGridMap().atPosition("elevation", rallypoint_local.head(2)) + rallypoint_relative_alt;
479+
rallypoint_list.push_back(rallypoint_local);
480+
}
481+
publishRallyPoints(rallypoint_pub, rallypoint_list, radius, Eigen::Vector3d(1.0, 0.0, 0.0));
482+
460483
terrain_map->getGridMap().setTimestamp(ros::Time::now().toNSec());
461484
publishGridMap(grid_map_pub, terrain_map->getGridMap());
462485

@@ -468,10 +491,6 @@ int main(int argc, char** argv) {
468491
/// TODO: Get bounds from gridmap
469492
planner->setBoundsFromMap(terrain_map->getGridMap());
470493

471-
const double map_width_x = terrain_map->getGridMap().getLength().x();
472-
const double map_width_y = terrain_map->getGridMap().getLength().y();
473-
const Eigen::Vector2d map_pos = terrain_map->getGridMap().getPosition();
474-
475494
Eigen::Vector3d start{Eigen::Vector3d(map_pos(0) + 0.4 * map_width_x, map_pos(1) - 0.35 * map_width_y, 0.0)};
476495
Eigen::Vector3d updated_start;
477496
if (validatePosition(terrain_map, start, updated_start)) {
@@ -509,28 +528,6 @@ int main(int argc, char** argv) {
509528

510529
path.appendSegment(goal_loiter_path);
511530

512-
/// Generate candidate rally points
513-
std::cout << "Generating rally points" << std::endl;
514-
const int num_rally_points = 6;
515-
std::vector<Eigen::Vector3d> rally_points;
516-
for (int i = 0; i < num_rally_points; i++) {
517-
bool sample_is_valid = false;
518-
while (!sample_is_valid) {
519-
Eigen::Vector3d random_sample;
520-
random_sample(0) =
521-
getRandom(map_pos(0) - (0.4 * map_width_x - radius), map_pos(0) + (0.4 * map_width_x - radius));
522-
random_sample(1) =
523-
getRandom(map_pos(1) - (0.4 * map_width_y - radius), map_pos(1) + (0.4 * map_width_y - radius));
524-
Eigen::Vector3d candidate_loiter_position = random_sample;
525-
Eigen::Vector3d new_loiter_position;
526-
sample_is_valid = validatePosition(terrain_map->getGridMap(), candidate_loiter_position, new_loiter_position);
527-
if (sample_is_valid) {
528-
rally_points.push_back(new_loiter_position);
529-
}
530-
}
531-
}
532-
publishRallyPoints(rallypoint_pub, rally_points, radius, Eigen::Vector3d(1.0, 1.0, 0.0));
533-
534531
std::cout << "Successfully Generated rally points" << std::endl;
535532

536533
/// TODO: Iterate over path segments to find abort paths
@@ -540,7 +537,7 @@ int main(int argc, char** argv) {
540537
std::cout << " - segment ID: " << segment_id << std::endl;
541538
Eigen::Vector3d segment_end = path_segment.states.back().position;
542539
Eigen::Vector3d segment_end_tangent = path_segment.states.back().velocity;
543-
planner->setupProblem(segment_end, segment_end_tangent, rally_points);
540+
planner->setupProblem(segment_end, segment_end_tangent, rallypoint_list);
544541
Path abort_path;
545542
if (planner->Solve(10.0, abort_path)) {
546543
std::cout << "[TestRRTCircleGoal] Found Solution!" << std::endl;

0 commit comments

Comments
 (0)