@@ -103,7 +103,7 @@ class Demo
103
103
104
104
Eigen::Isometry3d text_pose = Eigen::Isometry3d::Identity ();
105
105
text_pose.translation ().z () = 1.75 ;
106
- visual_tools_.publishText (text_pose, " Parallel Planning Tutorial" , rvt::WHITE, rvt::XLARGE);
106
+ visual_tools_.publishText (text_pose, " Cost Function Tutorial" , rvt::WHITE, rvt::XLARGE);
107
107
visual_tools_.trigger ();
108
108
}
109
109
@@ -188,64 +188,48 @@ class Demo
188
188
RCLCPP_INFO (LOGGER, " Loaded planning scene successfully" );
189
189
190
190
// Get planning scene query
191
- moveit_warehouse::MotionPlanRequestWithMetadata planning_query;
192
- std::string query_name = scene_name + " _query" ;
193
- try
191
+ for (int index = 0 ; index < 10 ; index++)
194
192
{
195
- planning_scene_storage->getPlanningQuery (planning_query, scene_name, query_name);
196
- }
197
- catch (std::exception& ex)
198
- {
199
- RCLCPP_ERROR (LOGGER, " Error loading motion planning query '%s': %s" , query_name.c_str (), ex.what ());
200
- }
193
+ moveit_warehouse::MotionPlanRequestWithMetadata planning_query;
194
+ std::string query_name = " kitchen_panda_scene_sensed" + std::to_string (index) + " _query" ;
195
+ try
196
+ {
197
+ planning_scene_storage->getPlanningQuery (planning_query, scene_name, query_name);
198
+ }
199
+ catch (std::exception& ex)
200
+ {
201
+ RCLCPP_ERROR (LOGGER, " Error loading motion planning query '%s': %s" , query_name.c_str (), ex.what ());
202
+ }
201
203
202
- planning_query_request_ = static_cast <moveit_msgs::msg::MotionPlanRequest>(*planning_query);
204
+ motion_plan_requests.push_back (static_cast <moveit_msgs::msg::MotionPlanRequest>(*planning_query));
205
+ }
203
206
visual_tools_.prompt (" Press 'next' in the RvizVisualToolsGui window to start the demo" );
204
207
visual_tools_.trigger ();
205
208
return true ;
206
209
}
207
210
208
- // / \brief Set joint goal state for next planning attempt
209
- // / \param [in] panda_jointN Goal value for the Nth joint [rad]
210
- void setJointGoal (double const panda_joint1, double const panda_joint2, double const panda_joint3,
211
- double const panda_joint4, double const panda_joint5, double const panda_joint6,
212
- double const panda_joint7)
213
- {
214
- auto robot_goal_state = planning_component_->getStartState ();
215
- robot_goal_state->setJointPositions (" panda_joint1" , &panda_joint1);
216
- robot_goal_state->setJointPositions (" panda_joint2" , &panda_joint2);
217
- robot_goal_state->setJointPositions (" panda_joint3" , &panda_joint3);
218
- robot_goal_state->setJointPositions (" panda_joint4" , &panda_joint4);
219
- robot_goal_state->setJointPositions (" panda_joint5" , &panda_joint5);
220
- robot_goal_state->setJointPositions (" panda_joint6" , &panda_joint6);
221
- robot_goal_state->setJointPositions (" panda_joint7" , &panda_joint7);
222
-
223
- // Set goal state
224
- planning_component_->setGoal (*robot_goal_state);
225
- }
226
-
227
211
// / \brief Set goal state for next planning attempt based on query loaded from the database
228
- void setQueryGoal ()
212
+ void setQueryGoal (moveit_msgs::msg::MotionPlanRequest const & motion_plan_request )
229
213
{
230
214
// Set goal state
231
- if (!planning_query_request_ .goal_constraints .empty ())
215
+ if (!motion_plan_request .goal_constraints .empty ())
232
216
{
233
- for (auto constraint : planning_query_request_ .goal_constraints )
234
- {
235
- for (auto joint_constraint : constraint.joint_constraints )
236
- {
237
- RCLCPP_INFO_STREAM (LOGGER, " position: " << joint_constraint.position << " \n "
238
- << " tolerance_above: " << joint_constraint.tolerance_above << " \n "
239
- << " tolerance_below: " << joint_constraint.tolerance_below << " \n "
240
- << " weight: " << joint_constraint.weight << " \n " );
241
- }
242
- for (auto position_constraint : constraint.position_constraints )
243
- {
244
- RCLCPP_WARN (LOGGER, " Goal constraints contain position constrains, please use joint constraints only in this "
245
- " example." );
246
- }
247
- }
248
- planning_component_->setGoal (planning_query_request_ .goal_constraints );
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 );
249
233
}
250
234
else
251
235
{
@@ -254,7 +238,8 @@ class Demo
254
238
}
255
239
256
240
// / \brief Request a motion plan based on the assumption that a goal is set and print debug information.
257
- void planAndVisualize (std::vector<std::pair<std::string, std::string>> pipeline_planner_pairs)
241
+ void planAndVisualize (std::vector<std::pair<std::string, std::string>> pipeline_planner_pairs,
242
+ moveit_msgs::msg::MotionPlanRequest const & motion_plan_request)
258
243
{
259
244
visual_tools_.deleteAllMarkers ();
260
245
visual_tools_.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
@@ -273,13 +258,10 @@ class Demo
273
258
return planning_scene::PlanningScene::clone (ls);
274
259
}();
275
260
276
- auto group_name = planning_query_request_ .group_name ;
261
+ auto group_name = motion_plan_request .group_name ;
277
262
// Set cost function
278
263
planning_component_->setStateCostFunction (
279
264
[robot_start_state, group_name, planning_scene](const Eigen::VectorXd& state_vector) mutable {
280
- // Publish robot state
281
- // auto const ee_tip = robot_state.getJointModelGroup(PLANNING_GROUP)->getOnlyOneEndEffectorTip();
282
- // this->getVisualTools().publishSphere(robot_state.getGlobalLinkTransform(ee_tip), rviz_visual_tools::GREEN,
283
265
// rviz_visual_tools::MEDIUM); this->getVisualTools().trigger();
284
266
auto clearance_cost_fn =
285
267
moveit::cost_functions::getClearanceCostFn (*robot_start_state, group_name, planning_scene);
@@ -288,7 +270,7 @@ class Demo
288
270
289
271
moveit_cpp::PlanningComponent::PlanRequestParameters plan_request_parameters;
290
272
plan_request_parameters.load (node_);
291
- RCLCPP_DEBUG_STREAM (
273
+ RCLCPP_INFO_STREAM (
292
274
LOGGER, " Default plan request parameters loaded with --"
293
275
<< " planning_pipeline: " << plan_request_parameters.planning_pipeline << ' ,'
294
276
<< " planner_id: " << plan_request_parameters.planner_id << ' ,'
@@ -297,17 +279,6 @@ class Demo
297
279
<< " max_velocity_scaling_factor: " << plan_request_parameters.max_velocity_scaling_factor << ' ,'
298
280
<< " max_acceleration_scaling_factor: " << plan_request_parameters.max_acceleration_scaling_factor );
299
281
300
- // planning_component_->setStateCostFunction(
301
- // [robot_start_state, group_name, planning_scene](const std::vector<double>& state_vector) mutable {
302
- // // Publish robot state
303
- // // auto const ee_tip = robot_state.getJointModelGroup(PLANNING_GROUP)->getOnlyOneEndEffectorTip();
304
- // // this->getVisualTools().publishSphere(robot_state.getGlobalLinkTransform(ee_tip), rviz_visual_tools::GREEN,
305
- // // rviz_visual_tools::MEDIUM); this->getVisualTools().trigger();
306
- // auto clearance_cost_fn =
307
- // moveit::cost_functions::getClearanceCostFn(*robot_start_state, group_name, planning_scene);
308
- // return clearance_cost_fn(state_vector);
309
- // });
310
-
311
282
std::vector<planning_interface::MotionPlanResponse> solutions;
312
283
solutions.reserve (pipeline_planner_pairs.size ());
313
284
for (auto const & pipeline_planner_pair : pipeline_planner_pairs)
@@ -321,18 +292,18 @@ class Demo
321
292
auto robot_model_ptr = moveit_cpp_->getRobotModel ();
322
293
auto joint_model_group_ptr = robot_model_ptr->getJointModelGroup (PLANNING_GROUP);
323
294
// Check if PlanningComponents succeeded in finding the plan
324
- // for (auto const& plan_solution : solutions)
325
- // {
326
- // if (plan_solution.trajectory)
327
- // {
328
- // RCLCPP_INFO_STREAM(LOGGER, plan_solution.planner_id.c_str()
329
- // << ": " << colorToString(rviz_visual_tools::Colors(color_index)));
330
- // // Visualize the trajectory in Rviz
331
- // visual_tools_.publishTrajectoryLine(plan_solution.trajectory, joint_model_group_ptr,
332
- // rviz_visual_tools::Colors(color_index));
333
- // color_index++;
334
- // }
335
- // }
295
+ for (auto const & plan_solution : solutions)
296
+ {
297
+ if (plan_solution.trajectory )
298
+ {
299
+ RCLCPP_INFO_STREAM (LOGGER, plan_solution.planner_id .c_str ()
300
+ << " : " << colorToString (rviz_visual_tools::Colors (color_index)));
301
+ // Visualize the trajectory in Rviz
302
+ visual_tools_.publishTrajectoryLine (plan_solution.trajectory , joint_model_group_ptr,
303
+ rviz_visual_tools::Colors (color_index));
304
+ color_index++;
305
+ }
306
+ }
336
307
visual_tools_.trigger ();
337
308
}
338
309
@@ -341,12 +312,17 @@ class Demo
341
312
return visual_tools_;
342
313
}
343
314
315
+ std::vector<moveit_msgs::msg::MotionPlanRequest> getMotionPlanRequests ()
316
+ {
317
+ return motion_plan_requests;
318
+ }
319
+
344
320
private:
345
321
std::shared_ptr<rclcpp::Node> node_;
346
322
std::shared_ptr<moveit_cpp::MoveItCpp> moveit_cpp_;
347
323
std::shared_ptr<moveit_cpp::PlanningComponent> planning_component_;
348
324
moveit_visual_tools::MoveItVisualTools visual_tools_;
349
- moveit_msgs::msg::MotionPlanRequest planning_query_request_ ;
325
+ std::vector< moveit_msgs::msg::MotionPlanRequest> motion_plan_requests ;
350
326
};
351
327
} // namespace plannner_cost_fn_example
352
328
@@ -371,14 +347,12 @@ int main(int argc, char** argv)
371
347
return 0 ;
372
348
}
373
349
374
- RCLCPP_INFO (LOGGER, " Starting MoveIt Tutorials..." );
375
-
376
- // Experiment - Long motion with collisions, CHOMP and Pilz are likely to fail here due to the difficulty of the planning problem
377
- RCLCPP_INFO (LOGGER, " Experiment - Long motion with collisions" );
378
- demo.setQueryGoal ();
379
-
380
- demo.planAndVisualize (
381
- { { " ompl_stomp" , " RRTConnectkConfigDefault" }, /* { "ompl", "RRTstarkConfigDefault" }, { "stomp", "stomp" }*/ });
350
+ RCLCPP_INFO (LOGGER, " Starting Cost Function Tutorial..." );
351
+ for (auto const & motion_plan_req : demo.getMotionPlanRequests ())
352
+ {
353
+ demo.setQueryGoal (motion_plan_req);
354
+ demo.planAndVisualize ({ { " ompl" , " RRTConnectkConfigDefault" }, { " stomp" , " stomp" } }, motion_plan_req);
355
+ }
382
356
383
357
demo.getVisualTools ().prompt (" Press 'next' in the RvizVisualToolsGui window to finish the demo" );
384
358
rclcpp::shutdown ();
0 commit comments