38 std::string calibrationFilePath = getProperty<std::string>(
"CalibrationFilePath").getValue();
41 throw LocalException(
"Could not find calibration file '") << calibrationFilePath <<
"'";
43 ARMARX_INFO <<
"reading config " << calibrationFilePath;
47 auto findDaqNode = [&](std::string serialNumber)
51 if (daqNode.attribute_value(
"serialNumber") == serialNumber)
59 offeringTopic(getProperty<std::string>(
"OptoForceTopicName").getValue());
61 OPort* portlist = ports.listPorts(
true);
62 ARMARX_INFO <<
"Found " << ports.getLastSize() <<
" Optoforce device(s).";
65 portlist = ports.listPorts(
true);
66 ARMARX_INFO <<
"Found " << ports.getLastSize() <<
" Optoforce device(s):";
68 for (
int i = 0; i < ports.getLastSize(); i++)
70 std::string deviceName(portlist[i].name);
71 std::string serialNumber(portlist[i].serialNumber);
72 ARMARX_INFO <<
"Found DAQ: deviceName='" << deviceName <<
"', serialNumber='"
73 << serialNumber <<
"'";
77 throw LocalException(
"Could not find config node for device deviceName='")
78 << deviceName <<
"', serialNumber='" << serialNumber <<
"'";
80 DaqWrapperPtr daqPtr(
new DaqWrapper(deviceName, serialNumber, daqNode));
81 daqList.push_back(daqPtr);
84 ARMARX_INFO <<
"number of ports: " << ports.getLastSize();
86 for (
int i = 0; i < ports.getLastSize(); ++i)
88 const DaqWrapperPtr& daq = daqList.at(i);
90 daq->daq.open(portlist[i]);
92 daq->checkSensorCount();
101 topicPrx = getTopic<OptoForceUnitListenerPrx>(
102 getProperty<std::string>(
"OptoForceTopicName").getValue());
112 OptoForceUnitListenerPrx batchPrx = topicPrx->ice_batchOneway();
115 while (readTask->isRunning())
117 bool flushNeeded =
false;
119 for (
const DaqWrapperPtr& daqPtr : daqList)
122 int size = daqPtr->daq.readAll(pa,
false);
133 if (daqPtr->daq.getSize() > 0)
138 int sensorCount = daqPtr->daq.getSensorSize();
140 std::vector<std::array<float, 3>>
data;
141 data.resize(sensorCount);
143 for (
int i = 0; i < sensorCount; i++)
145 if (!daqPtr->enableFlags.at(i))
149 for (
int n = 0; n < size; n++)
151 float countsPerN = daqPtr->countsPerN.at(i);
152 float x = pa[i * size + n].x / countsPerN - daqPtr->offsets.at(i).at(0);
153 float y = pa[i * size + n].y / countsPerN - daqPtr->offsets.at(i).at(1);
154 float z = pa[i * size + n].z / countsPerN - daqPtr->offsets.at(i).at(2);
156 batchPrx->reportSensorValues(daqPtr->deviceName +
":" +
to_string(i),
157 daqPtr->sensorNames.at(i),
163 data.at(i) = {x, y, z};
170 recordingFile <<
"{\"timestamp\":\"" << now.toDateTime() <<
"\",";
171 recordingFile <<
"\"daq\":\"" << daqPtr->serialNumber <<
"\",\"data\":[";
173 for (
int i = 0; i < sensorCount; i++)
175 if (!daqPtr->enableFlags.at(i))
181 recordingFile <<
",";
184 recordingFile <<
"[" <<
data.at(i).at(0) <<
"," <<
data.at(i).at(1) <<
","
185 <<
data.at(i).at(2) <<
"]";
187 recordingFile <<
"]}\n";
188 recordingFile.flush();
192 if (isRecording && stopRecordingFlag)
194 recordingFile.close();
197 stopRecordingFlag =
false;
200 batchPrx->ice_flushBatchRequests();
227 OptoForceUnit::DaqWrapper::DaqWrapper(
const std::string& deviceName,
228 const std::string& serialNumber,
230 deviceName(deviceName), serialNumber(serialNumber)
235 float counts_at_nc = sensorNode.attribute_as_float(
"counts_at_nc");
236 float nominalCapacity = sensorNode.attribute_as_float(
"nominalCapacity");
237 std::string sensorName =
238 sensorNode.attribute_value_or_default(
"name", serialNumber +
"-" +
to_string(i));
239 countsPerN.push_back(counts_at_nc / nominalCapacity);
240 sensorNames.push_back(sensorName);
241 enableFlags.push_back(
242 sensorNode.attribute_as_optional_bool(
"enabled",
"true",
"false",
true));
243 offsets.push_back({sensorNode.attribute_as_float(
"offsetX"),
244 sensorNode.attribute_as_float(
"offsetY"),
245 sensorNode.attribute_as_float(
"offsetZ")});
251 OptoForceUnit::DaqWrapper::printInfo()
253 SensorConfig config = daq.getConfig();
254 int state = config.getState();
255 int speed = config.getSpeed();
256 int filter = config.getFilter();
257 int mode = config.getMode();
271 OptoForceUnit::DaqWrapper::checkSensorCount()
273 if ((
int)countsPerN.size() != daq.getSensorSize())
275 throw LocalException(
"Sensor count mismatch. Configured: ")
276 << ((int)countsPerN.size()) <<
" found: " << daq.getSensorSize();
278 ARMARX_INFO_S <<
"Configured: " << ((int)countsPerN.size()) <<
" found: " << daq.getSensorSize()
286 recordingFile.open(filepath);
293 stopRecordingFlag =
true;