Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <ros/ros.h>
00039 #include <geometry_msgs/Pose.h>
00040
00041
00042 #include <moveit_msgs/PlanningScene.h>
00043 #include <moveit_msgs/AttachedCollisionObject.h>
00044 #include <moveit_msgs/GetStateValidity.h>
00045 #include <moveit_msgs/DisplayRobotState.h>
00046
00047 #include <moveit/robot_model_loader/robot_model_loader.h>
00048 #include <moveit/robot_state/robot_state.h>
00049 #include <moveit/robot_state/conversions.h>
00050
00051 int main(int argc, char **argv)
00052 {
00053 ros::init (argc, argv, "move_group_tutorial");
00054 ros::AsyncSpinner spinner(1);
00055 spinner.start();
00056 ros::NodeHandle node_handle;
00057
00058
00059
00060 ros::Publisher collision_object_publisher = node_handle.advertise<moveit_msgs::CollisionObject>("collision_object", 1);
00061 while(collision_object_publisher.getNumSubscribers() < 1)
00062 {
00063 ros::WallDuration sleep_t(0.5);
00064 sleep_t.sleep();
00065 }
00066
00067 moveit_msgs::CollisionObject object;
00068
00069 object.header.frame_id = "r_wrist_roll_link";
00070
00071 object.id = "box";
00072
00073
00074 geometry_msgs::Pose pose;
00075 pose.orientation.w = 1.0;
00076
00077
00078 shape_msgs::SolidPrimitive primitive;
00079 primitive.type = primitive.BOX;
00080 primitive.dimensions.resize(3);
00081 primitive.dimensions[0] = 0.1;
00082 primitive.dimensions[1] = 0.1;
00083 primitive.dimensions[2] = 0.1;
00084
00085 object.primitives.push_back(primitive);
00086 object.primitive_poses.push_back(pose);
00087
00088
00089 object.operation = attached_object.object.ADD;
00090
00091
00092 collision_object_publisher.publish(object);
00093 ros::WallDuration sleep_time(1.0);
00094 sleep_time.sleep();
00095
00096
00097
00098 ROS_INFO("Putting the object back into the environment");
00099 planning_scene.robot_state.attached_collision_objects.clear();
00100 planning_scene.world.collision_objects.clear();
00101 planning_scene.world.collision_objects.push_back(object);
00102 planning_scene.is_diff = true;
00103 planning_scene_diff_publisher.publish(planning_scene);
00104 sleep_time.sleep();
00105
00106
00107 robot_model_loader::RDFLoader robot_model_loader("robot_description");
00108
00109 robot_model::RobotModelPtr kinematic_model = robot_model_loader.getModel();
00110 robot_state::RobotState current_state(kinematic_model);
00111 current_state.getJointStateGroup("right_arm")->setToRandomValues();
00112
00113
00114 moveit_msgs::RobotState robot_state;
00115 robot_state::robotStateToRobotStateMsg(current_state, robot_state);
00116
00117
00118 moveit_msgs::GetStateValidity::Request get_state_validity_request;
00119 moveit_msgs::GetStateValidity::Response get_state_validity_response;
00120 get_state_validity_request.robot_state = robot_state;
00121 get_state_validity_request.group_name = "right_arm";
00122
00123
00124 ros::ServiceClient service_client = node_handle.serviceClient<moveit_msgs::GetStateValidity>("/check_state_validity");
00125
00126
00127 ros::Publisher display_publisher = node_handle.advertise<moveit_msgs::DisplayRobotState>("/display_robot_state", 1);
00128 moveit_msgs::DisplayRobotState display_state;
00129
00130 for(std::size_t i=0; i < 20; ++i)
00131 {
00132
00133 service_client.call(get_state_validity_request, get_state_validity_response);
00134 if(get_state_validity_response.valid)
00135 ROS_INFO("State %d was valid", (int) i);
00136 else
00137 ROS_ERROR("State %d was invalid", (int) i);
00138
00139
00140 display_state.state = robot_state;
00141 display_publisher.publish(display_state);
00142
00143
00144 current_state.getJointStateGroup("right_arm")->setToRandomValues();
00145 robot_state::robotStateToRobotStateMsg(current_state, robot_state);
00146 get_state_validity_request.robot_state = robot_state;
00147 sleep_time.sleep();
00148 }
00149 }