@@ -103,7 +103,7 @@ class Demo
103103
104104 Eigen::Isometry3d text_pose = Eigen::Isometry3d::Identity ();
105105 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);
107107 visual_tools_.trigger ();
108108 }
109109
@@ -188,64 +188,48 @@ class Demo
188188 RCLCPP_INFO (LOGGER, " Loaded planning scene successfully" );
189189
190190 // 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++)
194192 {
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+ }
201203
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+ }
203206 visual_tools_.prompt (" Press 'next' in the RvizVisualToolsGui window to start the demo" );
204207 visual_tools_.trigger ();
205208 return true ;
206209 }
207210
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-
227211 // / \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 )
229213 {
230214 // Set goal state
231- if (!planning_query_request_ .goal_constraints .empty ())
215+ if (!motion_plan_request .goal_constraints .empty ())
232216 {
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 );
249233 }
250234 else
251235 {
@@ -254,7 +238,8 @@ class Demo
254238 }
255239
256240 // / \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)
258243 {
259244 visual_tools_.deleteAllMarkers ();
260245 visual_tools_.prompt (" Press 'next' in the RvizVisualToolsGui window to continue the demo" );
@@ -273,13 +258,10 @@ class Demo
273258 return planning_scene::PlanningScene::clone (ls);
274259 }();
275260
276- auto group_name = planning_query_request_ .group_name ;
261+ auto group_name = motion_plan_request .group_name ;
277262 // Set cost function
278263 planning_component_->setStateCostFunction (
279264 [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,
283265 // rviz_visual_tools::MEDIUM); this->getVisualTools().trigger();
284266 auto clearance_cost_fn =
285267 moveit::cost_functions::getClearanceCostFn (*robot_start_state, group_name, planning_scene);
@@ -288,7 +270,7 @@ class Demo
288270
289271 moveit_cpp::PlanningComponent::PlanRequestParameters plan_request_parameters;
290272 plan_request_parameters.load (node_);
291- RCLCPP_DEBUG_STREAM (
273+ RCLCPP_INFO_STREAM (
292274 LOGGER, " Default plan request parameters loaded with --"
293275 << " planning_pipeline: " << plan_request_parameters.planning_pipeline << ' ,'
294276 << " planner_id: " << plan_request_parameters.planner_id << ' ,'
@@ -297,17 +279,6 @@ class Demo
297279 << " max_velocity_scaling_factor: " << plan_request_parameters.max_velocity_scaling_factor << ' ,'
298280 << " max_acceleration_scaling_factor: " << plan_request_parameters.max_acceleration_scaling_factor );
299281
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-
311282 std::vector<planning_interface::MotionPlanResponse> solutions;
312283 solutions.reserve (pipeline_planner_pairs.size ());
313284 for (auto const & pipeline_planner_pair : pipeline_planner_pairs)
@@ -321,18 +292,18 @@ class Demo
321292 auto robot_model_ptr = moveit_cpp_->getRobotModel ();
322293 auto joint_model_group_ptr = robot_model_ptr->getJointModelGroup (PLANNING_GROUP);
323294 // 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+ }
336307 visual_tools_.trigger ();
337308 }
338309
@@ -341,12 +312,17 @@ class Demo
341312 return visual_tools_;
342313 }
343314
315+ std::vector<moveit_msgs::msg::MotionPlanRequest> getMotionPlanRequests ()
316+ {
317+ return motion_plan_requests;
318+ }
319+
344320private:
345321 std::shared_ptr<rclcpp::Node> node_;
346322 std::shared_ptr<moveit_cpp::MoveItCpp> moveit_cpp_;
347323 std::shared_ptr<moveit_cpp::PlanningComponent> planning_component_;
348324 moveit_visual_tools::MoveItVisualTools visual_tools_;
349- moveit_msgs::msg::MotionPlanRequest planning_query_request_ ;
325+ std::vector< moveit_msgs::msg::MotionPlanRequest> motion_plan_requests ;
350326};
351327} // namespace plannner_cost_fn_example
352328
@@ -371,14 +347,12 @@ int main(int argc, char** argv)
371347 return 0 ;
372348 }
373349
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+ }
382356
383357 demo.getVisualTools ().prompt (" Press 'next' in the RvizVisualToolsGui window to finish the demo" );
384358 rclcpp::shutdown ();
0 commit comments