38 lines
1.3 KiB
C++
38 lines
1.3 KiB
C++
// SICK nanoScan3 example. The sensor's UDP output target must be configured
|
|
// in SICK Safety Designer; this driver only binds a local UDP port.
|
|
#include "lidarlib/sick_lidar.hpp"
|
|
#include <cstdio>
|
|
|
|
int main() {
|
|
lidarlib::NanoScanDriver drv(lidarlib::MODEL_SICK_NANOSCAN3, "0.0.0.0", 6060);
|
|
|
|
if (!drv.open()) {
|
|
fprintf(stderr, "Không mở được UDP socket cho nanoScan3\n");
|
|
return 1;
|
|
}
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
lidarlib::ScanResult result;
|
|
if (!drv.recv_scan(result, 2000)) {
|
|
fprintf(stderr, "Timeout hoặc lỗi nhận UDP datagram\n");
|
|
break;
|
|
}
|
|
const lidarlib::LaserScan& scan = result.scan;
|
|
const lidarlib::ExtraInfo& info = result.info;
|
|
printf("Scan #%d: %zu điểm, ts=%u, model=%s\n",
|
|
i, scan.ranges.size(), scan.timestamp_ms, info.detected_model.c_str());
|
|
|
|
for (size_t j = 0; j < 20 && j < scan.ranges.size(); ++j) {
|
|
float angle_deg = (scan.angle_min + j * scan.angle_increment) * 180.f / 3.14159265f;
|
|
printf(" [%zu] angle=%.2f° dist=%.3fm intensity=%.0f\n",
|
|
j, angle_deg, scan.ranges[j], scan.intensities[j]);
|
|
}
|
|
}
|
|
|
|
drv.close();
|
|
return 0;
|
|
}
|
|
|
|
// Build:
|
|
// g++ -std=c++17 -O2 -Iinclude -o nanoscan_example examples/nanoscan_example.cpp src/sick_lidar.cpp
|