moveit2
The MoveIt Motion Planning Framework for ROS 2.
BenchmarkOptions.cpp
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 
38 
39 using namespace moveit_ros_benchmarks;
40 
41 static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.ros.benchmarks.BenchmarkOptions");
42 
44 {
45 }
46 
47 BenchmarkOptions::BenchmarkOptions(const rclcpp::Node::SharedPtr& node)
48 {
50 }
51 
53 
54 // void BenchmarkOptions::setNamespace(const std::string& ros_namespace)
55 // {
56 // readBenchmarkOptions(ros_namespace);
57 // }
58 
59 void BenchmarkOptions::readBenchmarkOptions(const rclcpp::Node::SharedPtr& node)
60 {
61  if (node->has_parameter("benchmark_config.parameters.name"))
62  {
65  readPlannerConfigs(node);
66  }
67  else
68  {
69  RCLCPP_WARN(LOGGER, "No benchmark_config found on param server");
70  }
71 }
72 
73 const std::string& BenchmarkOptions::getHostName() const
74 {
75  return hostname_;
76 }
77 
79 {
80  return port_;
81 }
82 
83 const std::string& BenchmarkOptions::getSceneName() const
84 {
85  return scene_name_;
86 }
87 
89 {
90  return runs_;
91 }
92 
94 {
95  return timeout_;
96 }
97 
98 const std::string& BenchmarkOptions::getBenchmarkName() const
99 {
100  return benchmark_name_;
101 }
102 
103 const std::string& BenchmarkOptions::getGroupName() const
104 {
105  return group_name_;
106 }
107 
108 const std::string& BenchmarkOptions::getOutputDirectory() const
109 {
110  return output_directory_;
111 }
112 
113 const std::string& BenchmarkOptions::getQueryRegex() const
114 {
115  return query_regex_;
116 }
117 
118 const std::string& BenchmarkOptions::getStartStateRegex() const
119 {
120  return start_state_regex_;
121 }
122 
124 {
125  return goal_constraint_regex_;
126 }
127 
129 {
130  return path_constraint_regex_;
131 }
132 
134 {
136 }
137 
138 const std::vector<std::string>& BenchmarkOptions::getPredefinedPoses() const
139 {
140  return predefined_poses_;
141 }
142 
144 {
146 }
147 
148 void BenchmarkOptions::getGoalOffsets(std::vector<double>& offsets) const
149 {
150  offsets.resize(6);
151  memcpy(&offsets[0], goal_offsets, 6 * sizeof(double));
152 }
153 
154 const std::map<std::string, std::vector<std::string>>& BenchmarkOptions::getPlanningPipelineConfigurations() const
155 {
156  return planning_pipelines_;
157 }
158 
159 void BenchmarkOptions::getPlanningPipelineNames(std::vector<std::string>& planning_pipeline_names) const
160 {
161  planning_pipeline_names.clear();
162  for (const std::pair<const std::string, std::vector<std::string>>& planning_pipeline : planning_pipelines_)
163  planning_pipeline_names.push_back(planning_pipeline.first);
164 }
165 
166 const std::string& BenchmarkOptions::getWorkspaceFrameID() const
167 {
168  return workspace_.header.frame_id;
169 }
170 
171 const moveit_msgs::msg::WorkspaceParameters& BenchmarkOptions::getWorkspaceParameters() const
172 {
173  return workspace_;
174 }
175 
176 void BenchmarkOptions::readWarehouseOptions(const rclcpp::Node::SharedPtr& node)
177 {
178  node->get_parameter_or(std::string("benchmark_config.warehouse.host"), hostname_, std::string("127.0.0.1"));
179  node->get_parameter_or(std::string("benchmark_config.warehouse.port"), port_, 33829);
180 
181  if (!node->get_parameter("benchmark_config.warehouse.scene_name", scene_name_))
182  RCLCPP_WARN(LOGGER, "Benchmark scene_name NOT specified");
183 
184  RCLCPP_INFO(LOGGER, "Benchmark host: %s", hostname_.c_str());
185  RCLCPP_INFO(LOGGER, "Benchmark port: %d", port_);
186  RCLCPP_INFO(LOGGER, "Benchmark scene: %s", scene_name_.c_str());
187 }
188 
189 void BenchmarkOptions::readBenchmarkParameters(const rclcpp::Node::SharedPtr& node)
190 {
191  node->get_parameter_or(std::string("benchmark_config.parameters.name"), benchmark_name_, std::string(""));
192  node->get_parameter_or(std::string("benchmark_config.parameters.runs"), runs_, 10);
193  node->get_parameter_or(std::string("benchmark_config.parameters.timeout"), timeout_, 10.0);
194  node->get_parameter_or(std::string("benchmark_config.parameters.output_directory"), output_directory_,
195  std::string(""));
196  node->get_parameter_or(std::string("benchmark_config.parameters.queries"), query_regex_, std::string(".*"));
197  node->get_parameter_or(std::string("benchmark_config.parameters.start_states"), start_state_regex_, std::string(""));
198  node->get_parameter_or(std::string("benchmark_config.parameters.goal_constraints"), goal_constraint_regex_,
199  std::string(""));
200  node->get_parameter_or(std::string("benchmark_config.parameters.path_constraints"), path_constraint_regex_,
201  std::string(""));
202  node->get_parameter_or(std::string("benchmark_config.parameters.trajectory_constraints"),
203  trajectory_constraint_regex_, std::string(""));
204  node->get_parameter_or(std::string("benchmark_config.parameters.predefined_poses"), predefined_poses_, {});
205  node->get_parameter_or(std::string("benchmark_config.parameters.predefined_poses_group"), predefined_poses_group_,
206  std::string(""));
207 
208  if (!node->get_parameter(std::string("benchmark_config.parameters.group"), group_name_))
209  RCLCPP_INFO(LOGGER, "Benchmark group NOT specified");
210 
211  if (node->has_parameter("benchmark_config.parameters.workspace"))
213 
214  // Reading in goal_offset (or defaulting to zero)
215  node->get_parameter_or(std::string("benchmark_config.parameters.goal_offset.x"), goal_offsets[0], 0.0);
216  node->get_parameter_or(std::string("benchmark_config.parameters.goal_offset.y"), goal_offsets[1], 0.0);
217  node->get_parameter_or(std::string("benchmark_config.parameters.goal_offset.z"), goal_offsets[2], 0.0);
218  node->get_parameter_or(std::string("benchmark_config.parameters.goal_offset.roll"), goal_offsets[3], 0.0);
219  node->get_parameter_or(std::string("benchmark_config.parameters.goal_offset.pitch"), goal_offsets[4], 0.0);
220  node->get_parameter_or(std::string("benchmark_config.parameters.goal_offset.yaw"), goal_offsets[5], 0.0);
221 
222  RCLCPP_INFO(LOGGER, "Benchmark name: '%s'", benchmark_name_.c_str());
223  RCLCPP_INFO(LOGGER, "Benchmark #runs: %d", runs_);
224  RCLCPP_INFO(LOGGER, "Benchmark timeout: %f secs", timeout_);
225  RCLCPP_INFO(LOGGER, "Benchmark group: %s", group_name_.c_str());
226  RCLCPP_INFO(LOGGER, "Benchmark query regex: '%s'", query_regex_.c_str());
227  RCLCPP_INFO(LOGGER, "Benchmark start state regex: '%s':", start_state_regex_.c_str());
228  RCLCPP_INFO(LOGGER, "Benchmark goal constraint regex: '%s':", goal_constraint_regex_.c_str());
229  RCLCPP_INFO(LOGGER, "Benchmark path constraint regex: '%s':", path_constraint_regex_.c_str());
230  RCLCPP_INFO(LOGGER, "Benchmark goal offsets (%f %f %f, %f %f %f)", goal_offsets[0], goal_offsets[1], goal_offsets[2],
232  RCLCPP_INFO(LOGGER, "Benchmark output directory: %s", output_directory_.c_str());
233  RCLCPP_INFO_STREAM(LOGGER, "Benchmark workspace: min_corner: ["
234  << workspace_.min_corner.x << ", " << workspace_.min_corner.y << ", "
235  << workspace_.min_corner.z << "], "
236  << "max_corner: [" << workspace_.max_corner.x << ", " << workspace_.max_corner.y
237  << ", " << workspace_.max_corner.z << "]");
238 }
239 
240 void BenchmarkOptions::readWorkspaceParameters(const rclcpp::Node::SharedPtr& node)
241 {
242  // Make sure all params exist
243  if (!node->get_parameter("benchmark_config.parameters.workspace.frame_id", workspace_.header.frame_id))
244  RCLCPP_WARN(LOGGER, "Workspace frame_id not specified in benchmark config");
245 
246  node->get_parameter_or(std::string("benchmark_config.parameters.workspace.min_corner.x"), workspace_.min_corner.x,
247  0.0);
248  node->get_parameter_or(std::string("benchmark_config.parameters.workspace.min_corner.y"), workspace_.min_corner.y,
249  0.0);
250  node->get_parameter_or(std::string("benchmark_config.parameters.workspace.min_corner.z"), workspace_.min_corner.z,
251  0.0);
252 
253  node->get_parameter_or(std::string("benchmark_config.parameters.workspace.max_corner.x"), workspace_.max_corner.x,
254  0.0);
255  node->get_parameter_or(std::string("benchmark_config.parameters.workspace.max_corner.y"), workspace_.max_corner.y,
256  0.0);
257  node->get_parameter_or(std::string("benchmark_config.parameters.workspace.max_corner.z"), workspace_.max_corner.z,
258  0.0);
259 
260  workspace_.header.stamp = rclcpp::Clock().now();
261 }
262 
263 void BenchmarkOptions::readPlannerConfigs(const rclcpp::Node::SharedPtr& node)
264 {
265  planning_pipelines_.clear();
266 
267  const std::string np = "benchmark_config.planning_pipelines";
268  std::vector<std::string> pipelines;
269  if (!node->get_parameter(np + ".pipelines", pipelines))
270  {
271  RCLCPP_ERROR(LOGGER, "Fail to get the parameter in `%s` namespace.", (np + ".pipelines").c_str());
272  return;
273  }
274 
275  for (const std::string& pipeline : pipelines)
276  {
277  std::string pipeline_name;
278  const std::string pipeline_parameter_name = std::string(np).append(".").append(pipeline).append(".name");
279  if (!node->get_parameter(pipeline_parameter_name, pipeline_name))
280  {
281  RCLCPP_ERROR(LOGGER, "Fail to get the parameter in `%s` namespace.", pipeline_parameter_name.c_str());
282  return;
283  }
284 
285  RCLCPP_INFO(LOGGER, "Reading in planner names for planning pipeline '%s'", pipeline_name.c_str());
286 
287  std::vector<std::string> planners;
288  if (!node->get_parameter(pipeline_parameter_name, planners))
289  {
290  RCLCPP_ERROR(LOGGER, "Fail to get the parameter in `%s` namespace.", pipeline_parameter_name.c_str());
291  return;
292  }
293 
294  for (const std::string& planner : planners)
295  RCLCPP_INFO(LOGGER, " %s", planner.c_str());
296 
297  planning_pipelines_[pipeline_name] = planners;
298  }
299 }
const moveit_msgs::msg::WorkspaceParameters & getWorkspaceParameters() const
const std::string & getPathConstraintRegex() const
Get the regex expression for matching the names of all path constraints to plan with.
const std::map< std::string, std::vector< std::string > > & getPlanningPipelineConfigurations() const
Get all planning pipeline names mapped to their parameter configuration.
std::vector< std::string > predefined_poses_
const std::string & getBenchmarkName() const
Get the reference name of the benchmark.
int getNumRuns() const
Get the specified number of benchmark query runs.
double getTimeout() const
Get the maximum timeout per planning attempt.
const std::string & getHostName() const
Set the ROS namespace the node handle should use for parameter lookup.
void readWorkspaceParameters(const rclcpp::Node::SharedPtr &node)
void readBenchmarkParameters(const rclcpp::Node::SharedPtr &node)
void readBenchmarkOptions(const rclcpp::Node::SharedPtr &node)
moveit_msgs::msg::WorkspaceParameters workspace_
void getPlanningPipelineNames(std::vector< std::string > &planning_pipeline_names) const
Get all planning pipeline names.
int getPort() const
Get the port of the warehouse database host server.
void getGoalOffsets(std::vector< double > &offsets) const
Get the constant position/orientation offset to be used for shifting all goal constraints.
const std::string & getQueryRegex() const
Get the regex expression for matching the names of all queries to run.
const std::vector< std::string > & getPredefinedPoses() const
Get the names of all predefined poses to consider for planning.
std::map< std::string, std::vector< std::string > > planning_pipelines_
planner configurations
const std::string & getGroupName() const
Get the name of the planning group to run the benchmark with.
const std::string & getWorkspaceFrameID() const
const std::string & getPredefinedPosesGroup() const
Get the name of the planning group for which the predefined poses are defined.
const std::string & getGoalConstraintRegex() const
Get the regex expression for matching the names of all goal constraints to plan to.
void readWarehouseOptions(const rclcpp::Node::SharedPtr &node)
const std::string & getStartStateRegex() const
Get the regex expression for matching the names of all start states to plan from.
const std::string & getSceneName() const
Get the reference name of the planning scene stored inside the warehouse database.
void readPlannerConfigs(const rclcpp::Node::SharedPtr &node)
std::string hostname_
warehouse parameters
const std::string & getOutputDirectory() const
Get the target directory for the generated benchmark result data.
const std::string & getTrajectoryConstraintRegex() const
Get the regex expression for matching the names of all trajectory constraints to plan with.
Planning pipeline.
const rclcpp::Logger LOGGER
Definition: async_test.h:31