move_in_pose.cpp
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         // Action client for the joint trajectory action 
00015     // used to trigger the arm movement action
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                 // tell the action client that we want to spin a thread by default
00026                 traj_client_ = new TrajClient("move_iri_wam", true);
00027                 
00028                 // wait for action server to come up
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                 /*ros::NodeHandle nh("/");
00090             
00091                 if(!nh.hasParam("/move_arm/tip_name"))
00092                 {
00093                         ROS_FATAL("tip_name undefined");
00094                         exit(1);
00095                 }       
00096                 std::string tip_name="";         
00097                 nh.param("/move_arm/tip_name", desired_pose.link_name, tip_name);
00098                 if(!nh.hasParam("/move_arm/root_name"))
00099                 {
00100                         ROS_FATAL("root_name undefined");
00101                         exit(1);
00102                 } 
00103                 std::string root_name="";
00104                 nh.param("/move_arm/root_name", desired_pose.header.frame_id,root_name);
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                 /*double tolerance_x;
00120                 double tolerance_y;
00121                 double tolerance_z;
00122                 double tolerance_roll;
00123                 double tolerance_pitch;
00124                 double tolerance_yaw;
00125                 
00126                 nh.param("/move_arm/position/tolerance_x", tolerance_x, 0.02);
00127                 nh.param("/move_arm/position/tolerance_y", tolerance_y, 0.02);
00128                 nh.param("/move_arm/position/tolerance_z", tolerance_z, 0.02);
00129                 nh.param("/move_arm/rotation/tolerance_roll", tolerance_roll, 0.04);
00130                 nh.param("/move_arm/rotation/tolerance_pitch", tolerance_pitch,0.04);
00131                 nh.param("/move_arm/rotation/tolerance_yaw", tolerance_yaw, 0.04);*/
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   // Init the ROS node
00147   ros::init(argc, argv, "move_arm_node");
00148   MoveInPose arm;
00149   arm_navigation_msgs::MoveArmGoal move;
00150   // Start the trajectory  
00151   arm.getTrajectory(argc,argv);
00152   arm.setNamesJoint();
00153   arm.setPlannerRequest(move);
00154   arm.setPlannerRequestPose(move);
00155   arm.startTrajectory(move);
00156   // Wait for trajectory completion
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 }


iri_wam_move_arm
Author(s): Ivan Rojas (ivan.rojas.j@gmail.com)
autogenerated on Fri Dec 6 2013 20:42:05