ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You aren't calling ros::spin anywhere and the main thread of the program is blocking so the necessary callbacks aren't ever occurring. Adding an AsynSpinner is the right way to go. This code works for me:

#include <ros/ros.h>

#include <arm_navigation_msgs/SetPlanningSceneDiff.h>
#include <planning_environment/models/collision_models_interface.h>

int main(int argc, char **argv) {
  ros::init(argc, argv, "planning_scene_test_node");
  ros::NodeHandle n;

  ros::AsyncSpinner spinner(1); 
  spinner.start();

  ros::ServiceClient scene_client =
    n.serviceClient<arm_navigation_msgs::SetPlanningSceneDiff>
    ("/environment_server/set_planning_scene_diff");
  ROS_INFO("Waiting for planning scene service");
  scene_client.waitForExistence();
  ROS_INFO("Planning scene service is now available");

  planning_environment::CollisionModelsInterface cmi("robot_description");
  arm_navigation_msgs::SetPlanningSceneDiff ssd;
  if (!scene_client.call(ssd)) {
    ROS_ERROR("Unable to set planning scene");
    return 1;
  }
  ROS_INFO("Successfully set planning scene");
  return 0;
}