25 #include <SimoxUtility/algorithm/string/string_tools.h>
33 #include <HokuyoLaserScannerDriver/urg_utils.h>
49 laserScannerListenerProxyName = getProperty<std::string>(
"LaserScannerListenerName").getValue();
51 ARMARX_INFO <<
"Going to report to listener " << laserScannerListenerProxyName;
52 updatePeriod = getProperty<int>(
"UpdatePeriod").getValue();
53 angleOffset = getProperty<float>(
"AngleOffset").getValue();
55 std::string deviceStrings = getProperty<std::string>(
"Devices").getValue();
56 std::vector<std::string> splitDeviceStrings =
Split(deviceStrings,
";");
58 devices.reserve(splitDeviceStrings.size());
59 for (std::string
const& deviceString : splitDeviceStrings)
61 std::vector<std::string> deviceInfo =
Split(deviceString,
",");
62 if (deviceInfo.size() != 3)
64 ARMARX_WARNING <<
"Unexpected format for laser scanner device: " << deviceString
65 <<
" (split size: " << deviceInfo.size() <<
")";
71 int port = std::stoi(deviceInfo[1]);
74 device.
ip = deviceInfo[0];
76 device.
frame = deviceInfo[2];
82 catch (std::exception
const& ex)
84 ARMARX_WARNING <<
"Could not convert port to integer for laser scanner device "
85 << deviceString <<
" (port is " << deviceInfo[1] <<
") : " << ex.what();
97 debugObserver = getTopic<DebugObserverInterfacePrx>(
98 getProperty<std::string>(
"DebugObserverName").getValue());
100 connectedDevices.clear();
106 device.task =
nullptr;
110 if (!device.reconnect())
112 ARMARX_WARNING <<
"Not starting task for laser scanner with IP: " << device.ip
113 <<
", Port: " << device.port;
118 heartbeat->
signUp(device.ip,
121 {
"LaserScanner",
"Localization"},
122 "HokuyoLaserScanDevice");
124 LaserScannerInfo info;
125 info.device = device.ip;
126 info.frame = device.frame;
127 int minStep = 0, maxStep = 0;
128 urg_step_min_max(&device.urg, &minStep, &maxStep);
129 info.minAngle = urg_step2rad(&device.urg, minStep);
130 info.maxAngle = urg_step2rad(&device.urg, maxStep);
133 int lengthDataSize = urg_max_data_size(&device.urg);
134 info.stepSize = (info.maxAngle - info.minAngle) / (maxStep - minStep);
135 device.lengthData.resize(lengthDataSize);
137 device.listenerPrx = listenerPrx;
138 device.robotHealthPlugin = heartbeat;
139 device.debugObserver = debugObserver;
141 connectedDevices.push_back(info);
143 ARMARX_INFO <<
"Connected to " << device.ip <<
", " << info.frame <<
", " << info.minAngle
144 <<
", " << info.maxAngle <<
", " << info.stepSize;
148 device.task->start();
160 device.task =
nullptr;
162 if (device.connected)
164 urg_close(&device.urg);
165 device.connected =
false;
185 return laserScannerListenerProxyName;
191 return connectedDevices;
199 ARMARX_INFO <<
"Disconnecting from laser scanner with IP " <<
ip;
204 int ret = urg_open(&
urg, URG_ETHERNET,
ip.c_str(),
port);
208 ARMARX_WARNING <<
"Could not connect to laser scanner device using URG driver (IP: " <<
ip
209 <<
", Port: " <<
port <<
", Error: " <<
ret <<
")";
212 ret = urg_start_measurement(&
urg, URG_DISTANCE, URG_SCAN_INFINITY, 0);
222 <<
"Could not start measurement for laser scanner device using URG driver (IP: " <<
ip
223 <<
", Port: " <<
port <<
", Error: " <<
ret <<
")";
232 while (!
task->isStopped())
240 ARMARX_ERROR <<
"Device " <<
ip <<
" has too many consecutive errors!";
246 int lengthDataSize = urg_get_distance(&
urg,
lengthData.data(),
nullptr);
247 if (lengthDataSize < 0)
250 <<
"Could not get measurement for laser scanner (IP: " <<
ip
251 <<
", Port: " <<
port <<
", Error: " << lengthDataSize <<
")";
259 scan.reserve(lengthDataSize);
260 for (
int stepIndex = 0; stepIndex < lengthDataSize; ++stepIndex)
270 scan.push_back(step);
296 <<
", Port: " <<
port;
304 durations[
"total_ms"] =
new Variant(duration.toMilliSecondsDouble());
305 durations[
"measure_ms"] =
306 new Variant((time_measure - time_start).toMilliSecondsDouble());
307 durations[
"update_ms"] =
308 new Variant((time_update - time_measure).toMilliSecondsDouble());
309 durations[
"proxy_report_ms"] =
310 new Variant((time_proxyReport - time_update).toMilliSecondsDouble());
311 durations[
"topic_health_ms"] =
312 new Variant((time_topicHeartbeat - time_proxyReport).toMilliSecondsDouble());
314 "LaserScannerDuration_" + simox::alg::replace_all(
ip,
".",
"_"), durations);
316 if (duration.toSecondsDouble() > 0.1)
319 <<
"Total time: " << duration.toMilliSecondsDouble() <<
"ms\n"
321 << (time_measure - time_start).toMilliSecondsDouble() <<
"ms \n"
323 << (time_update - time_measure).toMilliSecondsDouble() <<
"ms\n"
325 << (time_proxyReport - time_update).toMilliSecondsDouble() <<
"ms\n"
327 << (time_topicHeartbeat - time_proxyReport).toMilliSecondsDouble()