@@ -208,42 +208,22 @@ class Demo
208
208
return true ;
209
209
}
210
210
211
- // / \brief Set goal state for next planning attempt based on query loaded from the database
212
- void setQueryGoal (moveit_msgs::msg::MotionPlanRequest const & motion_plan_request)
211
+ struct PipelineConfig
213
212
{
214
- // Set goal state
215
- if (!motion_plan_request.goal_constraints .empty ())
216
- {
217
- // for (auto constraint : motion_plan_request.goal_constraints)
218
- // {
219
- // for (auto joint_constraint : constraint.joint_constraints)
220
- // {
221
- // RCLCPP_INFO_STREAM(LOGGER, "position: " << joint_constraint.position << "\n"
222
- // << "tolerance_above: " << joint_constraint.tolerance_above << "\n"
223
- // << "tolerance_below: " << joint_constraint.tolerance_below << "\n"
224
- // << "weight: " << joint_constraint.weight << "\n");
225
- // }
226
- // for (auto position_constraint : constraint.position_constraints)
227
- // {
228
- // RCLCPP_WARN(LOGGER, "Goal constraints contain position constrains, please use joint constraints only in this "
229
- // "example.");
230
- // }
231
- // }
232
- planning_component_->setGoal (motion_plan_request.goal_constraints );
233
- }
234
- else
235
- {
236
- RCLCPP_ERROR (LOGGER, " Planning query request does not contain any goal constraints" );
237
- }
238
- }
213
+ std::string planning_pipeline;
214
+ std::string planner_id;
215
+ bool use_cost_function;
216
+ };
239
217
240
218
// / \brief Request a motion plan based on the assumption that a goal is set and print debug information.
241
- void planAndVisualize (std::vector<std::pair<std::string, std::string>> pipeline_planner_pairs ,
219
+ void planAndVisualize (std::vector<PipelineConfig> pipeline_configs ,
242
220
moveit_msgs::msg::MotionPlanRequest const & motion_plan_request)
243
221
{
244
222
visual_tools_.deleteAllMarkers ();
245
223
visual_tools_.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
246
224
225
+ // Set goal state
226
+ planning_component_->setGoal (motion_plan_request.goal_constraints );
247
227
// Set start state as current state
248
228
planning_component_->setStartStateToCurrentState ();
249
229
@@ -259,14 +239,6 @@ class Demo
259
239
}();
260
240
261
241
auto group_name = motion_plan_request.group_name ;
262
- // Set cost function
263
- planning_component_->setStateCostFunction (
264
- [robot_start_state, group_name, planning_scene](const Eigen::VectorXd& state_vector) mutable {
265
- // rviz_visual_tools::MEDIUM); this->getVisualTools().trigger();
266
- auto clearance_cost_fn =
267
- moveit::cost_functions::getClearanceCostFn (*robot_start_state, group_name, planning_scene);
268
- return clearance_cost_fn (state_vector);
269
- });
270
242
271
243
moveit_cpp::PlanningComponent::PlanRequestParameters plan_request_parameters;
272
244
plan_request_parameters.load (node_);
@@ -280,11 +252,28 @@ class Demo
280
252
<< " max_acceleration_scaling_factor: " << plan_request_parameters.max_acceleration_scaling_factor );
281
253
282
254
std::vector<planning_interface::MotionPlanResponse> solutions;
283
- solutions.reserve (pipeline_planner_pairs .size ());
284
- for (auto const & pipeline_planner_pair : pipeline_planner_pairs )
255
+ solutions.reserve (pipeline_configs .size ());
256
+ for (auto const & pipeline_config : pipeline_configs )
285
257
{
286
- plan_request_parameters.planning_pipeline = pipeline_planner_pair.first ;
287
- plan_request_parameters.planner_id = pipeline_planner_pair.second ;
258
+ plan_request_parameters.planning_pipeline = pipeline_config.planning_pipeline ;
259
+ plan_request_parameters.planner_id = pipeline_config.planner_id ;
260
+
261
+ // Set cost function
262
+ if (pipeline_config.use_cost_function )
263
+ {
264
+ planning_component_->setStateCostFunction (
265
+ [robot_start_state, group_name, planning_scene](const Eigen::VectorXd& state_vector) mutable {
266
+ // rviz_visual_tools::MEDIUM); this->getVisualTools().trigger();
267
+ auto clearance_cost_fn =
268
+ moveit::cost_functions::getClearanceCostFn (*robot_start_state, group_name, planning_scene);
269
+ return clearance_cost_fn (state_vector);
270
+ });
271
+ }
272
+ else
273
+ {
274
+ planning_component_->setStateCostFunction (nullptr );
275
+ }
276
+
288
277
solutions.push_back (planning_component_->plan (plan_request_parameters, planning_scene));
289
278
}
290
279
@@ -297,7 +286,8 @@ class Demo
297
286
if (plan_solution.trajectory )
298
287
{
299
288
RCLCPP_INFO_STREAM (LOGGER, plan_solution.planner_id .c_str ()
300
- << " : " << colorToString (rviz_visual_tools::Colors (color_index)));
289
+ << " , " << std::to_string (plan_solution.use_cost_function ) << " : "
290
+ << colorToString (rviz_visual_tools::Colors (color_index)));
301
291
// Visualize the trajectory in Rviz
302
292
visual_tools_.publishTrajectoryLine (plan_solution.trajectory , joint_model_group_ptr,
303
293
rviz_visual_tools::Colors (color_index));
@@ -350,8 +340,9 @@ int main(int argc, char** argv)
350
340
RCLCPP_INFO (LOGGER, " Starting Cost Function Tutorial..." );
351
341
for (auto const & motion_plan_req : demo.getMotionPlanRequests ())
352
342
{
353
- demo.setQueryGoal (motion_plan_req);
354
- demo.planAndVisualize ({ { " ompl" , " RRTConnectkConfigDefault" }, { " stomp" , " stomp" } }, motion_plan_req);
343
+ demo.planAndVisualize (
344
+ { { " ompl" , " RRTConnectkConfigDefault" , false }, { " stomp" , " stomp" , false }, { " stomp" , " stomp" , true } },
345
+ motion_plan_req);
355
346
}
356
347
357
348
demo.getVisualTools ().prompt (" Press 'next' in the RvizVisualToolsGui window to finish the demo" );
0 commit comments