28 #include <boost/regex.hpp>
29 #include <boost/format.hpp>
34 : device(device), connected(false), setDeviceTagScheduled(false), minimumReportIntervalMs(minimumReportIntervalMs)
38 boost::regex_search(device, match, boost::regex(
"\\w+$"));
39 this->deviceFileName = match[0];
52 jsWriter.reset(
new TextWriter(deviceFileName +
".js"));
55 sensor->stopPeriodicFrameAcquisition();
66 if (sensor->tryGetDeviceTag(tag))
68 ARMARX_INFO <<
"[" << device <<
"] Got Device Tag: " << tag;
73 ARMARX_WARNING <<
"[" << device <<
"] No device tag present using device name instead";
74 this->tag = deviceFileName;
79 jsWriter->writeLine(
str(boost::format(
"%s = {};") % deviceFileName));
80 jsWriter->writeLine(
str(boost::format(
"sensors.push(%s);") % deviceFileName));
81 jsWriter->writeLine(
str(boost::format(
"%s.device = \"%s\";") % deviceFileName % device));
82 jsWriter->writeLine(
str(boost::format(
"%s.tag = \"%s\";") % deviceFileName % tag));
83 jsWriter->writeLine(
str(boost::format(
"%s.data = [];") % deviceFileName));
89 this->mi = sensor->getMatrixInformation();
92 sensor->setAquisitionWindow(1, 1, mi.
res_x, mi.
res_y);
94 sensor->setFrontEndGain(255);
95 ARMARX_LOG <<
"[" << device <<
"] Front end gain set to " << (int)sensor->getFrontEndGain();
97 sensor->setThreshold(0);
98 ARMARX_LOG <<
"[" << device <<
"] threshold set to " << (int)sensor->getThreshold();
101 ARMARX_LOG << device <<
": Connect done, Interface=" << sensor->getInterfaceInfo();
107 sensorTask->stop(
true);
112 this->listenerPrx = listenerPrx;
117 ARMARX_LOG << device <<
": startSampling" << std::endl;
128 std::unique_lock lock(mutex);
129 setDeviceTagValue = tag;
130 setDeviceTagScheduled =
true;
133 void WeissHapticSensor::frameAcquisitionTaskLoop()
135 ARMARX_LOG << device <<
": readAndReportSensorValues";
137 ARMARX_LOG << device <<
": Interface Info: " << sensor->getInterfaceInfo();
139 ARMARX_LOG << device <<
this <<
": startPeriodicFrameAcquisition";
140 sensor->startPeriodicFrameAcquisition(0);
147 while (!sensorTask->isStopped())
158 std::vector<float> sensorValues;
162 sensorValues.push_back(
data.data->at(i));
165 slidingMedian.addEntry(sensorValues);
168 std::vector<float> filteredSensorValues = slidingMedian.getMedian();
170 for (
int y = 0; y < mi.
res_y; y++)
172 for (
int x = 0; x < mi.
res_x; x++)
174 (*matrix)(y, x) = filteredSensorValues.at(y * mi.
res_x + x);
194 writeMatrixToJs(matrix, nowTimestamp);
198 if (
interval.toMilliSeconds() >= minimumReportIntervalMs)
200 listenerPrx->reportSensorValues(device, tag, matrix, nowTimestamp);
206 ARMARX_WARNING <<
"Caught ChecksumErrorException on " << device <<
", skipping frame";
209 if (setDeviceTagScheduled)
211 std::unique_lock lock(mutex);
212 setDeviceTagScheduled =
false;
214 ARMARX_INFO <<
"[" << device <<
"] Stopping periodic frame aquisition to set new device tag";
215 sensor->stopPeriodicFrameAcquisition();
217 ARMARX_IMPORTANT <<
"[" << device <<
"] Setting new device tag '" << setDeviceTagValue <<
"'";
218 sensor->setDeviceTag(setDeviceTagValue);
219 this->tag = setDeviceTagValue;
221 ARMARX_INFO <<
"[" << device <<
"] Starting periodic frame aquisition";
222 sensor->startPeriodicFrameAcquisition(0);
226 ARMARX_LOG << device <<
": stopPeriodicFrameAcquisition";
227 sensor->stopPeriodicFrameAcquisition();
233 if (jsWriter != NULL)
235 jsWriter->writeLine(
str(boost::format(
"%s.data.push([%i, %s]);") % deviceFileName % timestamp->getTimestamp() % matrix->toJsonRowMajor()));