kinton_arm_node.cpp
Go to the documentation of this file.
00001 #include "kinton_arm_node.h"
00002 
00003 using namespace std;
00004 
00005 KintonArmDriverNode::KintonArmDriverNode(ros::NodeHandle &nh) : 
00006   iri_base_driver::IriBaseNodeDriver<KintonArmDriver>(nh)
00007 {
00008   //init class attributes if necessary
00009   //this->loop_rate_ = 2;//in [Hz]
00010   this->new_pos_.resize(5);
00011   this->new_pos_.reserve(5);
00012   this->new_pos_.clear();
00013   this->new_pos_.push_back(90);
00014   this->new_pos_.push_back(160);
00015   this->new_pos_.push_back(180);  
00016   this->new_pos_.push_back(20);
00017   this->new_pos_.push_back(90);
00018 
00019   this->old_pos_ = this->new_pos_;
00020 
00021   // [init publishers]
00022   this->arm_joint_feedback_publisher_ = this->public_node_handle_.advertise<sensor_msgs::JointState>("arm_joint_feedback", 10);
00023   
00024   // [init subscribers]
00025   this->arm_joint_pos_subscriber_ = this->public_node_handle_.subscribe("arm_joint_pos", 10, &KintonArmDriverNode::arm_joint_pos_callback, this);
00026   
00027   // [init services]
00028   
00029   // [init clients]
00030   
00031   // [init action servers]
00032   
00033   // [init action clients]
00034 }
00035 
00036 void KintonArmDriverNode::mainNodeThread(void)
00037 {
00038   //lock access to driver if necessary
00039   this->driver_.lock();
00040 
00041   if (this->new_pos_ != this->old_pos_) 
00042   {
00043     this->driver_.set_new_positions(this->new_pos_);
00044   }
00045 
00046   this->old_pos_ = this->new_pos_;
00047 
00048   // [fill msg Header if necessary]
00049   this->JointState_msg_.header.stamp = ros::Time::now();
00050   // [fill msg structures]
00051   // Without feedback, the Joint state message is the same
00052 
00053   this->JointState_msg_.position.clear();
00054   this->JointState_msg_.velocity.clear();
00055   this->JointState_msg_.name.clear();
00056 
00057   this->JointState_msg_.name.push_back("joint1");
00058   this->JointState_msg_.name.push_back("joint2");
00059   this->JointState_msg_.name.push_back("joint3");
00060   this->JointState_msg_.name.push_back("joint4");
00061   this->JointState_msg_.name.push_back("joint5");
00062 
00063   for(size_t i=0;i<this->new_pos_.size();i++)
00064   {
00065     // convert from degrees to radians
00066     this->JointState_msg_.position.push_back(this->new_pos_[i]*3.14159/180.0);
00067     this->JointState_msg_.velocity.push_back(0.0);
00068   }  
00069 
00070   // [fill srv structure and make request to the server]
00071   
00072   // [fill action structure and make request to the action server]
00073 
00074   // [publish messages]
00075   this->arm_joint_feedback_publisher_.publish(this->JointState_msg_);
00076 
00077   //unlock access to driver if previously blocked
00078   this->driver_.unlock();
00079 }
00080 
00081 /*  [subscriber callbacks] */
00082 void KintonArmDriverNode::arm_joint_pos_callback(const sensor_msgs::JointState::ConstPtr& msg) 
00083 { 
00084   //ROS_INFO("KintonArmDriverNode::arm_joint_pos_callback: New Message Received"); 
00085 
00086   //use appropiate mutex to shared variables if necessary 
00087   this->driver_.lock(); 
00088   //this->arm_joint_pos_mutex_.enter(); 
00089 
00090   //std::cout << msg->data << std::endl; 
00091 
00092   this->new_pos_.clear();
00093   this->new_pos_.push_back(msg->position[0]);
00094   this->new_pos_.push_back(msg->position[1]);
00095   this->new_pos_.push_back(msg->position[2]);  
00096   this->new_pos_.push_back(msg->position[3]);
00097   this->new_pos_.push_back(msg->position[4]);
00098 
00099    //unlock previously blocked shared variables 
00100   this->driver_.unlock(); 
00101   //this->arm_joint_pos_mutex_.exit(); 
00102 }
00103 
00104 /*  [service callbacks] */
00105 
00106 /*  [action callbacks] */
00107 
00108 /*  [action requests] */
00109 
00110 void KintonArmDriverNode::postNodeOpenHook(void)
00111 {
00112 }
00113 
00114 void KintonArmDriverNode::addNodeDiagnostics(void)
00115 {
00116 }
00117 
00118 void KintonArmDriverNode::addNodeOpenedTests(void)
00119 {
00120 }
00121 
00122 void KintonArmDriverNode::addNodeStoppedTests(void)
00123 {
00124 }
00125 
00126 void KintonArmDriverNode::addNodeRunningTests(void)
00127 {
00128 }
00129 
00130 void KintonArmDriverNode::reconfigureNodeHook(int level)
00131 {
00132   // To move the servo positions manually using dynamic reconfigure
00133   
00134   this->driver_.lock(); 
00135   //this->arm_joint_pos_mutex_.enter(); 
00136   
00137   this->new_pos_.clear();
00138   this->new_pos_.push_back(this->driver_.config_.servo_1_pos);
00139   this->new_pos_.push_back(this->driver_.config_.servo_2_pos);
00140   this->new_pos_.push_back(this->driver_.config_.servo_3_pos);  
00141   this->new_pos_.push_back(this->driver_.config_.servo_4_pos);
00142   this->new_pos_.push_back(this->driver_.config_.servo_5_pos);
00143   
00144   this->driver_.unlock(); 
00145   //this->arm_joint_pos_mutex_.exit(); 
00146 }
00147 
00148 KintonArmDriverNode::~KintonArmDriverNode(void)
00149 {
00150   // [free dynamic memory]
00151 }
00152 
00153 /* main function */
00154 int main(int argc,char *argv[])
00155 {
00156   return driver_base::main<KintonArmDriverNode>(argc, argv, "kinton_arm_driver_node");
00157 }


kinton_arm_node
Author(s): asantamaria
autogenerated on Fri Dec 6 2013 22:26:48