27 #include <boost/format.hpp>
28 #include <boost/regex.hpp>
37 setDeviceTagScheduled(false),
38 minimumReportIntervalMs(minimumReportIntervalMs)
43 boost::regex_search(device, match, boost::regex(
"\\w+$"));
44 this->deviceFileName = match[0];
58 jsWriter.reset(
new TextWriter(deviceFileName +
".js"));
61 sensor->stopPeriodicFrameAcquisition();
72 if (sensor->tryGetDeviceTag(tag))
74 ARMARX_INFO <<
"[" << device <<
"] Got Device Tag: " << tag;
79 ARMARX_WARNING <<
"[" << device <<
"] No device tag present using device name instead";
80 this->tag = deviceFileName;
85 jsWriter->writeLine(
str(boost::format(
"%s = {};") % deviceFileName));
86 jsWriter->writeLine(
str(boost::format(
"sensors.push(%s);") % deviceFileName));
87 jsWriter->writeLine(
str(boost::format(
"%s.device = \"%s\";") % deviceFileName % device));
88 jsWriter->writeLine(
str(boost::format(
"%s.tag = \"%s\";") % deviceFileName % tag));
89 jsWriter->writeLine(
str(boost::format(
"%s.data = [];") % deviceFileName));
95 this->mi = sensor->getMatrixInformation();
98 sensor->setAquisitionWindow(1, 1, mi.
res_x, mi.
res_y);
100 sensor->setFrontEndGain(255);
101 ARMARX_LOG <<
"[" << device <<
"] Front end gain set to " << (int)sensor->getFrontEndGain();
103 sensor->setThreshold(0);
104 ARMARX_LOG <<
"[" << device <<
"] threshold set to " << (int)sensor->getThreshold();
107 ARMARX_LOG << device <<
": Connect done, Interface=" << sensor->getInterfaceInfo();
114 sensorTask->stop(
true);
120 this->listenerPrx = listenerPrx;
126 ARMARX_LOG << device <<
": startSampling" << std::endl;
139 std::unique_lock lock(mutex);
140 setDeviceTagValue = tag;
141 setDeviceTagScheduled =
true;
145 WeissHapticSensor::frameAcquisitionTaskLoop()
147 ARMARX_LOG << device <<
": readAndReportSensorValues";
149 ARMARX_LOG << device <<
": Interface Info: " << sensor->getInterfaceInfo();
151 ARMARX_LOG << device <<
this <<
": startPeriodicFrameAcquisition";
152 sensor->startPeriodicFrameAcquisition(0);
160 while (!sensorTask->isStopped())
171 std::vector<float> sensorValues;
175 sensorValues.push_back(
data.data->at(i));
178 slidingMedian.addEntry(sensorValues);
181 std::vector<float> filteredSensorValues = slidingMedian.getMedian();
183 for (
int y = 0; y < mi.
res_y; y++)
185 for (
int x = 0; x < mi.
res_x; x++)
187 (*matrix)(y, x) = filteredSensorValues.at(y * mi.
res_x + x);
207 writeMatrixToJs(matrix, nowTimestamp);
211 if (
interval.toMilliSeconds() >= minimumReportIntervalMs)
213 listenerPrx->reportSensorValues(device, tag, matrix, nowTimestamp);
219 ARMARX_WARNING <<
"Caught ChecksumErrorException on " << device <<
", skipping frame";
222 if (setDeviceTagScheduled)
224 std::unique_lock lock(mutex);
225 setDeviceTagScheduled =
false;
228 <<
"] Stopping periodic frame aquisition to set new device tag";
229 sensor->stopPeriodicFrameAcquisition();
231 ARMARX_IMPORTANT <<
"[" << device <<
"] Setting new device tag '" << setDeviceTagValue
233 sensor->setDeviceTag(setDeviceTagValue);
234 this->tag = setDeviceTagValue;
236 ARMARX_INFO <<
"[" << device <<
"] Starting periodic frame aquisition";
237 sensor->startPeriodicFrameAcquisition(0);
241 ARMARX_LOG << device <<
": stopPeriodicFrameAcquisition";
242 sensor->stopPeriodicFrameAcquisition();
249 if (jsWriter != NULL)
251 jsWriter->writeLine(
str(boost::format(
"%s.data.push([%i, %s]);") % deviceFileName %
252 timestamp->getTimestamp() % matrix->toJsonRowMajor()));