Path Visualization

OMPL does not contain any built-in visualization tools, but it is usually not too difficult to visualize paths with external software. The basic idea is to print the path as a matrix, save it to a text file, and open this file in an external program. In OMPL there are two different kinds of paths: ompl::geometric::PathGeometric and ompl::control::PathControl. Both classes have a method called printAsMatrix(). For ompl::geometric::PathGeometric the matrix consists of all the states along the path, one per row. For ompl::control::PathControl each row also contains the controls and control duration needed to reach the state in this row starting from the state in the previous row (the controls and duration in the first row are all zeros). The basic usage is as follows.


1 solved = ss.solve(20.0) # ss is a SimpleSetup object
2 if solved:
3  print(ss.getSolutionPath().printAsMatrix())


bool solved = ss.solve(20.0); // ss is a SimpleSetup object
if (solved)

In the case of ompl::control::PathControl, you may want to convert the path first to a geometric path. This conversion automatically interpolates the path at the propagation step size. The code above then changes to:


1 solved = ss.solve(20.0) # ss is a SimpleSetup object
2 if solved:
3  print(ss.getSolutionPath().asGeometric().printAsMatrix())


bool solved = ss.solve(20.0); // ss is a SimpleSetup object
if (solved)

Run your program and save the output of printAsMatrix() to a file called, say, path.txt. Let us assume the path consists of SE(3) states. This means that the first three columns represent the 3D position component of the state and the next four columns the orientation represented by a unit quaternion. Below we will describe how to visualize this path with a variety of programs.

  • GUI: The GUI can be used to “play back” any path consisting of SE(2) or SE(3) paths. First, load a mesh representing the robot and (optionally) a mesh representing the environment. Next, load the path file path.txt. You can either let the GUI loop through the states along the path or show them all simultaneously.
  • Matplotlib:
    1 from mpl_toolkits.mplot3d import Axes3D
    2 import numpy
    3 import matplotlib.pyplot as plt
    5 data = numpy.loadtxt('path.txt')
    6 fig = plt.figure()
    7 ax = fig.gca(projection='3d')
    8 ax.plot(data[:,1],data[:,2],data[:,3],'.-')
  • Matlab / Octave:
    1 data=load('path.txt');
    2 plot3(data(:,1), data(:,2), data(:,3), 'o-');
    3 axis equal, grid on, rotate3d on;
  • Excel: When you open path.txt with Excel, it will guide you through the process of importing it into a spreadsheet. You should select space-delimited data. Unfortunately, it looks like it is difficult to make plots of a 3D curve in Excel. However, you can plot 2D curves. To create such a plot, select the first two columns of data and select "Insert>Chart...". Next, click on "Scatter>Straight Marked Scatter". (This is for Microsoft Excel for Mac 2011; the menu items might be called something slightly differently in the Microsoft Windows version.)
  • R: First, you need to install the scatterplot3d package:
    1 install.packages(scatterplot3d)
    Then you can plot the path like so:
    1 library(scatterplot3d)
    2 data <- read.table('path.txt')
    3 scatterplot3d(data[,('V1')], data[,('V2')], data[,('V3')], color = "blue", type = "l", angle = 120, xlab='x', ylab='y', zlab='z')
  • gnuplot:
    1 set grid xtics ytics ztics
    2 splot "path.txt" using 1:2:3 with linespoints

Plotting little coordinate frames at each position to represent the orientation encoded by the quaternion in columns 4 through 7 is straightforward and left as an exercise to the reader.