/*The MoveGroup node was launched separately*/
ros::NodeHandle nodehandle;
//Create the MoveGroup interface
moveit::planning_interface::MoveGroup *group= new moveit::planning_interface::MoveGroup("arm");
//Publish a collision object
ros::Publisher object_pub = nodehandle.advertise<moveit_msgs::CollisionObject>("/collision_object",10);
ros::Duration(0.5).sleep();
moveit_msgs::CollisionObject object;
geometry_msgs::Pose object_pose;
object_pose.position.x = 1;
object_pose.position.y = 1;
object_pose.position.z = 0.5;
object_pose.orientation.w = 1;
object_pose.orientation.x = 0;
object_pose.orientation.y = 0;
object_pose.orientation.z = 0;
shape_msgs::SolidPrimitive shape;
shape.type = shape.BOX;
shape.dimensions.push_back(0.1); //x dimension
shape.dimensions.push_back(0.1); //y dimension
shape.dimensions.push_back(0.1); //z dimension
object.header.frame_id = "/world";
object.header.stamp = ros::Time::now();
object.primitives.push_back(shape); //shape is of type shape_msgs::SolidPrimitive
object.primitive_poses.push_back(object_pose); //object_pose is of type geometry_msgs::Pose
object.operation = object.ADD;
object.id = "object1";
object_pub.publish(object);
//Sleep to make sure the object is received within the MoveGroup node
ros::Duration(0.5).sleep();
//Attach the object
ros::Publisher aco_pub = nodehandle.advertise<moveit_msgs::AttachedCollisionObject>("/attached_collision_object",10);
ros::Duration(0.5).sleep();
moveit_msgs::AttachedCollisionObject aco;
aco.object.id = object.id;
aco.link_name = "link_eef";
aco.touch_links.push_back(aco.link_name);
aco.object.operation = moveit_msgs::CollisionObject::ADD;
aco_pub.publish(aco);
//Sleep again
ros::Duration(0.5).sleep();
//Check if the object is now attached using the /get_planning_scene service
ros::ServiceClient client_get_scene = nodehandle.serviceClient<moveit_msgs::GetPlanningScene>("/get_planning_scene");
moveit_msgs::GetPlanningScene scene_srv;
scene_srv.request.components.components = scene_srv.request.components.ROBOT_STATE_ATTACHED_OBJECTS;
if (!client_get_scene.call(scene_srv)){
ROS_WARN("Failed to call service /get_planning_scene");
} else {
ROS_INFO_STREAM("Number of attached bodies according to /get_planning_scene: " << scene_srv.response.scene.robot_state.attached_collision_objects.size());
}
//Check if the object is now attached by getting the current state of the robot via the MoveGroup interface
robot_state::RobotStatePtr RS = group->getCurrentState();
std::vector<const robot_state::AttachedBody*> bodies;
RS->getAttachedBodies(bodies);
ROS_INFO_STREAM("Number of attached bodies according to MoveGroup interface: " << bodies.size());
ros::waitForShutdown();
return 0;
Running this code gives me the following result:
[ INFO] [1379318006.970417558, 298.023000000]: Number of attached bodies according to /get_planning_scene: 1
[ INFO] [1379318006.970601829, 298.024000000]: Number of attached bodies according to MoveGroup interface: 0
I left out the actual planning, because I assume the planner will not consider the attached object unless it is present in the RobotState associated with the MoveGroup interface.
Hope this helps.
Simon
group->attachObject(object);ros::Duration(1.0).sleep();
group = new moveit::planning_interface::MoveGroup("arm");
group->setPoseTarget(target_pose);
group->setStartStateToCurrentState();
group->plan(planA);
I'm now using version 0.5.8 of moveit under Hydro.
Any help is much appreciated.
Regards,
Simon