darwin_arm_client_alg_node.cpp
Go to the documentation of this file.
00001 #include "darwin_arm_client_alg_node.h"
00002 
00003 
00004 DarwinArmClientAlgNode::DarwinArmClientAlgNode(void) :
00005   algorithm_base::IriBaseAlgorithm<DarwinArmClientAlgorithm>(),
00006   move_joints_client_("move_joints", true)
00007 {
00008   //init class attributes if necessary
00009   //this->loop_rate_ = 2;//in [Hz]
00010 
00011   // [init publishers]
00012   
00013   // [init subscribers]
00014   
00015   // [init services]
00016   
00017   // [init clients]
00018   
00019   // [init action servers]
00020   
00021   // [init action clients]
00022 
00023   this->motion_done=true;
00024   sleep(10);
00025 }
00026 
00027 DarwinArmClientAlgNode::~DarwinArmClientAlgNode(void)
00028 {
00029   // [free dynamic memory]
00030 }
00031 
00032 void DarwinArmClientAlgNode::mainNodeThread(void)
00033 {
00034   static int sequence_step=0;
00035   // [fill msg structures]
00036   
00037   // [fill srv structure and make request to the server]
00038   
00039   // [fill action structure and make request to the action server]
00040   if(this->motion_done)
00041   {
00042     this->move_joints_goal_.trajectory.joint_names.resize(5);
00043     this->move_joints_goal_.trajectory.joint_names[0]="j_shoulder_r";
00044     this->move_joints_goal_.trajectory.joint_names[1]="j_high_arm_r";
00045     this->move_joints_goal_.trajectory.joint_names[2]="j_low_arm_r";
00046     this->move_joints_goal_.trajectory.joint_names[3]="j_wrist_r";
00047     this->move_joints_goal_.trajectory.joint_names[4]="j_gripper_r";
00048     this->move_joints_goal_.trajectory.points.resize(1);
00049     this->move_joints_goal_.trajectory.points[0].positions.resize(5,0.0);
00050     this->move_joints_goal_.trajectory.points[0].velocities.resize(5,50.0);
00051     this->move_joints_goal_.trajectory.points[0].accelerations.resize(5,100.0);
00052     switch(sequence_step)
00053     {
00054       case 0: break;
00055       case 1: this->move_joints_goal_.trajectory.points[0].positions[2]=60.0;
00056               this->move_joints_goal_.trajectory.points[0].positions[0]=45.0;
00057               break;
00058       case 2: this->move_joints_goal_.trajectory.points[0].positions[3]=45.0;
00059               break;
00060       case 3: this->move_joints_goal_.trajectory.points[0].positions[2]=-45.0;
00061               this->move_joints_goal_.trajectory.points[0].positions[0]=-25.0;
00062               break;
00063       case 4: this->move_joints_goal_.trajectory.points[0].positions[4]=0.0;
00064               this->move_joints_goal_.trajectory.points[0].positions[0]=0.0;
00065               this->move_joints_goal_.trajectory.points[0].positions[1]=0.0;
00066               this->move_joints_goal_.trajectory.points[0].positions[2]=0.0;
00067               this->move_joints_goal_.trajectory.points[0].positions[3]=0.0;
00068               break;
00069       default: return;
00070     }
00071     move_jointsMakeActionRequest(); 
00072     sequence_step++;
00073   }
00074 
00075   // [publish messages]
00076 }
00077 
00078 /*  [subscriber callbacks] */
00079 
00080 /*  [service callbacks] */
00081 
00082 /*  [action callbacks] */
00083 void DarwinArmClientAlgNode::move_jointsDone(const actionlib::SimpleClientGoalState& state,  const control_msgs::FollowJointTrajectoryResultConstPtr& result) 
00084 { 
00085   if( state.toString().compare("SUCCEEDED") == 0 ) 
00086     ROS_INFO("DarwinArmClientAlgNode::move_jointsDone: Goal Achieved!"); 
00087   else 
00088     ROS_INFO("DarwinArmClientAlgNode::move_jointsDone: %s", state.toString().c_str()); 
00089   this->motion_done=true;
00090   //copy & work with requested result 
00091 } 
00092 
00093 void DarwinArmClientAlgNode::move_jointsActive() 
00094 { 
00095   //ROS_INFO("DarwinArmClientAlgNode::move_jointsActive: Goal just went active!"); 
00096 } 
00097 
00098 void DarwinArmClientAlgNode::move_jointsFeedback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback) 
00099 { 
00100   //ROS_INFO("DarwinArmClientAlgNode::move_jointsFeedback: Got Feedback!"); 
00101 
00102   bool feedback_is_ok = true; 
00103 
00104   //analyze feedback 
00105   //my_var = feedback->var; 
00106 
00107   //if feedback is not what expected, cancel requested goal 
00108   if( !feedback_is_ok ) 
00109   { 
00110     move_joints_client_.cancelGoal(); 
00111     //ROS_INFO("DarwinArmClientAlgNode::move_jointsFeedback: Cancelling Action!"); 
00112   } 
00113 }
00114 
00115 /*  [action requests] */
00116 void DarwinArmClientAlgNode::move_jointsMakeActionRequest() 
00117 { 
00118   ROS_INFO("DarwinArmClientAlgNode::move_jointsMakeActionRequest: Starting New Request!"); 
00119 
00120   //wait for the action server to start 
00121   //will wait for infinite time 
00122   move_joints_client_.waitForServer();  
00123   ROS_INFO("DarwinArmClientAlgNode::move_jointsMakeActionRequest: Server is Available!"); 
00124 
00125   //send a goal to the action 
00126   //move_joints_goal_.data = my_desired_goal; 
00127   move_joints_client_.sendGoal(move_joints_goal_, 
00128               boost::bind(&DarwinArmClientAlgNode::move_jointsDone,     this, _1, _2), 
00129               boost::bind(&DarwinArmClientAlgNode::move_jointsActive,   this), 
00130               boost::bind(&DarwinArmClientAlgNode::move_jointsFeedback, this, _1)); 
00131   ROS_INFO("DarwinArmClientAlgNode::move_jointsMakeActionRequest: Goal Sent. Wait for Result!"); 
00132   this->motion_done=false; 
00133 }
00134 
00135 void DarwinArmClientAlgNode::node_config_update(Config &config, uint32_t level)
00136 {
00137   this->alg_.lock();
00138 
00139   this->alg_.unlock();
00140 }
00141 
00142 void DarwinArmClientAlgNode::addNodeDiagnostics(void)
00143 {
00144 }
00145 
00146 /* main function */
00147 int main(int argc,char *argv[])
00148 {
00149   return algorithm_base::main<DarwinArmClientAlgNode>(argc, argv, "darwin_arm_client_alg_node");
00150 }


darwin_arm_client
Author(s): Sergi Hernandez Juan
autogenerated on Fri Dec 6 2013 22:40:19