Go to the documentation of this file.00001 #include "hokuyo_laser_driver_node.h"
00002 #include <cmath>
00003
00004 HokuyoLaserDriverNode::HokuyoLaserDriverNode(ros::NodeHandle &nh) : iri_base_driver::IriBaseNodeDriver<HokuyoLaserDriver>(nh)
00005 {
00006
00007
00008 this->loop_rate_ = 100;
00009
00010
00011
00012 this->scan_publisher = this->public_node_handle_.advertise<sensor_msgs::LaserScan>("scan", 100);
00013 if(driver_.config_.is_multiecho){
00014 this->scan_publisher2 = this->public_node_handle_.advertise<sensor_msgs::LaserScan>("scan2", 100);
00015 this->scan_publisher3 = this->public_node_handle_.advertise<sensor_msgs::LaserScan>("scan3", 100);
00016 }
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 event_server_ = CEventServer::instance();
00029 }
00030
00031 void HokuyoLaserDriverNode::mainNodeThread(void)
00032 {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 int current_event = 0;
00044
00045 ROS_DEBUG("WAIT FOR SCAN");
00046
00047
00048 try
00049 {
00050 current_event = event_server_->wait_first(driver_.evnts,5000);
00051 switch( current_event )
00052 {
00053 default:
00054 case 0:
00055
00056 this->driver_.lock();
00057 mutex_scan_.enter();
00058 this->driver_.getScan(last_scan_);
00059 mutex_scan_.exit();
00060 this->driver_.unlock();
00061 ROS_DEBUG("HokuyoLaserDriverNode::mainNodeThread NEW SCAN");
00062 break;
00063 case 1:
00064 ROS_DEBUG("HokuyoLaserDriverNode::mainNodeThread END SCANS");
00065
00066 break;
00067 case 2:
00068
00069 ROS_DEBUG("HokuyoLaserDriverNode::mainNodeThread ERROR");
00070 break;
00071 }
00072 }
00073 catch(CException &e)
00074 {
00075 cout << e.what() << endl;
00076 }
00077
00078
00079
00080
00081 ROS_DEBUG("BUILD MESSAGE");
00082 mutex_scan_.enter();
00083 ros::Time t_laser( last_scan_.t.seconds(), last_scan_.t.nanoseconds() );
00084 this->LaserScan_msg.header.stamp = t_laser;
00085 this->driver_.lock();
00086 this->LaserScan_msg.header.frame_id = this->driver_.config_.frame_id;
00087
00088 this->LaserScan_msg.angle_min = this->driver_.config_.angle_min;
00089 this->LaserScan_msg.angle_max = this->driver_.config_.angle_max;
00090 this->LaserScan_msg.angle_increment = this->driver_.angle_increment;
00091 this->LaserScan_msg.time_increment = this->driver_.time_increment;
00092 this->LaserScan_msg.scan_time = this->driver_.scan_time;
00093 this->LaserScan_msg.range_min = this->driver_.range_min;
00094 this->LaserScan_msg.range_max = this->driver_.range_max;
00095
00096 is_multiecho_ = driver_.config_.is_multiecho;
00097 this->driver_.unlock();
00098
00099 vector<float> franges,franges2,franges3;
00100 franges.reserve(last_scan_.distance.size());
00101 franges2.reserve(last_scan_.distance.size());
00102 franges3.reserve(last_scan_.distance.size());
00103
00104 for(uint i=0;i<last_scan_.distance.size();i++)
00105 {
00106 franges.push_back((float)(last_scan_.distance[i][0])/1000);
00107
00108 if(is_multiecho_){
00109 if(last_scan_.distance[i].size()==2)
00110 {
00111 franges2.push_back((float)(last_scan_.distance[i][1])/1000);
00112 franges3.push_back(franges.back());
00113 }
00114 else if(last_scan_.distance[i].size()==3)
00115 {
00116 franges3.push_back((float)(last_scan_.distance[i][2])/1000);
00117 franges2.push_back(franges.back());
00118 }
00119 else
00120 {
00121 franges2.push_back(franges.back());
00122 franges3.push_back(franges.back());
00123 }
00124 }
00125 }
00126
00127 vector<float> fintens;
00128 fintens.reserve(last_scan_.intensity.size());
00129
00130
00131 for(uint i=0;i<last_scan_.intensity.size();i++)
00132 fintens.push_back((float)(last_scan_.intensity[i][0]));
00133
00134 this->LaserScan_msg.intensities = fintens;
00135 this->LaserScan_msg.ranges = franges;
00136 mutex_scan_.exit();
00137
00138
00139
00140
00141
00142 ROS_DEBUG("PUBLISH MESSAGE");
00143
00144 this->scan_publisher.publish(this->LaserScan_msg);
00145
00146 if(is_multiecho_)
00147 {
00148 this->LaserScan2_msg = this->LaserScan_msg;
00149 this->LaserScan3_msg = this->LaserScan_msg;
00150 this->LaserScan2_msg.ranges = franges2;
00151 this->LaserScan3_msg.ranges = franges3;
00152 this->scan_publisher2.publish(this->LaserScan2_msg);
00153 this->scan_publisher3.publish(this->LaserScan3_msg);
00154 }
00155
00156
00157
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 void HokuyoLaserDriverNode::postNodeOpenHook(void)
00169 {
00170 }
00171
00172 void HokuyoLaserDriverNode::addNodeDiagnostics(void)
00173 {
00174 }
00175
00176 void HokuyoLaserDriverNode::addNodeOpenedTests(void)
00177 {
00178 }
00179
00180 void HokuyoLaserDriverNode::addNodeStoppedTests(void)
00181 {
00182 }
00183
00184 void HokuyoLaserDriverNode::addNodeRunningTests(void)
00185 {
00186 }
00187
00188 void HokuyoLaserDriverNode::reconfigureNodeHook(int level)
00189 {
00190 }
00191
00192 HokuyoLaserDriverNode::~HokuyoLaserDriverNode()
00193 {
00194
00195 }
00196
00197
00198 int main(int argc,char *argv[])
00199 {
00200 return driver_base::main<HokuyoLaserDriverNode>(argc,argv,"hokuyo_laser_driver_node");
00201 }