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   
00009   
00010 
00011   
00012   
00013   
00014   
00015   
00016   
00017   
00018   
00019   
00020   
00021   
00022 
00023   this->motion_done=true;
00024   sleep(10);
00025 }
00026 
00027 DarwinArmClientAlgNode::~DarwinArmClientAlgNode(void)
00028 {
00029   
00030 }
00031 
00032 void DarwinArmClientAlgNode::mainNodeThread(void)
00033 {
00034   static int sequence_step=0;
00035   
00036   
00037   
00038   
00039   
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   
00076 }
00077 
00078 
00079 
00080 
00081 
00082 
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   
00091 } 
00092 
00093 void DarwinArmClientAlgNode::move_jointsActive() 
00094 { 
00095   
00096 } 
00097 
00098 void DarwinArmClientAlgNode::move_jointsFeedback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback) 
00099 { 
00100   
00101 
00102   bool feedback_is_ok = true; 
00103 
00104   
00105   
00106 
00107   
00108   if( !feedback_is_ok ) 
00109   { 
00110     move_joints_client_.cancelGoal(); 
00111     
00112   } 
00113 }
00114 
00115 
00116 void DarwinArmClientAlgNode::move_jointsMakeActionRequest() 
00117 { 
00118   ROS_INFO("DarwinArmClientAlgNode::move_jointsMakeActionRequest: Starting New Request!"); 
00119 
00120   
00121   
00122   move_joints_client_.waitForServer();  
00123   ROS_INFO("DarwinArmClientAlgNode::move_jointsMakeActionRequest: Server is Available!"); 
00124 
00125   
00126   
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 
00147 int main(int argc,char *argv[])
00148 {
00149   return algorithm_base::main<DarwinArmClientAlgNode>(argc, argv, "darwin_arm_client_alg_node");
00150 }