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
00007
00008
00009
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
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
00020
00021
00022
00023
00024
00025
00026
00027
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
00039 lastOdoTs = ros::Time::now().toSec();
00040 }
00041
00042 RyOaBridgeAlgNode::~RyOaBridgeAlgNode(void)
00043 {
00044
00045 }
00046
00047 void RyOaBridgeAlgNode::mainNodeThread(void)
00048 {
00049
00050
00051
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
00062
00063
00064
00065
00066 this->status_publisher_.publish(this->oaStatus_msg_);
00067 this->command_publisher_.publish(this->Twist_msg_);
00068 }
00069
00070
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);
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
00085
00086 yarpLocalizationOut.write();
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
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);
00107 botW.addDouble(msg->header.stamp.toSec());
00108 botW.addInt(2);
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);
00117 botW.addDouble(-1);
00118 botW.addDouble(-1);
00119 botW.addDouble(-1);
00120 botW.addDouble(-1);
00121 botW.addDouble(-1);
00122 yarpOdometryOut.write();
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
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);
00142 botW.addDouble(msg->header.stamp.toSec());
00143 botW.addDouble(0);
00144 botW.addDouble(0);
00145 botW.addDouble(0);
00146 botW.addDouble(0);
00147 botW.addDouble(0);
00148 botW.addDouble(0);
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);
00154 botW.addInt(msg->ranges.size());
00155 for (ii=0;ii<msg->ranges.size();ii++){ botW.addDouble(msg->ranges.at(ii)); }
00156 botW.addDouble(-1);
00157 botW.addDouble(-1);
00158 yarpVerticalLaserOut.write();
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
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);
00178 botW.addDouble(msg->header.stamp.toSec());
00179 botW.addDouble(0);
00180 botW.addDouble(0);
00181 botW.addDouble(0);
00182 botW.addDouble(0);
00183 botW.addDouble(0);
00184 botW.addDouble(0);
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);
00190 botW.addInt(msg->ranges.size());
00191 for (ii=0;ii<msg->ranges.size();ii++){ botW.addDouble(msg->ranges.at(ii)); }
00192 botW.addDouble(-1);
00193 botW.addDouble(-1);
00194 yarpFrontLaserOut.write();
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 }
00208
00209
00210
00211
00212
00213
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
00227 int main(int argc,char *argv[])
00228 {
00229 return algorithm_base::main<RyOaBridgeAlgNode>(argc, argv, "ry_oa_bridge_alg_node");
00230 }