Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <actionlib/client/simple_action_client.h>
00003 #include <actionlib/client/terminal_state.h>
00004 #include <arm_navigation_msgs/MoveArmAction.h>
00005 #include <arm_navigation_msgs/utils.h>
00006 #include <sstream>
00007 #include <iostream>
00008 #include <stdlib.h>
00009
00010 typedef actionlib::SimpleActionClient<arm_navigation_msgs::MoveArmAction> TrajClient;
00011 class MoveInPose
00012 {
00013 private:
00014
00015
00016 TrajClient* traj_client_;
00017 ros::Duration time_move;
00018 std::vector<double> posicion;
00019 std::vector<double> rotacion;
00020 std::vector<std::string> names;
00021 public:
00023 MoveInPose()
00024 {
00025
00026 traj_client_ = new TrajClient("move_iri_wam", true);
00027
00028
00029 while(!traj_client_->waitForServer(ros::Duration(5.0))){
00030 ROS_INFO("Waiting for the move_iri_wam server");
00031 }
00032 }
00034 ~MoveInPose()
00035 {
00036 delete traj_client_;
00037 }
00039 void setNamesJoint(void)
00040 {
00041 names.push_back("j1_joint");
00042 names.push_back("j2_joint");
00043 names.push_back("j3_joint");
00044 names.push_back("j4_joint");
00045 names.push_back("j5_joint");
00046 names.push_back("j6_joint");
00047 names.push_back("j7_joint");
00048 }
00050 void startTrajectory(arm_navigation_msgs::MoveArmGoal& goal)
00051 {
00052 traj_client_->sendGoal(goal);
00053 }
00055 void getTrajectory(int argc, char** argv)
00056 {
00057 if(argc < 8 || argc > 9)
00058 {
00059 ROS_FATAL("Error: The numbers of parameters out of bound ");
00060 exit(1);
00061 }
00062 posicion.resize(3);
00063 rotacion.resize(4);
00064 for(int i =1; i <=7; ++i)
00065 {
00066 (i < 4)? posicion[i-1]=strtod(argv[i],NULL):rotacion[i-4]=strtod(argv[i],NULL);
00067 }
00068 time_move= (argc == 9)?ros::Duration(strtod(argv[8],NULL)):ros::Duration(0.0);
00069 }
00071 actionlib::SimpleClientGoalState getState()
00072 {
00073 return traj_client_->getState();
00074 }
00076 void setPlannerRequest(arm_navigation_msgs::MoveArmGoal& goal)
00077 {
00078 goal.motion_plan_request.group_name="iri_wam";
00079 goal.motion_plan_request.num_planning_attempts = 1;
00080 goal.motion_plan_request.allowed_planning_time = ros::Duration(5.0);
00081 goal.motion_plan_request.planner_id = std::string("");
00082 goal.planner_service_name=std::string("ompl_planning/plan_kinematic_path");
00083 goal.motion_plan_request.expected_path_dt = time_move;
00084 }
00086 void setPlannerRequestPose(arm_navigation_msgs::MoveArmGoal& goal)
00087 {
00088 arm_navigation_msgs::SimplePoseConstraint desired_pose;
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 desired_pose.header.frame_id="world";
00108 desired_pose.link_name="lk_wam7";
00109 desired_pose.pose.position.x = posicion[0];
00110 desired_pose.pose.position.y = posicion[1];
00111 desired_pose.pose.position.z = posicion[2];
00112
00113
00114 desired_pose.pose.orientation.x = rotacion[0];
00115 desired_pose.pose.orientation.y = rotacion[1];
00116 desired_pose.pose.orientation.z = rotacion[2];
00117 desired_pose.pose.orientation.w = rotacion[3];
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 desired_pose.absolute_position_tolerance.x = 0.02;
00134 desired_pose.absolute_position_tolerance.y = 0.02;
00135 desired_pose.absolute_position_tolerance.z = 0.02;
00136
00137 desired_pose.absolute_roll_tolerance = 0.04;
00138 desired_pose.absolute_pitch_tolerance = 0.04;
00139 desired_pose.absolute_yaw_tolerance = 0.04;
00140
00141 arm_navigation_msgs::addGoalConstraintToMoveArmGoal(desired_pose,goal);
00142 }
00143 };
00144 int main(int argc, char** argv)
00145 {
00146
00147 ros::init(argc, argv, "move_arm_node");
00148 MoveInPose arm;
00149 arm_navigation_msgs::MoveArmGoal move;
00150
00151 arm.getTrajectory(argc,argv);
00152 arm.setNamesJoint();
00153 arm.setPlannerRequest(move);
00154 arm.setPlannerRequestPose(move);
00155 arm.startTrajectory(move);
00156
00157 while(!arm.getState().isDone() && ros::ok())
00158 {
00159 usleep(50000);
00160 }
00161
00162 bool success = (arm.getState() == actionlib::SimpleClientGoalState::SUCCEEDED);
00163 if(success)
00164 ROS_INFO("Action finished: %s",arm.getState().toString().c_str());
00165 else
00166 ROS_INFO("Action failed: %s",arm.getState().toString().c_str());
00167 }