tibi_dabo_arm_client_alg_node.cpp
Go to the documentation of this file.
00001 #include "tibi_dabo_arm_client_alg_node.h"
00002 
00003 TibiDaboArmClientAlgNode::TibiDaboArmClientAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<TibiDaboArmClientAlgorithm>(),
00005   joint_motion_client_("joint_motion", true)
00006 {
00007   //init class attributes if necessary
00008   //this->loop_rate_ = 2;//in [Hz]
00009 
00010   // [init publishers]
00011   
00012   // [init subscribers]
00013   
00014   // [init services]
00015   
00016   // [init clients]
00017   
00018   // [init action servers]
00019   
00020   // [init action clients]
00021   this->public_node_handle_.getParam("robot",this->robot);
00022   this->public_node_handle_.getParam("side",this->side);
00023 
00024   this->joint_motion_done=true;
00025   // initialize the message by default
00026   this->change_joint_names(this->robot,this->side);
00027 }
00028 
00029 TibiDaboArmClientAlgNode::~TibiDaboArmClientAlgNode(void)
00030 {
00031   // [free dynamic memory]
00032 }
00033 
00034 void TibiDaboArmClientAlgNode::mainNodeThread(void)
00035 {
00036   // [fill msg structures]
00037 
00038   // [fill srv structure and make request to the server]
00039 
00040   // [fill action structure and make request to the action server]
00041 
00042   // [publish messages]
00043 }
00044 
00045 void TibiDaboArmClientAlgNode::change_joint_names(int robot_id, int side_id)
00046 {
00047   std::string side_prefix;
00048   
00049   if(side==0)//left
00050     side_prefix="left_";    
00051   else//right
00052     side_prefix="right_";
00053 
00054   this->joint_motion_goal_.trajectory.points.resize(1);
00055   if(robot_id==0)//dabo
00056   {
00057     this->joint_motion_goal_.trajectory.joint_names.resize(4);
00058     this->joint_motion_goal_.trajectory.joint_names[0]=side_prefix + "shoulder_yaw";
00059     this->joint_motion_goal_.trajectory.joint_names[1]=side_prefix + "shoulder_pitch";
00060     this->joint_motion_goal_.trajectory.joint_names[2]=side_prefix + "shoulder_roll";
00061     this->joint_motion_goal_.trajectory.joint_names[3]=side_prefix + "elbow";
00062     this->joint_motion_goal_.trajectory.points[0].positions.resize(4);
00063     this->joint_motion_goal_.trajectory.points[0].velocities.resize(4);
00064     this->joint_motion_goal_.trajectory.points[0].accelerations.resize(4);
00065     this->joint_motion_goal_.trajectory.points[0].time_from_start=ros::Duration(0);
00066   }
00067   else
00068   {
00069     this->joint_motion_goal_.trajectory.joint_names.resize(2);
00070     this->joint_motion_goal_.trajectory.joint_names[0]=side_prefix + "shoulder_yaw";
00071     this->joint_motion_goal_.trajectory.joint_names[1]=side_prefix + "shoulder_roll";
00072     this->joint_motion_goal_.trajectory.points[0].positions.resize(2);
00073     this->joint_motion_goal_.trajectory.points[0].velocities.resize(2);
00074     this->joint_motion_goal_.trajectory.points[0].accelerations.resize(2);
00075     this->joint_motion_goal_.trajectory.points[0].time_from_start=ros::Duration(0);
00076   }
00077 }
00078 
00079 /*  [subscriber callbacks] */
00080 
00081 /*  [service callbacks] */
00082 
00083 /*  [action callbacks] */
00084 void TibiDaboArmClientAlgNode::joint_motionDone(const actionlib::SimpleClientGoalState& state,  const control_msgs::FollowJointTrajectoryResultConstPtr& result) 
00085 { 
00086   if( state.toString().compare("SUCCEEDED") == 0 ) 
00087     ROS_INFO("TibiDaboArmClientAlgNode::joint_motionDone: Goal Achieved!"); 
00088   else 
00089     ROS_INFO("TibiDaboArmClientAlgNode::joint_motionDone: %s", state.toString().c_str()); 
00090   this->joint_motion_done=true;
00091   //copy & work with requested result 
00092 } 
00093 
00094 void TibiDaboArmClientAlgNode::joint_motionActive() 
00095 { 
00096   //ROS_INFO("TibiDaboArmClientAlgNode::joint_motionActive: Goal just went active!"); 
00097 } 
00098 
00099 void TibiDaboArmClientAlgNode::joint_motionFeedback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback) 
00100 { 
00101   //ROS_INFO("TibiDaboArmClientAlgNode::joint_motionFeedback: Got Feedback!"); 
00102 
00103   bool feedback_is_ok = true; 
00104 
00105   //analyze feedback 
00106   //my_var = feedback->var; 
00107 
00108   //if feedback is not what expected, cancel requested goal 
00109   if( !feedback_is_ok ) 
00110   { 
00111     joint_motion_client_.cancelGoal(); 
00112     //ROS_INFO("TibiDaboArmClientAlgNode::joint_motionFeedback: Cancelling Action!"); 
00113   } 
00114 }
00115 
00116 /*  [action requests] */
00117 void TibiDaboArmClientAlgNode::joint_motionMakeActionRequest() 
00118 { 
00119   ROS_INFO("TibiDaboArmClientAlgNode::joint_motionMakeActionRequest: Starting New Request!"); 
00120 
00121   //wait for the action server to start 
00122   //will wait for infinite time 
00123   joint_motion_client_.waitForServer();  
00124   ROS_INFO("TibiDaboArmClientAlgNode::joint_motionMakeActionRequest: Server is Available!"); 
00125 
00126   //send a goal to the action 
00127   //joint_motion_goal_.data = my_desired_goal; 
00128   joint_motion_client_.sendGoal(joint_motion_goal_, 
00129               boost::bind(&TibiDaboArmClientAlgNode::joint_motionDone,     this, _1, _2), 
00130               boost::bind(&TibiDaboArmClientAlgNode::joint_motionActive,   this), 
00131               boost::bind(&TibiDaboArmClientAlgNode::joint_motionFeedback, this, _1)); 
00132   ROS_INFO("TibiDaboArmClientAlgNode::joint_motionMakeActionRequest: Goal Sent. Wait for Result!"); 
00133   this->joint_motion_done=false;
00134 }
00135 
00136 void TibiDaboArmClientAlgNode::node_config_update(Config &config, uint32_t level)
00137 {
00138   this->alg_.lock();
00139   if(this->joint_motion_done)
00140   {
00141     if(config.shoulder_yaw)
00142     {
00143       ROS_INFO("TibiDaboArmClientAlgNode::shouler yaw loaded!");
00144       this->joint_motion_goal_.trajectory.points[0].positions[0]  = config.shoulder_yaw_angle*3.14159/180.0;
00145       this->joint_motion_goal_.trajectory.points[0].velocities[0] = config.speed*3.14159/180.0;
00146     }
00147     if(config.shoulder_pitch && this->robot==0)
00148     {
00149       ROS_INFO("TibiDaboArmClientAlgNode::shoudler pitch loaded!");
00150       this->joint_motion_goal_.trajectory.points[0].positions[1]  = config.shoulder_pitch_angle*3.14159/180.0;
00151       this->joint_motion_goal_.trajectory.points[0].velocities[1] = config.speed*3.14159/180.0;
00152     }
00153     else
00154     {
00155       config.shoulder_pitch=false;
00156       config.shoulder_pitch_angle=0.0;
00157     }
00158     if(config.shoulder_roll)
00159     {
00160       ROS_INFO("TibiDaboArmClientAlgNode::shoulder roll loaded!");
00161       if(this->robot==0)
00162       {
00163         this->joint_motion_goal_.trajectory.points[0].positions[2]  = config.shoulder_roll_angle*3.14159/180.0;
00164         this->joint_motion_goal_.trajectory.points[0].velocities[2] = config.speed*3.14159/180.0;
00165       }
00166       else
00167       {
00168         this->joint_motion_goal_.trajectory.points[0].positions[1]  = config.shoulder_roll_angle*3.14159/180.0;
00169         this->joint_motion_goal_.trajectory.points[0].velocities[1] = config.speed*3.14159/180.0;
00170       }
00171     }
00172     if(config.elbow && this->robot==0)
00173     {
00174       ROS_INFO("TibiDaboArmClientAlgNode::elbow loaded!");
00175       this->joint_motion_goal_.trajectory.points[0].positions[3]  = config.elbow_angle*3.14159/180.0;
00176       this->joint_motion_goal_.trajectory.points[0].velocities[3] = config.speed*3.14159/180.0;
00177     }
00178     else
00179     {
00180       config.elbow=false;
00181       config.elbow_angle=0.0;
00182     }
00183     if(config.move)
00184     {
00185       ROS_INFO("TibiDaboArmClientAlgNode:: requesting head move!");
00186       joint_motionMakeActionRequest();
00187       config.move=false;
00188     }
00189   }
00190 
00191   this->alg_.unlock();
00192 }
00193 
00194 void TibiDaboArmClientAlgNode::addNodeDiagnostics(void)
00195 {
00196 }
00197 
00198 /* main function */
00199 int main(int argc,char *argv[])
00200 {
00201   return algorithm_base::main<TibiDaboArmClientAlgNode>(argc, argv, "tibi_dabo_arm_client_alg_node");
00202 }


tibi_dabo_arm_client
Author(s): dabo
autogenerated on Fri Dec 6 2013 23:45:44