38 XV11Laser::XV11Laser(
const std::string& port, uint32_t baud_rate, uint32_t firmware, boost::asio::io_service& io): port_(port),
39 baud_rate_(baud_rate), firmware_(firmware), shutting_down_(false), serial_(io, port_) {
45 uint8_t start_count = 0;
46 bool got_scan =
false;
49 boost::array<uint8_t, 1440> raw_bytes;
52 boost::asio::read(
serial_, boost::asio::buffer(&temp_char,1));
53 if(start_count == 0) {
54 if(temp_char == 0x5A) {
57 }
else if(start_count == 1) {
58 if(temp_char == 0xA5) {
61 }
else if(start_count == 2) {
62 if(temp_char == 0x00) {
65 }
else if(start_count == 3) {
66 if(temp_char == 0xC0) {
74 boost::asio::read(
serial_,boost::asio::buffer(&raw_bytes,1440));
76 scan->angle_min = 0.0;
77 scan->angle_max = 2.0*M_PI;
78 scan->angle_increment = (2.0*M_PI/360.0);
80 scan->range_min = 0.06;
81 scan->range_max = 5.0;
82 scan->ranges.reserve(360);
83 scan->intensities.reserve(360);
85 for(uint16_t i = 0; i < raw_bytes.size(); i=i+4) {
87 uint8_t byte0 = raw_bytes[i];
88 uint8_t byte1 = raw_bytes[i+1];
89 uint8_t byte2 = raw_bytes[i+2];
90 uint8_t byte3 = raw_bytes[i+3];
92 uint8_t flag1 = (byte1 & 0x80) >> 7;
93 uint8_t flag2 = (byte1 & 0x40) >> 6;
95 uint16_t range = ((byte1 & 0x3F)<< 8) + byte0;
97 uint16_t intensity = (byte3 << 8) + byte2;
99 scan->ranges.push_back(range / 1000.0);
100 scan->intensities.push_back(intensity);
106 boost::array<uint8_t, 1980> raw_bytes;
107 uint8_t good_sets = 0;
108 uint32_t motor_speed = 0;
113 boost::asio::read(
serial_, boost::asio::buffer(&raw_bytes[start_count],1));
114 if(start_count == 0) {
115 if(raw_bytes[start_count] == 0xFA) {
118 }
else if(start_count == 1) {
119 if(raw_bytes[start_count] == 0xA0) {
125 boost::asio::read(
serial_,boost::asio::buffer(&raw_bytes[2], 1978));
127 scan->angle_min = 0.0;
128 scan->angle_max = 2.0*M_PI;
129 scan->angle_increment = (2.0*M_PI/360.0);
130 scan->range_min = 0.06;
131 scan->range_max = 5.0;
132 scan->ranges.resize(360);
133 scan->intensities.resize(360);
136 for(uint16_t i = 0; i < raw_bytes.size(); i=i+22) {
137 if(raw_bytes[i] == 0xFA && raw_bytes[i+1] == (0xA0+i/22)) {
139 motor_speed += (raw_bytes[i+3] << 8) + raw_bytes[i+2];
140 rpms=(raw_bytes[i+3]<<8|raw_bytes[i+2])/64;
142 for(uint16_t j = i+4; j < i+20; j=j+4) {
143 index = (4*i)/22 + (j-4-i)/4;
145 uint8_t byte0 = raw_bytes[j];
146 uint8_t byte1 = raw_bytes[j+1];
147 uint8_t byte2 = raw_bytes[j+2];
148 uint8_t byte3 = raw_bytes[j+3];
153 uint16_t range = ((byte1 & 0x3F)<< 8) + byte0;
155 uint16_t intensity = (byte3 << 8) + byte2;
157 scan->ranges[index] = range / 1000.0;
158 scan->intensities[index] = intensity;
163 scan->time_increment = motor_speed/good_sets/1e8;
bool shutting_down_
Flag for whether the driver is supposed to be shutting down or not.
uint32_t firmware_
The firmware version to check. Currently supports two different versions: 1 and 2.
uint32_t baud_rate_
The baud rate for the serial connection.
uint16_t rpms
RPMS derived from the rpm bytes in an XV11 packet.
boost::asio::serial_port serial_
Actual serial port object for reading/writing to the XV11 Laser Scanner.
uint16_t motor_speed_
current motor speed as reported by the XV11.
XV11Laser(const std::string &port, uint32_t baud_rate, uint32_t firmware, boost::asio::io_service &io)
Constructs a new XV11Laser attached to the given serial port.
void poll(sensor_msgs::LaserScan::Ptr scan)
Poll the laser to get a new scan. Blocks until a complete new scan is received or close is called...