32 QT_CHARTS_USE_NAMESPACE
40 chart_(new QPolarChart),
41 series_(new QScatterSeries),
43 port_(
"/dev/ttyUSB0"),
44 shutting_down_(false),
47 port_ =
"/dev/ttyUSB0";
50 boost::asio::write(
serial_, boost::asio::buffer(
"b", 1));
55 series_->setPen(QColor(Qt::transparent));
56 series_->setPen(QColor(255,0,0));
59 chart_->legend()->setVisible(
false);
62 QValueAxis *angularAxis =
new QValueAxis();
63 angularAxis->setTickCount(9);
64 angularAxis->setLabelFormat(
"%.1f");
65 angularAxis->setShadesVisible(
true);
66 angularAxis->setShadesBrush(QBrush(QColor(249, 249, 255)));
67 chart_->addAxis(angularAxis, QPolarChart::PolarOrientationAngular);
69 QValueAxis *radialAxis =
new QValueAxis();
70 radialAxis->setTickCount(9);
71 radialAxis->setLabelFormat(
"%d");
72 chart_->addAxis(radialAxis, QPolarChart::PolarOrientationRadial);
74 series_->attachAxis(radialAxis);
75 series_->attachAxis(angularAxis);
81 this->setRenderHint(QPainter::Antialiasing);
87 boost::asio::write(
serial_, boost::asio::buffer(
"e", 1));
92 uint16_t *laser_sensor_data;
93 laser_sensor_data =
poll();
99 series_->append(i, laser_sensor_data[i]);
107 bool got_scan =
false;
109 uint8_t start_count = 0;
110 uint32_t motor_speed = 0;
112 static uint16_t range_data[360] = {0, };
113 static uint16_t intensity_data[360] = {0, };
114 boost::array<uint8_t, 2520> raw_bytes;
119 boost::asio::read(
serial_, boost::asio::buffer(&raw_bytes[start_count],1));
123 if(raw_bytes[start_count] == 0xFA)
128 else if(start_count == 1)
130 if(raw_bytes[start_count] == 0xA0)
137 boost::asio::read(
serial_,boost::asio::buffer(&raw_bytes[2], 2518));
140 for(uint16_t i = 0; i < raw_bytes.size(); i=i+42)
142 if(raw_bytes[i] == 0xFA && raw_bytes[i+1] == (0xA0 + i / 42))
144 motor_speed += (raw_bytes[i+3] << 8) + raw_bytes[i+2];
145 rpms=(raw_bytes[i+3]<<8|raw_bytes[i+2])/10;
147 for(uint16_t j = i+4; j < i+40; j=j+6)
149 index = 6*(i/42) + (j-4-i)/6;
152 uint8_t byte0 = raw_bytes[j];
153 uint8_t byte1 = raw_bytes[j+1];
154 uint8_t byte2 = raw_bytes[j+2];
155 uint8_t byte3 = raw_bytes[j+3];
158 uint16_t intensity = (byte1 << 8) + byte0;
159 intensity_data[359-index] = intensity;
160 uint16_t range = (byte3 << 8) + byte2;
161 range_data[359-index] = range;
bool shutting_down_
Flag for whether the driver is supposed to be shutting down or not.
LdsPolarGraph(QWidget *parent=0)
boost::asio::serial_port serial_
Actual serial port object for reading/writing to the LFCD Laser Scanner.
std::string port_
The serial port the driver is attached to.
uint32_t baud_rate_
The baud rate for the serial connection.