Skip to content

Commit c6dedc0

Browse files
authored
Extract path segments (#7)
* WIP extract path segments Fix path segment extraction * Fix path visualizations * Add dubins path planner example * Fix parsing velocity states * Add back loiter path segment
1 parent 04e7ee8 commit c6dedc0

File tree

6 files changed

+140
-89
lines changed

6 files changed

+140
-89
lines changed

terrain_navigation/include/terrain_navigation/path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Path {
6969
void resetSegments() { segments.clear(); };
7070
void prependSegment(const PathSegment &trajectory) { segments.insert(segments.begin(), trajectory); };
7171
void prependSegment(const Path &trajectory_segments) {
72-
for (int i = trajectory_segments.segments.size() -1; i > -1; i--) {
72+
for (int i = trajectory_segments.segments.size() - 1; i > -1; i--) {
7373
prependSegment(trajectory_segments.segments[i]);
7474
}
7575
}

terrain_planner/include/terrain_planner/terrain_ompl_rrt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ class TerrainOmplRrt {
202202
min_altitude_ = min_altitude;
203203
}
204204

205+
PathSegment extractPathSegment(ompl::base::State* from, ompl::base::State* to,
206+
ompl::base::OwenStateSpace::PathType& path, double t_start = 0.0, double t_end = 1.0,
207+
double dt = 0.01) const;
208+
205209
private:
206210
// double minimum_turning_radius_{66.67};
207211
std::shared_ptr<ompl::OmplSetup> problem_setup_;

terrain_planner/src/terrain_ompl_rrt.cpp

Lines changed: 76 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,24 @@ bool TerrainOmplRrt::getSolutionPath(std::vector<Eigen::Vector3d>& path) {
333333
// return segment_curvature;
334334
// }
335335

336+
PathSegment TerrainOmplRrt::extractPathSegment(ompl::base::State* from, ompl::base::State* to,
337+
ompl::base::OwenStateSpace::PathType& path, double t_start, double t_end,
338+
double dt) const {
339+
ompl::base::State* state = problem_setup_->getStateSpace()->allocState();
340+
PathSegment trajectory;
341+
for (double t = t_start; t <= t_end; t += dt) {
342+
// Append to trajectory
343+
problem_setup_->getStateSpace()->as<ompl::base::OwenStateSpace>()->interpolate(from, to, t, path, state);
344+
State segment_state;
345+
segment_state.position = dubinsairplanePosition(state);
346+
double yaw = dubinsairplaneYaw(state);
347+
Eigen::Vector3d velocity = Eigen::Vector3d(std::cos(yaw), std::sin(yaw), 0.0);
348+
segment_state.velocity = velocity;
349+
trajectory.states.emplace_back(segment_state);
350+
}
351+
return trajectory;
352+
}
353+
336354
void TerrainOmplRrt::solutionPathToPath(ompl::geometric::PathGeometric path, Path& trajectory_segments,
337355
double resolution) const {
338356
trajectory_segments.segments.clear();
@@ -341,72 +359,64 @@ void TerrainOmplRrt::solutionPathToPath(ompl::geometric::PathGeometric path, Pat
341359
for (size_t idx = 0; idx < state_vector.size() - 1; idx++) {
342360
auto from = state_vector[idx]; // Start of the segment
343361
auto to = state_vector[idx + 1]; // End of the segment
344-
auto path = problem_setup_->getStateSpace()->as<ompl::base::OwenStateSpace>()->getPath(from, to);
345-
// ompl::base::OwenStateSpace::SegmentStarts segmentStarts;
346-
// problem_setup_->getStateSpace()->as<ompl::base::OwenStateSpace>()->calculateSegments(
347-
// from, to, dubins_path, segmentStarts);
348-
349-
ompl::base::State* segment_start_state = problem_setup_->getStateSpace()->allocState();
350-
ompl::base::State* segment_end_state = problem_setup_->getStateSpace()->allocState();
351-
352-
// const double total_length = dubins_path.length_2D();
353-
// const double dt = resolution / dubins_path.length_2D();
354-
double progress{0.0};
355-
// for (size_t start_idx = 0; start_idx < segmentStarts.segmentStarts.size(); start_idx++) {
356-
// if (dubins_path.getSegmentLength(start_idx) > 0.0) {
357-
// double segment_progress = dubins_path.getSegmentLength(start_idx) / total_length;
358-
// // Read segment start and end statess
359-
// segmentStart2omplState(segmentStarts.segmentStarts[start_idx], segment_start_state);
360-
// if ((start_idx + 1) > (segmentStarts.segmentStarts.size() - 1)) {
361-
// segment_end_state = to;
362-
// } else if ((start_idx + 1) > (segmentStarts.segmentStarts.size() - 2) &&
363-
// dubins_path.getSegmentLength(start_idx + 1) == 0.0) {
364-
// segment_end_state = to;
365-
// } else {
366-
// segmentStart2omplState(segmentStarts.segmentStarts[start_idx + 1], segment_end_state);
367-
// }
368-
369-
// // Append to trajectory
370-
// PathSegment trajectory;
371-
// trajectory.curvature = getSegmentCurvature(problem_setup_, dubins_path, start_idx);
372-
// ompl::base::State* state = problem_setup_->getStateSpace()->allocState();
373-
// trajectory.flightpath_angle = dubins_path.getGamma();
374-
// double yaw;
375-
// double track_progress{0.0};
376-
// for (double t = progress; t <= progress + segment_progress; t = t + dt) {
377-
// State segment_state;
378-
// problem_setup_->getStateSpace()->as<ompl::base::OwenStateSpace>()->interpolate(
379-
// dubins_path, segmentStarts, t, state);
380-
// Eigen::Vector3d position = dubinsairplanePosition(state);
381-
// yaw = dubinsairplaneYaw(state);
382-
// Eigen::Vector3d velocity = Eigen::Vector3d(std::cos(yaw), std::sin(yaw), 0.0);
383-
// segment_state.position = position;
384-
// segment_state.velocity = velocity;
385-
// segment_state.attitude = Eigen::Vector4d(std::cos(yaw / 2.0), 0.0, 0.0, std::sin(yaw / 2.0));
386-
// trajectory.states.emplace_back(segment_state);
387-
// track_progress = t;
388-
// }
389-
// // Append end state
390-
// if (((start_idx + 1) > (segmentStarts.segmentStarts.size() - 1)) ||
391-
// ((start_idx + 1) > (segmentStarts.segmentStarts.size() - 2) &&
392-
// dubins_path.getSegmentLength(start_idx + 1) == 0.0)) {
393-
// // Append segment with last state
394-
// State end_state;
395-
// Eigen::Vector3d end_position = dubinsairplanePosition(segment_end_state);
396-
// double end_yaw = dubinsairplaneYaw(segment_end_state);
397-
// Eigen::Vector3d end_velocity = Eigen::Vector3d(std::cos(end_yaw), std::sin(end_yaw), 0.0);
398-
// end_state.position = end_position;
399-
// end_state.velocity = end_velocity;
400-
// end_state.attitude = Eigen::Vector4d(std::cos(end_yaw / 2.0), 0.0, 0.0, std::sin(end_yaw / 2.0));
401-
// trajectory.states.emplace_back(end_state);
402-
// }
403-
// progress = track_progress;
404-
// // Do not append trajectory if the segment is too short
405-
// if (trajectory.states.size() > 1) {
406-
// trajectory_segments.segments.push_back(trajectory);
407-
// }
408-
// }
409-
// }
362+
auto dubins_path = problem_setup_->getStateSpace()->as<ompl::base::OwenStateSpace>()->getPath(from, to);
363+
364+
if (dubins_path->phi_ == 0.) {
365+
if (dubins_path->numTurns_ == 0) {
366+
// Low path case
367+
double t_start{0.0};
368+
double t_end{0.0};
369+
double length = dubins_path->path_.length();
370+
for (int idx = 0; idx < 3; idx++) {
371+
t_end = idx == 2 ? 1.0 : dubins_path->path_.length_[idx] / length + t_start;
372+
auto trajectory = extractPathSegment(from, to, *dubins_path, t_start, t_end);
373+
if (trajectory.states.size() > 1) {
374+
trajectory_segments.segments.push_back(trajectory);
375+
}
376+
t_start = t_end;
377+
}
378+
} else {
379+
// high altitude path
380+
381+
// Parse Trochoidal periodic paths
382+
double lengthPeriodicPath = 2.0 * M_PI * dubins_path->turnRadius_;
383+
auto lengthPath = dubins_path->path_.length();
384+
auto lengthTotal = lengthPath + lengthPeriodicPath * dubins_path->numTurns_;
385+
double t_start, t_end;
386+
for (int k = 0; k < dubins_path->numTurns_; k++) {
387+
/// TODO: Further divide this into segments
388+
t_start = lengthPeriodicPath * k / lengthTotal;
389+
t_end = lengthPeriodicPath * (k + 1) / lengthTotal;
390+
auto trajectory = extractPathSegment(from, to, *dubins_path, t_start, t_end);
391+
if (trajectory.states.size() > 1) {
392+
trajectory_segments.segments.push_back(trajectory);
393+
}
394+
}
395+
// Path
396+
t_start = lengthPeriodicPath * dubins_path->numTurns_ / lengthTotal;
397+
auto trajectory = extractPathSegment(from, to, *dubins_path, t_start, 1.0);
398+
if (trajectory.states.size() > 1) {
399+
trajectory_segments.segments.push_back(trajectory);
400+
}
401+
}
402+
} else {
403+
// medium altitude path
404+
auto lengthTurn = std::abs(dubins_path->phi_);
405+
auto lengthPath = dubins_path->path_.length();
406+
auto lengthTotal = lengthTurn + lengthPath;
407+
{
408+
auto trajectory = extractPathSegment(from, to, *dubins_path, 0.0, lengthTurn / lengthTotal);
409+
if (trajectory.states.size() > 1) {
410+
trajectory_segments.segments.push_back(trajectory);
411+
}
412+
}
413+
{
414+
auto trajectory = extractPathSegment(from, to, *dubins_path, lengthTurn / lengthTotal, 1.0);
415+
if (trajectory.states.size() > 1) {
416+
trajectory_segments.segments.push_back(trajectory);
417+
}
418+
}
419+
}
410420
}
411421
}
412422

terrain_planner_benchmark/launch/config.rviz

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Panels:
44
Name: Displays
55
Property Tree Widget:
66
Expanded:
7+
- /GridMap1
78
- /GridMap1/ElevationGridMap1
9+
- /GridMap1/AvalancheGridMap1
810
- /Planning1
911
Splitter Ratio: 0.5
1012
Tree Height: 930
@@ -145,15 +147,15 @@ Visualization Manager:
145147
Value: /grid_map
146148
Use Rainbow: true
147149
Value: false
148-
- Alpha: 0.8999999761581421
150+
- Alpha: 0.5
149151
Autocompute Intensity Bounds: true
150152
Class: grid_map_rviz_plugin/GridMap
151153
Color: 200; 200; 200
152154
Color Layer: elevation
153-
Color Transformer: GridMapLayer
154-
Enabled: false
155+
Color Transformer: IntensityLayer
156+
Enabled: true
155157
Height Layer: elevation
156-
Height Transformer: GridMapLayer
158+
Height Transformer: Layer
157159
History Length: 1
158160
Invert Rainbow: false
159161
Max Color: 255; 255; 255
@@ -168,9 +170,9 @@ Visualization Manager:
168170
Filter size: 10
169171
History Policy: Keep Last
170172
Reliability Policy: Reliable
171-
Value: /avalanche_map
173+
Value: /grid_map
172174
Use Rainbow: true
173-
Value: false
175+
Value: true
174176
Enabled: true
175177
Name: GridMap
176178
- Class: rviz_common/Group
@@ -239,7 +241,7 @@ Visualization Manager:
239241
Enabled: true
240242
Name: PathSegmentsMarkerArray
241243
Namespaces:
242-
{}
244+
normals: true
243245
Topic:
244246
Depth: 5
245247
Durability Policy: Volatile
@@ -263,7 +265,7 @@ Visualization Manager:
263265
Buffer Length: 1
264266
Class: rviz_default_plugins/Path
265267
Color: 255; 255; 0
266-
Enabled: true
268+
Enabled: false
267269
Head Diameter: 0.30000001192092896
268270
Head Length: 0.20000000298023224
269271
Length: 0.30000001192092896
@@ -286,7 +288,7 @@ Visualization Manager:
286288
History Policy: Keep Last
287289
Reliability Policy: Reliable
288290
Value: /path
289-
Value: true
291+
Value: false
290292
Enabled: true
291293
Name: Planning
292294
Enabled: true
@@ -336,25 +338,25 @@ Visualization Manager:
336338
Views:
337339
Current:
338340
Class: rviz_default_plugins/Orbit
339-
Distance: 3363.000244140625
341+
Distance: 4154.14404296875
340342
Enable Stereo Rendering:
341343
Stereo Eye Separation: 0.05999999865889549
342344
Stereo Focal Distance: 1
343345
Swap Stereo Eyes: false
344346
Value: false
345347
Focal Point:
346-
X: -324.49951171875
347-
Y: -279.8844299316406
348-
Z: 1438.21044921875
348+
X: -205.7038116455078
349+
Y: -69.17835235595703
350+
Z: 174.4804229736328
349351
Focal Shape Fixed Size: true
350352
Focal Shape Size: 0.05000000074505806
351353
Invert Z Axis: false
352354
Name: Current View
353355
Near Clip Distance: 0.009999999776482582
354-
Pitch: 0.7297971248626709
356+
Pitch: 0.45479774475097656
355357
Target Frame: map
356358
Value: Orbit (rviz_default_plugins)
357-
Yaw: 0.7050155997276306
359+
Yaw: 3.7250149250030518
358360
Saved: ~
359361
Window Geometry:
360362
Displays:
@@ -364,7 +366,7 @@ Window Geometry:
364366
Hide Right Dock: true
365367
PlanningPanel:
366368
collapsed: false
367-
QMainWindow State: 000000ff00000000fd000000040000000000000156000003ddfc020000000bfb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000078000003dd000000c700fffffffb0000001a0050006c0061006e006e0069006e006700500061006e0065006c0000000263000001f20000014e00fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000000a0049006d006100670065010000020c000001b10000000000000000fb0000000c00540065006c0065006f00700000000368000000b20000006e00ffffff000000010000010f000002dafc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000064000002da000000a000fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b20000000000000000000000020000073a00000037fc0100000002fb0000000800540069006d006501000000000000073a0000025300fffffffb0000000a00560069006500770073030000004e00000080000002e10000019700000003000007800000014efc0100000001fb0000000800540069006d00650100000000000004500000000000000000000005de000003dd00000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
369+
QMainWindow State: 000000ff00000000fd000000040000000000000156000003ddfc020000000bfb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000078000003dd000000c700fffffffb0000001a0050006c0061006e006e0069006e006700500061006e0065006c0000000263000001f20000006e00fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000000a0049006d006100670065010000020c000001b10000000000000000fb0000000c00540065006c0065006f00700000000368000000b20000006e00ffffff000000010000010f000002dafc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000064000002da000000a000fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b20000000000000000000000020000073a00000037fc0100000002fb0000000800540069006d006501000000000000073a0000025300fffffffb0000000a00560069006500770073030000004e00000080000002e10000019700000003000007800000014efc0100000001fb0000000800540069006d00650100000000000004500000000000000000000005de000003dd00000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
368370
Selection:
369371
collapsed: false
370372
Teleop:
@@ -376,5 +378,5 @@ Window Geometry:
376378
Views:
377379
collapsed: true
378380
Width: 1850
379-
X: 872
380-
Y: 1467
381+
X: 70
382+
Y: 27

terrain_planner_benchmark/launch/test_ompl_rrt_circle_launch.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
<!-- <node pkg="tf" type="static_transform_publisher" name="world_map" args="0 0 0 0 0 0 world map 10"/> -->
44
<node pkg="terrain_planner_benchmark" exec="test_rrt_circle_goal" name="rrt_planner" output="screen">
55
<param name="location" value="sertig"/>
6-
<param name="map_path" value="$(find-pkg-share terrain_models)/models/sertig.tif"/>
7-
<param name="color_file_path" value="$(find-pkg-share terrain_models)/models/sertig_color.tif"/>
6+
<param name="map_path" value="/home/jaeyoung/dev/terrain-loader/downloads/berkeley_elevation.tif"/>
7+
<param name="color_file_path" value="/home/jaeyoung/dev/terrain-loader/downloads/berkeley_ortho.tif"/>
8+
<!-- <param name="map_path" value="$(find-pkg-share terrain_models)/models/sertig.tif"/>
9+
<param name="color_file_path" value="$(find-pkg-share terrain_models)/models/sertig_color.tif"/> -->
810
<param name="output_directory" value="$(find-pkg-share terrain_planner_benchmark)/../output"/>
911
</node>
1012
<node pkg="rviz2" exec="rviz2" name="rviz" args="-d $(find-pkg-share terrain_planner_benchmark)/launch/config.rviz" />

0 commit comments

Comments
 (0)