40 : port_(port), baud_rate_(baud_rate), shutting_down_(false), serial_(io, port_)
45 boost::asio::write(
serial_, boost::asio::buffer(
"b", 1));
50 boost::asio::write(
serial_, boost::asio::buffer(
"e", 1));
56 uint8_t start_count = 0;
57 bool got_scan =
false;
58 boost::array<uint8_t, 2520> raw_bytes;
59 uint8_t good_sets = 0;
60 uint32_t motor_speed = 0;
67 boost::asio::read(
serial_, boost::asio::buffer(&raw_bytes[start_count],1));
71 if(raw_bytes[start_count] == 0xFA)
76 else if(start_count == 1)
78 if(raw_bytes[start_count] == 0xA0)
85 boost::asio::read(
serial_,boost::asio::buffer(&raw_bytes[2], 2518));
96 for(uint16_t i = 0; i < raw_bytes.size(); i=i+42)
98 if(raw_bytes[i] == 0xFA && raw_bytes[i+1] == (0xA0 + i / 42))
101 motor_speed += (raw_bytes[i+3] << 8) + raw_bytes[i+2];
102 rpms=(raw_bytes[i+3]<<8|raw_bytes[i+2])/10;
104 for(uint16_t j = i+4; j < i+40; j=j+6)
106 index = 6*(i/42) + (j-4-i)/6;
109 uint8_t byte0 = raw_bytes[j];
110 uint8_t byte1 = raw_bytes[j+1];
111 uint8_t byte2 = raw_bytes[j+2];
112 uint8_t byte3 = raw_bytes[j+3];
115 uint16_t intensity = (byte1 << 8) + byte0;
119 uint16_t range = (byte3 << 8) + byte2;
123 printf (
"r[%d]=%f,",359-index, range / 1000.0);
139 int main(
int argc,
char **argv)
144 port =
"/dev/ttyUSB0";
146 boost::asio::io_service io;
160 catch (boost::system::system_error ex)
162 printf(
"An exception was thrown: %s", ex.what());
boost::asio::serial_port serial_
Actual serial port object for reading/writing to the LFCD Laser Scanner.
uint32_t baud_rate_
The baud rate for the serial connection.
int main(int argc, char **argv)
LFCDLaser(const std::string &port, uint32_t baud_rate, boost::asio::io_service &io)
Constructs a new LFCDLaser attached to the given serial port.
~LFCDLaser()
Default destructor.
bool shutting_down_
Flag for whether the driver is supposed to be shutting down or not.
void close()
Close the driver down and prevent the polling loop from advancing.
uint16_t rpms
RPMS derived from the rpm bytes in an LFCD packet.
void poll()
Poll the laser to get a new scan. Blocks until a complete new scan is received or close is called...