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 <pluginlib/class_loader.h>
00039 #include <ros/ros.h>
00040
00041
00042 #include <moveit/robot_model_loader/robot_model_loader.h>
00043 #include <moveit/planning_pipeline/planning_pipeline.h>
00044 #include <moveit/planning_interface/planning_interface.h>
00045 #include <moveit/kinematic_constraints/utils.h>
00046 #include <moveit_msgs/DisplayTrajectory.h>
00047 #include <moveit_msgs/PlanningScene.h>
00048
00049 int main(int argc, char **argv)
00050 {
00051 ros::init (argc, argv, "move_group_tutorial");
00052 ros::AsyncSpinner spinner(1);
00053 spinner.start();
00054 ros::NodeHandle node_handle("~");
00055
00056
00057
00058 robot_model_loader::RobotModelLoader robot_model_loader("robot_description");
00059
00060
00061 robot_model::RobotModelPtr robot_model = robot_model_loader.getModel();
00062
00063
00064
00065
00066 planning_scene::PlanningScenePtr planning_scene(new planning_scene::PlanningScene(robot_model));
00067
00068
00069 planning_pipeline::PlanningPipelinePtr planning_pipeline(new planning_pipeline::PlanningPipeline(robot_model, node_handle, "planning_plugin", "request_adapters"));
00070
00071
00072 ros::WallDuration sleep_time(8.0);
00073 sleep_time.sleep();
00074
00075
00076
00077 planning_interface::MotionPlanRequest req;
00078 planning_interface::MotionPlanResponse res;
00079
00080
00081 geometry_msgs::PoseStamped pose;
00082 pose.header.frame_id = "torso_lift_link";
00083 pose.pose.position.x = 0.75;
00084 pose.pose.position.y = 0.0;
00085 pose.pose.position.z = 0.0;
00086 pose.pose.orientation.w = 1.0;
00087
00088
00089 std::vector<double> tolerance_pose(3, 0.01);
00090 std::vector<double> tolerance_angle(3, 0.01);
00091
00092
00093 req.group_name = "right_arm";
00094 moveit_msgs::Constraints pose_goal = kinematic_constraints::constructGoalConstraints("r_wrist_roll_link", pose, tolerance_pose, tolerance_angle);
00095 req.goal_constraints.push_back(pose_goal);
00096
00097
00098
00099 planning_pipeline->generatePlan(planning_scene, req, res);
00100
00101
00102 if(res.error_code_.val != res.error_code_.SUCCESS)
00103 {
00104 ROS_ERROR("Could not compute plan successfully");
00105 return 0;
00106 }
00107
00108
00109
00110 ros::Publisher display_publisher = node_handle.advertise<moveit_msgs::DisplayTrajectory>("/move_group/display_planned_path", 1, true);
00111 moveit_msgs::DisplayTrajectory display_trajectory;
00112
00113
00114 ROS_INFO("Visualizing the trajectory");
00115 moveit_msgs::MotionPlanResponse response;
00116 res.getMessage(response);
00117
00118 display_trajectory.trajectory_start = response.trajectory_start;
00119 display_trajectory.trajectory.push_back(response.trajectory);
00120 display_publisher.publish(display_trajectory);
00121
00122 sleep_time.sleep();
00123
00124
00125
00126 robot_state::RobotState& robot_state = planning_scene->getCurrentStateNonConst();
00127 planning_scene->setCurrentState(response.trajectory_start);
00128 robot_state::JointStateGroup* joint_state_group = robot_state.getJointStateGroup("right_arm");
00129 joint_state_group->setVariableValues(response.trajectory.joint_trajectory.points.back().positions);
00130
00131
00132 robot_state::RobotState goal_state(robot_model);
00133 robot_state::JointStateGroup* goal_group = goal_state.getJointStateGroup("right_arm");
00134 std::vector<double> joint_values(7, 0.0);
00135 joint_values[0] = -2.0;
00136 joint_values[3] = -0.2;
00137 joint_values[5] = -0.15;
00138 goal_group->setVariableValues(joint_values);
00139 moveit_msgs::Constraints joint_goal = kinematic_constraints::constructGoalConstraints(goal_group);
00140
00141 req.goal_constraints.clear();
00142 req.goal_constraints.push_back(joint_goal);
00143
00144
00145 planning_pipeline->generatePlan(planning_scene, req, res);
00146
00147
00148 if(res.error_code_.val != res.error_code_.SUCCESS)
00149 {
00150 ROS_ERROR("Could not compute plan successfully");
00151 return 0;
00152 }
00153
00154
00155 ROS_INFO("Visualizing the trajectory");
00156 res.getMessage(response);
00157
00158 display_trajectory.trajectory_start = response.trajectory_start;
00159 display_trajectory.trajectory.push_back(response.trajectory);
00160
00161 display_publisher.publish(display_trajectory);
00162
00163 sleep_time.sleep();
00164
00165
00166
00167
00168
00169
00170 robot_state = planning_scene->getCurrentStateNonConst();
00171 planning_scene->setCurrentState(response.trajectory_start);
00172 joint_state_group = robot_state.getJointStateGroup("right_arm");
00173 joint_state_group->setVariableValues(response.trajectory.joint_trajectory.points.back().positions);
00174
00175
00176 robot_state::JointState* joint_state = joint_state_group->getJointState("r_shoulder_pan_joint");
00177 const std::vector<std::pair<double, double> >& joint_bounds = joint_state->getVariableBounds();
00178 std::vector<double> tmp_values(1, 0.0);
00179 tmp_values[0] = joint_bounds[0].first - 0.01;
00180 joint_state->setVariableValues(tmp_values);
00181
00182 req.goal_constraints.clear();
00183 req.goal_constraints.push_back(pose_goal);
00184 planning_pipeline->generatePlan(planning_scene, req, res);
00185 if(res.error_code_.val != res.error_code_.SUCCESS)
00186 {
00187 ROS_ERROR("Could not compute plan successfully");
00188 return 0;
00189 }
00190
00191 ROS_INFO("Visualizing the trajectory");
00192 res.getMessage(response);
00193 display_trajectory.trajectory_start = response.trajectory_start;
00194 display_trajectory.trajectory.push_back(response.trajectory);
00195
00196 display_publisher.publish(display_trajectory);
00197
00198 sleep_time.sleep();
00199 ROS_INFO("Done");
00200 return 0;
00201 }