// sick_example.cpp — quick try-out of the SICK TiM driver (SOPAS/CoLa-A, TCP) // // Verified against a real SICK TiM781S — see the caveat in // include/lidarlib/sick_lidar.hpp for exactly what was (and wasn't) confirmed. #include "lidarlib/sick_lidar.hpp" #include int main() { lidarlib::SickDriver drv(lidarlib::MODEL_SICK_TIM571, "192.168.0.1", 2111); if (!drv.open()) { fprintf(stderr, "Không kết nối được TCP tới lidar SICK\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 telegram\n"); break; } const lidarlib::LaserScan& scan = result.scan; const lidarlib::ExtraInfo& info = result.info; printf("Scan #%d: %zu điểm, ts=%u ms, err=0x%02X, model=%s\n", i, scan.ranges.size(), scan.timestamp_ms, info.error_status, 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 sick_example examples/sick_example.cpp src/sick_lidar.cpp