3 #include <boost/program_options.hpp>
5 #include <ompl/base/Planner.h>
21 namespace po = boost::program_options;
31 static const double TIME = 60.0;
44 tso.
title =
"Live Profiling";
50 const auto &points = result.getProgressPropertiesAsPoints(
"time REAL", field);
51 tso.
points.emplace(field, points);
65 const auto &ompl_planner = std::dynamic_pointer_cast<const OMPL::OMPLInterfacePlanner>(planner);
66 const auto &ss = ompl_planner->getLastSimpleSetup();
67 const auto &op = ss->getPlanner();
70 ompl::base::PlannerData pd(op->getSpaceInformation());
71 op->getPlannerData(pd);
87 const auto &ompl_planner = std::dynamic_pointer_cast<const OMPL::OMPLInterfacePlanner>(planner);
88 const auto &ss = ompl_planner->getLastSimpleSetup();
89 const auto &op = ss->getPlanner();
95 const auto &
robot = planner->getRobot();
96 const auto &ss = op->getSpaceInformation()->getStateSpace();
99 ompl::base::PlannerData pd(op->getSpaceInformation());
100 op->getPlannerData(pd);
108 const auto &pdv = pd.getVertex(i);
109 const auto &state = pdv.getState();
110 ss->copyToReals(reals, state);
113 poses[i] =
robot->getLinkTF(
"wrist_roll_link");
119 {1, 0.37, 0.81, 0.4}};
128 pd.getEdges(i, edges);
129 const auto &src = pd.getVertex(i);
130 for (
const auto &edge : edges)
132 const auto &dst = pd.getVertex(edge);
136 colors.
emplace_back((si < color_map.
size()) ? color_map[si] : color_map[0]);
140 colors.
emplace_back((di < color_map.size()) ? color_map[di] : color_map[0]);
145 rviz->removeAllMarkers();
146 rviz->addLineMarker(
"graph", points, colors, 0.005);
147 rviz->updateMarkers();
160 const auto &ompl_planner = std::dynamic_pointer_cast<const OMPL::OMPLInterfacePlanner>(planner);
162 const auto &pdef = ompl_planner->getLastSimpleSetup()->getProblemDefinition();
163 double distance = pdef->getSolutionDifference();
167 const auto &start = pdef->getStartState(0);
168 const auto &goal = std::dynamic_pointer_cast<ompl::base::GoalRegion>(pdef->getGoal());
169 distance = goal->distanceGoal(start);
176 int main(
int argc,
char **argv)
184 bool custom_progress;
186 double progress_rate;
189 po::options_description description;
190 description.add_options()
191 (
"help,h",
"Produces this help message")
192 (
"planner,p", po::value<std::string>(&planner_name)->default_value(
"RRTstar"),
193 "Which OMPL Planner to use.")
194 (
"rate,r", po::value<double>(&progress_rate)->default_value(0.5),
195 "Update rate of planner progress property collection in seconds.")
196 (
"gnuplot,g", po::bool_switch(&gnuplot),
197 "Enables GNUPlot visualization of the best cost path (if a progress property)")
198 (
"liveplot,l", po::bool_switch(&live_plotting),
199 "Enables live GNUPlot plotting of `best cost` and `num vertices` (if enabled and available).")
200 (
"rviz,v", po::bool_switch(&rviz_enable),
201 "Enables live visualization of the planning graph through the RViz MarkerArray.")
202 (
"vertices,n", po::bool_switch(&custom_progress),
203 "Enables the number of vertices in the planning graph with a custom progress property.")
206 po::variables_map vm;
207 po::store(po::parse_command_line(argc, argv, description), vm);
209 if (vm.count(
"help"))
218 auto fetch = std::make_shared<FetchRobot>();
219 fetch->initialize(
false);
222 auto planner = std::make_shared<OMPL::OMPLInterfacePlanner>(
fetch);
227 planner->initialize(
"package://robowflex_resources/fetch/config/ompl_planning.yaml", settings);
231 scene->fromYAMLFile(
"package://robowflex_library/yaml/fetch_box/scene0001.yaml");
234 auto request = std::make_shared<MotionRequestBuilder>(planner,
GROUP);
235 request->fromYAMLFile(
"package://robowflex_library/yaml/fetch_box/request0001.yaml");
236 request->setAllowedPlanningTime(
TIME);
237 request->setNumPlanningAttempts(1);
238 request->setConfig(planner_name);
240 scene->getCurrentState() = *request->getStartConfiguration();
250 auto rviz = std::make_shared<IO::RVIZHelper>(
fetch);
252 rviz->updateScene(
scene);
256 tso.
title =
"Best Cost";
286 if (profiler.
profilePlan(planner,
scene, request->getRequest(), options, result))
301 RBX_INFO(
"Press Enter to Continue...");
Helper class to open a pipe to a GNUPlot instance for live visualization of data.
void timeseries(const TimeSeriesOptions &options)
Plot timeseries data.
Settings descriptor for settings provided by the default MoveIt! OMPL planning pipeline.
bool simplify_solutions
Whether or not planner should simplify solutions.
Detailed statistics and metrics computed from profiling a planner's motion planning.
std::vector< std::pair< double, double > > getProgressPropertiesAsPoints(const std::string &xprop, const std::string &yprop) const
Retrieves the time series data of a planner progress property for a given X-,Y- pair of progress prop...
TrajectoryPtr trajectory
The resulting trajectory, if available.
A shared pointer wrapper for robowflex::Planner.
void addProgressCallbackAllocator(const ProgressCallbackAllocator &allocator)
Add a function that is called in the planner progress property loop.
void addProgressCallback(const ProgressCallback &callback)
Add a function that is called in the planner progress property loop.
void addMetricCallback(const std::string &name, const ComputeMetricCallback &metric)
Add a callback function to compute a metric at the end of planning.
@ WAYPOINTS
Number of waypoints in path.
@ SMOOTHNESS
Smoothness of path.
@ CORRECT
Is the path correct (no collisions?).
@ LENGTH
Length of the path.
void addProgressAllocator(const std::string &name, const ProgressPropertyAllocator &allocator)
Add a function that allocates a function that returns a planner progress property function.
bool profilePlan(const PlannerPtr &planner, const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request, const Options &options, PlanData &result) const
Profiling a single plan using a planner.
RAII-pattern for starting up ROS.
A const shared pointer wrapper for robowflex::Scene.
T emplace_back(T... args)
Profiler::ProgressCallbackAllocator getRVIZGraphVisualizationAllocator(IO::RVIZHelperPtr &rviz)
Get a custom progress callback allocator that allocates a function to visualize the current planning ...
int main(int argc, char **argv)
Profiler::ComputeMetricCallback getGoalDistanceCallback()
Get a custom metric that computes the distance to the goal for the best solution the planner found.
Profiler::ProgressPropertyAllocator getNumVerticesAllocator()
Get a custom progress property function allocator that extracts the planner data from the underlying ...
static const std::string GROUP
Profiler::ProgressCallback getGNUPlotCallback(IO::GNUPlotHelper &plotter, const std::string &field)
Creates a progress callback function to plot the progress property field live using GNUPlot.
#define RBX_INFO(fmt,...)
Output a info logging message.
moveit_msgs::MotionPlanRequest MotionPlanRequest
Functions for loading and animating robots in Blender.
std::string format(const std::string &fmt, Args &&... args)
Recursion base case, return string form of formatted arguments.
Main namespace. Contains all library classes and functions.
boost::variant< bool, double, int, std::size_t, std::string > PlannerMetric
Variant type of possible values a run metric could be.
Functions for loading and animating scenes in Blender.
double max
Upper axis limit. If NaN, will auto-adjust.
double min
Lower axis limit. If NaN, will auto-adjust.
std::string label
Axis label.
std::string title
Title of the plot.
Time series plotting options.
std::map< std::string, Series > points
Map of names to time series data.
double progress_update_rate
Update rate for progress callbacks.
uint32_t metrics
Bitmask of which metrics to compute after planning.