ry_oa_bridge_alg_node.cpp
Go to the documentation of this file.
00001 #include "ry_oa_bridge_alg_node.h"
00002 
00003 RyOaBridgeAlgNode::RyOaBridgeAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<RyOaBridgeAlgorithm>()
00005 {
00006   //init class attributes if necessary
00007   //this->loop_rate_ = 2;//in [Hz]
00008 
00009   // [init publishers]
00010   this->status_publisher_ = this->public_node_handle_.advertise<iri_ry_oa_bridge::oaStatus>("status", 100);
00011   this->command_publisher_ = this->public_node_handle_.advertise<geometry_msgs::Twist>("command", 100);
00012   
00013   // [init subscribers]
00014   this->localization_subscriber_ = this->public_node_handle_.subscribe("localization", 100, &RyOaBridgeAlgNode::localization_callback, this);
00015   this->odometry_subscriber_ = this->public_node_handle_.subscribe("odometry", 100, &RyOaBridgeAlgNode::odometry_callback, this);
00016   this->vertical_laser_subscriber_ = this->public_node_handle_.subscribe("vertical_laser", 100, &RyOaBridgeAlgNode::vertical_laser_callback, this);
00017   this->front_laser_subscriber_ = this->public_node_handle_.subscribe("front_laser", 100, &RyOaBridgeAlgNode::front_laser_callback, this);
00018   
00019   // [init services]
00020   
00021   // [init clients]
00022   
00023   // [init action servers]
00024   
00025   // [init action clients]
00026   
00027   //yarp init's
00028   Network yarp;
00029   yarpOdometryOut.open("/oa_bridge/odometry");
00030   yarpVerticalLaserOut.open("/oa_bridge/verticalLaser");
00031   yarpFrontLaserOut.open("/oa_bridge/frontLaser");
00032   yarpLocalizationOut.open("/oa_bridge/localization");
00033   yarpVelocitiesIn.open("/oa_bridge/velocities");
00034   yarpVelocitiesIn.useCallback();
00035   yarpOaStatusIn.open("/oa_bridge/status");
00036   yarpOaStatusIn.useCallback();
00037   
00038   //other init's
00039   lastOdoTs = ros::Time::now().toSec();
00040 }
00041 
00042 RyOaBridgeAlgNode::~RyOaBridgeAlgNode(void)
00043 {
00044   // [free dynamic memory]
00045 }
00046 
00047 void RyOaBridgeAlgNode::mainNodeThread(void)
00048 {
00049   // [fill msg structures]
00050   //this->oaStatus_msg.data = my_var;
00051   //this->Twist_msg.data = my_var;
00052   this->oaStatus_msg_.status = yarpOaStatusIn.getStatus();
00053   this->oaStatus_msg_.state = yarpOaStatusIn.getState();
00054   this->Twist_msg_.linear.x = yarpVelocitiesIn.getV();
00055   this->Twist_msg_.linear.y = 0;
00056   this->Twist_msg_.linear.z = 0;
00057   this->Twist_msg_.angular.x = 0;
00058   this->Twist_msg_.angular.y = 0;
00059   this->Twist_msg_.angular.z = yarpVelocitiesIn.getW();
00060   
00061   // [fill srv structure and make request to the server]
00062   
00063   // [fill action structure and make request to the action server]
00064 
00065   // [publish messages]
00066   this->status_publisher_.publish(this->oaStatus_msg_);
00067   this->command_publisher_.publish(this->Twist_msg_);
00068 }
00069 
00070 /*  [subscriber callbacks] */
00071 void RyOaBridgeAlgNode::localization_callback(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg) 
00072 { 
00073         double now, dT;
00074         
00075         Bottle & botW = yarpLocalizationOut.prepare(); 
00076         botW.clear();
00077         botW.addInt(2);//indicates basic success
00078         botW.addDouble(msg->header.stamp.toSec());
00079         botW.addInt(0); 
00080         botW.addInt(0);
00081         botW.addDouble(msg->pose.pose.position.x);
00082         botW.addDouble(msg->pose.pose.position.y);
00083         botW.addDouble(msg->pose.pose.position.z);
00084         //fill orientation if required by ry_path_execution
00085         //...
00086         yarpLocalizationOut.write();
00087 
00088 //   ROS_INFO("RyOaBridgeAlgNode::localization_callback: New Message Received"); 
00089 
00090   //use appropiate mutex to shared variables if necessary 
00091   //this->alg_.lock(); 
00092   //this->localization_mutex_.enter(); 
00093 
00094   //std::cout << msg->data << std::endl; 
00095 
00096   //unlock previously blocked shared variables 
00097   //this->alg_.unlock(); 
00098   //this->localization_mutex_.exit(); 
00099 }
00100 void RyOaBridgeAlgNode::odometry_callback(const nav_msgs::Odometry::ConstPtr& msg) 
00101 { 
00102         double now, dT;
00103         
00104         Bottle & botW = yarpOdometryOut.prepare(); 
00105         botW.clear();
00106         botW.addInt(2);//indicates basic success
00107         botW.addDouble(msg->header.stamp.toSec());
00108         botW.addInt(2); //indicates two-wheel balanced
00109         now = msg->header.stamp.toSec();
00110         dT = now - lastOdoTs;
00111         lastOdoTs = now;
00112         botW.addDouble(dT*msg->twist.twist.linear.x);
00113         botW.addDouble(dT*msg->twist.twist.angular.z);
00114         botW.addDouble(msg->twist.twist.linear.x);
00115         botW.addDouble(msg->twist.twist.angular.z);
00116         botW.addDouble(-1);//torque1
00117         botW.addDouble(-1);//torque2
00118         botW.addDouble(-1);//voltage1
00119         botW.addDouble(-1);//voltage2
00120         botW.addDouble(-1);//reserved1
00121         botW.addDouble(-1);//reserved2
00122         yarpOdometryOut.write();
00123 
00124   //ROS_INFO("RyOaBridgeAlgNode::odometry_callback: New Message Received"); 
00125 
00126   //use appropiate mutex to shared variables if necessary 
00127   //this->alg_.lock(); 
00128   //this->odometry_mutex_.enter(); 
00129   
00130   //std::cout << msg->data << std::endl; 
00131 
00132   //unlock previously blocked shared variables 
00133   //this->alg_.unlock(); 
00134   //this->odometry_mutex_.exit(); 
00135 }
00136 void RyOaBridgeAlgNode::vertical_laser_callback(const sensor_msgs::LaserScan::ConstPtr& msg) 
00137 { 
00138         unsigned int ii;
00139         
00140         Bottle & botW = yarpVerticalLaserOut.prepare(); 
00141         botW.addInt(2);//indicates basic success
00142         botW.addDouble(msg->header.stamp.toSec());
00143         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00144         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00145         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00146         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00147         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00148         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00149         botW.addDouble(fabs(msg->angle_max - msg->angle_min));
00150         botW.addDouble(msg->angle_min);
00151         botW.addDouble(msg->range_min);
00152         botW.addDouble(msg->range_max);
00153         botW.addDouble(0.05);//sigma. I think not used by ry-oa
00154         botW.addInt(msg->ranges.size());
00155         for (ii=0;ii<msg->ranges.size();ii++){ botW.addDouble(msg->ranges.at(ii)); } //add laser data
00156         botW.addDouble(-1);//reserved1
00157         botW.addDouble(-1);//reserved2
00158         yarpVerticalLaserOut.write();
00159 
00160   //ROS_INFO("RyOaBridgeAlgNode::vertical_laser_callback: New Message Received"); 
00161 
00162   //use appropiate mutex to shared variables if necessary 
00163   //this->alg_.lock(); 
00164   //this->vertical_laser_mutex_.enter(); 
00165 
00166   //std::cout << msg->data << std::endl; 
00167 
00168   //unlock previously blocked shared variables 
00169   //this->alg_.unlock(); 
00170   //this->vertical_laser_mutex_.exit(); 
00171 }
00172 void RyOaBridgeAlgNode::front_laser_callback(const sensor_msgs::LaserScan::ConstPtr& msg) 
00173 { 
00174         unsigned int ii;
00175         
00176         Bottle & botW = yarpFrontLaserOut.prepare(); 
00177         botW.addInt(2);//indicates basic success
00178         botW.addDouble(msg->header.stamp.toSec());
00179         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00180         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00181         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00182         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00183         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00184         botW.addDouble(0);//laser mounting position. Not taken into account by ry-oa
00185         botW.addDouble(fabs(msg->angle_max - msg->angle_min));
00186         botW.addDouble(msg->angle_min);
00187         botW.addDouble(msg->range_min);
00188         botW.addDouble(msg->range_max);
00189         botW.addDouble(0.05);//sigma. I think not used by ry-oa
00190         botW.addInt(msg->ranges.size());
00191         for (ii=0;ii<msg->ranges.size();ii++){ botW.addDouble(msg->ranges.at(ii)); } //add laser data
00192         botW.addDouble(-1);//reserved1
00193         botW.addDouble(-1);//reserved2
00194         yarpFrontLaserOut.write();
00195 
00196   //ROS_INFO("RyOaBridgeAlgNode::front_laser_callback: New Message Received"); 
00197 
00198   //use appropiate mutex to shared variables if necessary 
00199   //this->alg_.lock(); 
00200   //this->front_laser_mutex_.enter(); 
00201 
00202   //std::cout << msg->data << std::endl; 
00203 
00204   //unlock previously blocked shared variables 
00205   //this->alg_.unlock(); 
00206   //this->front_laser_mutex_.exit(); 
00207 }
00208 
00209 /*  [service callbacks] */
00210 
00211 /*  [action callbacks] */
00212 
00213 /*  [action requests] */
00214 
00215 void RyOaBridgeAlgNode::node_config_update(Config &config, uint32_t level)
00216 {
00217   this->alg_.lock();
00218 
00219   this->alg_.unlock();
00220 }
00221 
00222 void RyOaBridgeAlgNode::addNodeDiagnostics(void)
00223 {
00224 }
00225 
00226 /* main function */
00227 int main(int argc,char *argv[])
00228 {
00229   return algorithm_base::main<RyOaBridgeAlgNode>(argc, argv, "ry_oa_bridge_alg_node");
00230 }


iri_ry_oa_bridge
Author(s): andreu
autogenerated on Fri Dec 6 2013 22:22:45