update brand ESPE
This commit is contained in:
39
examples/espe_example.cpp
Normal file
39
examples/espe_example.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// ESPE LGA60 driver example (TCP, port 8080 theo cấu hình mặc định của hãng).
|
||||
#include "lidarlib/espe_lidar.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
int main() {
|
||||
lidarlib::EspeDriver drv(lidarlib::MODEL_ESPE_LGA60, "192.168.1.88", 8080);
|
||||
|
||||
lidarlib::ErrorCode err = drv.open();
|
||||
if (err != lidarlib::ErrorCode::Ok) {
|
||||
fprintf(stderr, "Không kết nối được tới lidar ESPE: %s\n",
|
||||
lidarlib::to_string(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
lidarlib::ScanResult result;
|
||||
if (!drv.recv_scan(result, 1000)) {
|
||||
fprintf(stderr, "Timeout hoặc lỗi nhận dữ liệu: %s\n",
|
||||
lidarlib::to_string(drv.last_error()));
|
||||
continue;
|
||||
}
|
||||
const lidarlib::LaserScan& scan = result.scan;
|
||||
printf("Scan #%d: %zu điểm, model=%s, diag=%s\n",
|
||||
i, scan.ranges.size(), result.info.detected_model.c_str(),
|
||||
lidarlib::to_string(drv.get_diagnostics()).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 espe_example examples/espe_example.cpp src/espe_lidar.cpp src/olei_lidar.cpp
|
||||
Reference in New Issue
Block a user