moveit2
The MoveIt Motion Planning Framework for ROS 2.
BenchmarkExecutor.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2015, Rice University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Rice University nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ryan Luna */
36 
37 #pragma once
38 
40 
42 
49 #include <warehouse_ros/database_loader.h>
50 #include <pluginlib/class_loader.hpp>
51 
52 #include <map>
53 #include <vector>
54 #include <string>
55 #include <functional>
56 
58 {
62 {
63 public:
65  typedef std::map<std::string, std::string> PlannerRunData;
67  typedef std::vector<PlannerRunData> PlannerBenchmarkData;
68 
70  typedef std::function<void(const moveit_msgs::msg::MotionPlanRequest& request, planning_scene::PlanningScenePtr)>
72 
74  typedef std::function<void(const moveit_msgs::msg::MotionPlanRequest& request, planning_scene::PlanningScenePtr)>
76 
79  typedef std::function<void(const moveit_msgs::msg::MotionPlanRequest& request, PlannerBenchmarkData& benchmark_data)>
81 
84  typedef std::function<void(const moveit_msgs::msg::MotionPlanRequest& request, PlannerBenchmarkData& benchmark_data)>
86 
88  typedef std::function<void(moveit_msgs::msg::MotionPlanRequest& request)> PreRunEventFunction;
89 
91  typedef std::function<void(const moveit_msgs::msg::MotionPlanRequest& request,
94 
95  BenchmarkExecutor(const rclcpp::Node::SharedPtr& node,
96  const std::string& robot_description_param = "robot_description");
97  virtual ~BenchmarkExecutor();
98 
99  // Initialize the benchmark executor by loading planning pipelines from the
100  // given set of classes
101  [[nodiscard]] bool initialize(const std::vector<std::string>& plugin_classes);
102 
103  void addPreRunEvent(const PreRunEventFunction& func);
104  void addPostRunEvent(const PostRunEventFunction& func);
109 
110  virtual void clear();
111 
112  virtual bool runBenchmarks(const BenchmarkOptions& options);
113 
114 protected:
116  {
117  std::string name;
119  };
120 
121  struct StartState
122  {
123  moveit_msgs::msg::RobotState state;
124  std::string name;
125  };
126 
128  {
129  std::vector<moveit_msgs::msg::Constraints> constraints;
130  std::string name;
131  };
132 
134  {
135  moveit_msgs::msg::TrajectoryConstraints constraints;
136  std::string name;
137  };
138 
139  virtual bool initializeBenchmarks(const BenchmarkOptions& options, moveit_msgs::msg::PlanningScene& scene_msg,
140  std::vector<BenchmarkRequest>& queries);
141 
143  virtual bool loadBenchmarkQueryData(const BenchmarkOptions& options, moveit_msgs::msg::PlanningScene& scene_msg,
144  std::vector<StartState>& start_states,
145  std::vector<PathConstraints>& path_constraints,
146  std::vector<PathConstraints>& goal_constraints,
147  std::vector<TrajectoryConstraints>& traj_constraints,
148  std::vector<BenchmarkRequest>& queries);
149 
150  virtual void collectMetrics(PlannerRunData& metrics,
151  const planning_interface::MotionPlanDetailedResponse& motion_plan_response, bool solved,
152  double total_time);
153 
157  const std::vector<planning_interface::MotionPlanDetailedResponse>& responses,
158  const std::vector<bool>& solved);
159 
165  const robot_trajectory::RobotTrajectory& traj_second, double& result_distance);
166 
167  virtual void writeOutput(const BenchmarkRequest& benchmark_request, const std::string& start_time,
168  double benchmark_duration, const BenchmarkOptions& options);
169 
170  void shiftConstraintsByOffset(moveit_msgs::msg::Constraints& constraints, const std::vector<double>& offset);
171 
173  bool pipelinesExist(const std::map<std::string, std::vector<std::string>>& planners);
174 
176  bool loadPlanningScene(const std::string& scene_name, moveit_msgs::msg::PlanningScene& scene_msg);
177 
179  bool loadStates(const std::string& regex, std::vector<StartState>& start_states);
180 
182  bool loadPathConstraints(const std::string& regex, std::vector<PathConstraints>& constraints);
183 
185  bool loadTrajectoryConstraints(const std::string& regex, std::vector<TrajectoryConstraints>& constraints);
186 
188  bool loadQueries(const std::string& regex, const std::string& scene_name, std::vector<BenchmarkRequest>& queries);
189 
191  void createRequestCombinations(const BenchmarkRequest& benchmark_request, const std::vector<StartState>& start_states,
192  const std::vector<PathConstraints>& path_constraints,
193  std::vector<BenchmarkRequest>& combos);
194 
197 
198  std::shared_ptr<planning_scene_monitor::PlanningSceneMonitor> planning_scene_monitor_;
199  std::shared_ptr<moveit_warehouse::PlanningSceneStorage> planning_scene_storage_;
200  std::shared_ptr<moveit_warehouse::PlanningSceneWorldStorage> planning_scene_world_storage_;
201  std::shared_ptr<moveit_warehouse::RobotStateStorage> robot_state_storage_;
202  std::shared_ptr<moveit_warehouse::ConstraintsStorage> constraints_storage_;
203  std::shared_ptr<moveit_warehouse::TrajectoryConstraintsStorage> trajectory_constraints_storage_;
204 
205  rclcpp::Node::SharedPtr node_;
206  warehouse_ros::DatabaseLoader db_loader_;
207  planning_scene::PlanningScenePtr planning_scene_;
208  std::shared_ptr<moveit_cpp::MoveItCpp> moveit_cpp_;
209 
210  std::vector<PlannerBenchmarkData> benchmark_data_;
211 
212  std::vector<PreRunEventFunction> pre_event_functions_;
213  std::vector<PostRunEventFunction> post_event_functions_;
214  std::vector<PlannerStartEventFunction> planner_start_functions_;
215  std::vector<PlannerCompletionEventFunction> planner_completion_functions_;
216  std::vector<QueryStartEventFunction> query_start_functions_;
217  std::vector<QueryCompletionEventFunction> query_end_functions_;
218 };
219 } // namespace moveit_ros_benchmarks
bool loadPlanningScene(const std::string &scene_name, moveit_msgs::msg::PlanningScene &scene_msg)
Load the planning scene with the given name from the warehouse.
void computeAveragePathSimilarities(PlannerBenchmarkData &planner_data, const std::vector< planning_interface::MotionPlanDetailedResponse > &responses, const std::vector< bool > &solved)
bool loadQueries(const std::string &regex, const std::string &scene_name, std::vector< BenchmarkRequest > &queries)
Load all motion plan requests matching the given regular expression from the warehouse.
void createRequestCombinations(const BenchmarkRequest &benchmark_request, const std::vector< StartState > &start_states, const std::vector< PathConstraints > &path_constraints, std::vector< BenchmarkRequest > &combos)
Duplicate the given benchmark request for all combinations of start states and path constraints.
std::vector< PlannerRunData > PlannerBenchmarkData
Structure to hold information for a single planner's benchmark data.
planning_scene::PlanningScenePtr planning_scene_
std::vector< PlannerStartEventFunction > planner_start_functions_
warehouse_ros::DatabaseLoader db_loader_
bool computeTrajectoryDistance(const robot_trajectory::RobotTrajectory &traj_first, const robot_trajectory::RobotTrajectory &traj_second, double &result_distance)
void addQueryStartEvent(const QueryStartEventFunction &func)
std::shared_ptr< moveit_warehouse::ConstraintsStorage > constraints_storage_
std::shared_ptr< moveit_warehouse::PlanningSceneStorage > planning_scene_storage_
std::function< void(const moveit_msgs::msg::MotionPlanRequest &request, PlannerBenchmarkData &benchmark_data)> PlannerCompletionEventFunction
std::vector< QueryCompletionEventFunction > query_end_functions_
std::shared_ptr< moveit_warehouse::TrajectoryConstraintsStorage > trajectory_constraints_storage_
std::function< void(const moveit_msgs::msg::MotionPlanRequest &request, planning_scene::PlanningScenePtr)> QueryCompletionEventFunction
Definition of a query-end benchmark event function. Invoked after a query has finished benchmarking.
std::shared_ptr< moveit_cpp::MoveItCpp > moveit_cpp_
virtual void collectMetrics(PlannerRunData &metrics, const planning_interface::MotionPlanDetailedResponse &motion_plan_response, bool solved, double total_time)
std::vector< QueryStartEventFunction > query_start_functions_
bool loadPathConstraints(const std::string &regex, std::vector< PathConstraints > &constraints)
Load all constraints matching the given regular expression from the warehouse.
std::vector< PreRunEventFunction > pre_event_functions_
void runBenchmark(moveit_msgs::msg::MotionPlanRequest request, const BenchmarkOptions &options)
Execute the given motion plan request on the set of planners for the set number of runs.
void addPreRunEvent(const PreRunEventFunction &func)
BenchmarkExecutor(const rclcpp::Node::SharedPtr &node, const std::string &robot_description_param="robot_description")
virtual bool runBenchmarks(const BenchmarkOptions &options)
std::vector< PlannerBenchmarkData > benchmark_data_
virtual bool loadBenchmarkQueryData(const BenchmarkOptions &options, moveit_msgs::msg::PlanningScene &scene_msg, std::vector< StartState > &start_states, std::vector< PathConstraints > &path_constraints, std::vector< PathConstraints > &goal_constraints, std::vector< TrajectoryConstraints > &traj_constraints, std::vector< BenchmarkRequest > &queries)
Initialize benchmark query data from start states and constraints.
std::vector< PostRunEventFunction > post_event_functions_
virtual bool initializeBenchmarks(const BenchmarkOptions &options, moveit_msgs::msg::PlanningScene &scene_msg, std::vector< BenchmarkRequest > &queries)
void addPlannerCompletionEvent(const PlannerCompletionEventFunction &func)
std::shared_ptr< planning_scene_monitor::PlanningSceneMonitor > planning_scene_monitor_
void addPlannerStartEvent(const PlannerStartEventFunction &func)
void addQueryCompletionEvent(const QueryCompletionEventFunction &func)
bool loadStates(const std::string &regex, std::vector< StartState > &start_states)
Load all states matching the given regular expression from the warehouse.
bool pipelinesExist(const std::map< std::string, std::vector< std::string >> &planners)
Check that the desired planning pipelines exist.
std::function< void(const moveit_msgs::msg::MotionPlanRequest &request, const planning_interface::MotionPlanDetailedResponse &response, PlannerRunData &run_data)> PostRunEventFunction
Definition of a post-run benchmark event function. Invoked immediately after each planner calls solve...
std::function< void(moveit_msgs::msg::MotionPlanRequest &request)> PreRunEventFunction
Definition of a pre-run benchmark event function. Invoked immediately before each planner calls solve...
std::vector< PlannerCompletionEventFunction > planner_completion_functions_
std::shared_ptr< moveit_warehouse::RobotStateStorage > robot_state_storage_
std::function< void(const moveit_msgs::msg::MotionPlanRequest &request, planning_scene::PlanningScenePtr)> QueryStartEventFunction
Definition of a query-start benchmark event function. Invoked before a new query is benchmarked.
virtual void writeOutput(const BenchmarkRequest &benchmark_request, const std::string &start_time, double benchmark_duration, const BenchmarkOptions &options)
bool initialize(const std::vector< std::string > &plugin_classes)
std::shared_ptr< moveit_warehouse::PlanningSceneWorldStorage > planning_scene_world_storage_
std::function< void(const moveit_msgs::msg::MotionPlanRequest &request, PlannerBenchmarkData &benchmark_data)> PlannerStartEventFunction
bool loadTrajectoryConstraints(const std::string &regex, std::vector< TrajectoryConstraints > &constraints)
Load all trajectory constraints from the warehouse that match the given regular expression.
void addPostRunEvent(const PostRunEventFunction &func)
void shiftConstraintsByOffset(moveit_msgs::msg::Constraints &constraints, const std::vector< double > &offset)
std::map< std::string, std::string > PlannerRunData
Structure to hold information for a single run of a planner.
Maintain a sequence of waypoints and the time durations between these waypoints.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
std::vector< moveit_msgs::msg::Constraints > constraints
Options to configure a benchmark experiment. The configuration is provided via ROS2 parameters.