12#include <yarp/os/Log.h>
13#include <yarp/os/LogStream.h>
19#include "EoAnalogSensors.h"
20#include "EoProtocol.h"
21#include "EoProtocolAS.h"
22#include "EoProtocolMN.h"
25#pragma warning(once : 4355)
29using namespace yarp::os;
34 yInfo() <<
"MultipleFTSensors has been created";
35 device_ = std::make_shared<yarp::dev::embObjDevPrivData>(
"embObjMultipleFTsensors");
54 yInfo() <<
"embObjMultipleFTsensors::open(): preparing ETH resource";
55 if (!
device_->prerareEthService(config,
this))
58 yInfo() <<
device_->getBoardInfo() <<
" embObjMultipleFTsensors::open(): browsing xml files which describe the service";
60 if (!parser.
parse(config))
62 yError() <<
device_->getBoardInfo() <<
"open() fails to parse xml... cannot continue ";
66 yInfo() <<
device_->getBoardInfo() <<
" embObjMultipleFTsensors::open(): verify the presence of the board and if its protocol version is correct";
67 if (!
device_->res->verifyEPprotocol(eoprot_endpoint_analogsensors))
69 yError() <<
device_->getBoardInfo() <<
" open() fails to verifyEPprotocol... cannot continue ";
74 yInfo() <<
device_->getBoardInfo() <<
" embObjMultipleFTsensors::open(): verify and activate the FT service";
75 eOmn_serv_parameter_t ftData;
76 ftData.configuration.type = eomn_serv_AS_ft;
77 ftData.configuration.diagnosticsmode = eomn_serv_diagn_mode_NONE;
78 ftData.configuration.diagnosticsparam = 0;
79 parser.
toEomn(ftData.configuration.data.as.ft);
80 if (!
device_->res->serviceVerifyActivate(eomn_serv_category_ft, &ftData, 5.0))
82 yError() <<
device_->getBoardInfo() <<
" open() fails to serviceVerifyActivate... cannot continue ";
87 yInfo() <<
device_->getBoardInfo() <<
" embObjMultipleFTsensors::open(): configure the FT service";
90 yError() <<
device_->getBoardInfo() <<
" open() fails to sendConfig2boards... cannot continue";
95 yInfo() <<
device_->getBoardInfo() <<
" embObjMultipleFTsensors::open(): impose the network variable which the ETH bord must stream up";
98 yError() <<
device_->getBoardInfo() <<
" open() fails to initRegulars... cannot continue";
103 yInfo() <<
device_->getBoardInfo() <<
" embObjMultipleFTsensors::open(): start the FT service";
104 if (!
device_->res->serviceStart(eomn_serv_category_ft))
106 yError() <<
device_->getBoardInfo() <<
" open() fails to serviceStart... cannot continue";
114 yDebug() <<
device_->getBoardInfo() <<
" open() correctly starts service";
118 yInfo() <<
device_->getBoardInfo() <<
" embObjMultipleFTsensors::open(): start streaming of FT data";
121 yError() <<
device_->getBoardInfo() <<
" open() fails to sendStart2boards... cannot continue";
134 for (
const auto &[
id,
data] : ftInfos)
136 eOprotID32_t id32 = eo_prot_ID32dummy;
137 eOas_ft_config_t cfg;
138 cfg.ftperiod =
data.ftAcquisitionRate;
139 cfg.temperatureperiod =
data.temperatureAcquisitionRate / 1000;
140 cfg.mode =
data.useCalibration;
141 cfg.calibrationset = 0;
142 id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, index, eoprot_tag_as_ft_config);
146 yError() <<
device_->getBoardInfo() <<
" sendConfig2boards() while try to configure ftPeriod=" << cfg.ftperiod;
152 yDebug() <<
device_->getBoardInfo() <<
" sendConfig2boards() correctly configured boards with ftPeriod=" << cfg.ftperiod;
156 eOprotIndex_t eoprotIndex = eoprot_ID2index(id32);
157 std::unique_lock<std::shared_mutex> lck(
mutex_);
165 eOprotID32_t id32 = eo_prot_ID32dummy;
169 const auto &ftInfos = parser.
getFtInfo();
171 for (
const auto &[
id,
data] : ftInfos)
173 id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, index, eoprot_tag_as_ft_cmmnds_enable);
177 yError() <<
device_->getBoardInfo() <<
" sendStart2boards() while try to enable the boards transmission";
183 yDebug() <<
device_->getBoardInfo() <<
" sendStart2boards() correctly enabled the boards transmission";
194 vector<eOprotID32_t> id32v;
195 eOprotID32_t id32 = eo_prot_ID32dummy;
197 const auto &ftInfos = parser.
getFtInfo();
199 for (
const auto &[
id,
data] : ftInfos)
201 id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, index, eoprot_tag_as_ft_status_timedvalue);
202 id32v.push_back(id32);
208 yError() <<
device_->getBoardInfo() <<
" initRegulars() fails to add its variables to regulars: cannot proceed any further";
214 yDebug() <<
device_->getBoardInfo() <<
" initRegulars() added" << id32v.size() <<
"regular rops ";
216 for (
size_t r = 0; r < id32v.size(); r++)
218 uint32_t item = id32v.at(r);
219 eoprot_ID2information(item, nvinfo,
sizeof(nvinfo));
220 yDebug() <<
device_->getBoardInfo() <<
"\t it added regular rop for" << nvinfo;
237 eOprotIndex_t eoprotIndex = eoprot_ID2index(id32);
240 yError() <<
device_->getBoardInfo() <<
" update() index too big";
244 eOprotEntity_t entity = eoprot_ID2entity(id32);
245 if (entity != eoprot_entity_as_ft)
247 yError() <<
device_->getBoardInfo() <<
" update() wrong entity";
251 eOprotTag_t tag = eoprot_ID2tag(id32);
252 if (tag != eoprot_tag_as_ft_status_timedvalue)
254 yError() <<
device_->getBoardInfo() <<
" update() wrong tag";
258 eOas_ft_timedvalue_t *
data = (eOas_ft_timedvalue_t *)rxdata;
264 std::unique_lock<std::shared_mutex> lck(
mutex_);
266 for (
int index = 0; index < eoas_ft_6axis; ++index)
294 std::shared_lock<std::shared_mutex> lck(
mutex_);
298 yError() <<
device_->getBoardInfo() <<
" getSixAxisForceTorqueSensorMeasure() fails data for index:" << sensorIndex <<
" not found";
325 std::shared_lock<std::shared_mutex> lck(
mutex_);
332 std::shared_lock<std::shared_mutex> lck(
mutex_);
349 std::shared_lock<std::shared_mutex> lck(
mutex_);
356 std::shared_lock<std::shared_mutex> lck(
mutex_);
366 std::shared_lock<std::shared_mutex> lck(
mutex_);
370 yError() <<
device_->getBoardInfo() <<
" getTemperatureSensorMeasure() fails data for index:" << sensorIndex <<
" not found";
398 yError() <<
device_->getBoardInfo() <<
" update timeout for index:" << eoprot_ID2index(id32);
400 masStatus_[eoprot_ID2index(id32)] = MAS_TIMEOUT;
411 return yarp::os::Time::now();
bool parse(const yarp::os::Searchable &config)
std::map< std::string, FtInfo > & getFtInfo()
bool toEomn(eOmn_serv_config_data_as_ft_t &out) const
virtual bool setcheckRemoteValue(const eOprotID32_t id32, void *value, const unsigned int retries=10, const double waitbeforecheck=0.001, const double timeout=0.050)=0
virtual bool serviceSetRegulars(eOmn_serv_category_t category, vector< eOprotID32_t > &id32vector, double timeout=0.500)=0
std::vector< yarp::dev::MAS_status > masStatus_
virtual bool initialised()
virtual bool getTemperatureSensorFrameName(size_t sensorindex, std::string &frameName) const override
bool checkUpdateTimeout(eOprotID32_t id32, eOabstime_t current)
virtual yarp::dev::MAS_status getSixAxisForceTorqueSensorStatus(size_t sensorindex) const override
bool initRegulars(ServiceParserMultipleFt &parser, eth::AbstractEthResource *deviceRes)
bool open(yarp::os::Searchable &config)
static constexpr bool useBoardTimeFlag_
std::map< eOprotID32_t, FtData > ftSensorsData_
bool sendStart2boards(ServiceParserMultipleFt &parser, eth::AbstractEthResource *deviceRes)
virtual eth::iethresType_t type()
virtual bool getTemperatureSensorMeasure(size_t sensorindex, double &out, double ×tamp) const override
virtual size_t getNrOfTemperatureSensors() const override
double calculateBoardTime(eOabstime_t current)
virtual bool getSixAxisForceTorqueSensorFrameName(size_t sensorindex, std::string &frameName) const override
static constexpr bool checkUpdateTimeoutFlag_
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)
embObjMultipleFTsensors()
std::map< eOprotID32_t, TemperatureData > temperaturesensordata_
double firstYarpTimestamp_
virtual size_t getNrOfSixAxisForceTorqueSensors() const override
static constexpr eOabstime_t updateTimeout_
bool sendConfig2boards(ServiceParserMultipleFt &parser, eth::AbstractEthResource *deviceRes)
virtual bool getSixAxisForceTorqueSensorMeasure(size_t sensorindex, yarp::sig::Vector &out, double ×tamp) const override
std::shared_ptr< yarp::dev::embObjDevPrivData > device_
eOabstime_t firstCanTimestamp_
std::map< eOprotID32_t, eOabstime_t > timeoutUpdate_
virtual bool getSixAxisForceTorqueSensorName(size_t sensorindex, std::string &name) const override
~embObjMultipleFTsensors()
virtual yarp::dev::MAS_status getTemperatureSensorStatus(size_t sensorindex) const override
virtual bool getTemperatureSensorName(size_t sensorindex, std::string &name) const override
static constexpr int ftChannels_
Copyright (C) 2008 RobotCub Consortium.