Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <xv_11_laser_driver/xv11_laser.h>
00036
00037 namespace xv_11_laser_driver {
00038 XV11Laser::XV11Laser(const std::string& port, uint32_t baud_rate, uint32_t firmware, boost::asio::io_service& io): port_(port),
00039 baud_rate_(baud_rate), firmware_(firmware), shutting_down_(false), serial_(io, port_) {
00040 serial_.set_option(boost::asio::serial_port_base::baud_rate(baud_rate_));
00041 }
00042
00043 void XV11Laser::poll(sensor_msgs::LaserScan::Ptr scan) {
00044 uint8_t temp_char;
00045 uint8_t start_count = 0;
00046 bool got_scan = false;
00047
00048 if(firmware_ == 1){
00049 boost::array<uint8_t, 1440> raw_bytes;
00050 while (!shutting_down_ && !got_scan) {
00051
00052 boost::asio::read(serial_, boost::asio::buffer(&temp_char,1));
00053 if(start_count == 0) {
00054 if(temp_char == 0x5A) {
00055 start_count = 1;
00056 }
00057 } else if(start_count == 1) {
00058 if(temp_char == 0xA5) {
00059 start_count = 2;
00060 }
00061 } else if(start_count == 2) {
00062 if(temp_char == 0x00) {
00063 start_count = 3;
00064 }
00065 } else if(start_count == 3) {
00066 if(temp_char == 0xC0) {
00067 start_count = 0;
00068
00069 got_scan = true;
00070
00071 boost::asio::read(serial_,boost::asio::buffer(&motor_speed_,2));
00072
00073
00074 boost::asio::read(serial_,boost::asio::buffer(&raw_bytes,1440));
00075
00076 scan->angle_min = 0.0;
00077 scan->angle_max = 2.0*M_PI;
00078 scan->angle_increment = (2.0*M_PI/360.0);
00079 scan->time_increment = motor_speed_/1e8;
00080 scan->range_min = 0.06;
00081 scan->range_max = 5.0;
00082 scan->ranges.reserve(360);
00083 scan->intensities.reserve(360);
00084
00085 for(uint16_t i = 0; i < raw_bytes.size(); i=i+4) {
00086
00087 uint8_t byte0 = raw_bytes[i];
00088 uint8_t byte1 = raw_bytes[i+1];
00089 uint8_t byte2 = raw_bytes[i+2];
00090 uint8_t byte3 = raw_bytes[i+3];
00091
00092 uint8_t flag1 = (byte1 & 0x80) >> 7;
00093 uint8_t flag2 = (byte1 & 0x40) >> 6;
00094
00095 uint16_t range = ((byte1 & 0x3F)<< 8) + byte0;
00096
00097 uint16_t intensity = (byte3 << 8) + byte2;
00098
00099 scan->ranges.push_back(range / 1000.0);
00100 scan->intensities.push_back(intensity);
00101 }
00102 }
00103 }
00104 }
00105 } else if(firmware_ == 2) {
00106 boost::array<uint8_t, 1980> raw_bytes;
00107 uint8_t good_sets = 0;
00108 uint32_t motor_speed = 0;
00109 rpms=0;
00110 int index;
00111 while (!shutting_down_ && !got_scan) {
00112
00113 boost::asio::read(serial_, boost::asio::buffer(&raw_bytes[start_count],1));
00114 if(start_count == 0) {
00115 if(raw_bytes[start_count] == 0xFA) {
00116 start_count = 1;
00117 }
00118 } else if(start_count == 1) {
00119 if(raw_bytes[start_count] == 0xA0) {
00120 start_count = 0;
00121
00122
00123 got_scan = true;
00124
00125 boost::asio::read(serial_,boost::asio::buffer(&raw_bytes[2], 1978));
00126
00127 scan->angle_min = 0.0;
00128 scan->angle_max = 2.0*M_PI;
00129 scan->angle_increment = (2.0*M_PI/360.0);
00130 scan->range_min = 0.06;
00131 scan->range_max = 5.0;
00132 scan->ranges.resize(360);
00133 scan->intensities.resize(360);
00134
00135
00136 for(uint16_t i = 0; i < raw_bytes.size(); i=i+22) {
00137 if(raw_bytes[i] == 0xFA && raw_bytes[i+1] == (0xA0+i/22)) {
00138 good_sets++;
00139 motor_speed += (raw_bytes[i+3] << 8) + raw_bytes[i+2];
00140 rpms=(raw_bytes[i+3]<<8|raw_bytes[i+2])/64;
00141
00142 for(uint16_t j = i+4; j < i+20; j=j+4) {
00143 index = (4*i)/22 + (j-4-i)/4;
00144
00145 uint8_t byte0 = raw_bytes[j];
00146 uint8_t byte1 = raw_bytes[j+1];
00147 uint8_t byte2 = raw_bytes[j+2];
00148 uint8_t byte3 = raw_bytes[j+3];
00149
00150
00151
00152
00153 uint16_t range = ((byte1 & 0x3F)<< 8) + byte0;
00154
00155 uint16_t intensity = (byte3 << 8) + byte2;
00156
00157 scan->ranges[index] = range / 1000.0;
00158 scan->intensities[index] = intensity;
00159 }
00160 }
00161 }
00162
00163 scan->time_increment = motor_speed/good_sets/1e8;
00164 }
00165 }
00166 }
00167 }
00168 }
00169 };