11 #include "EoProtocolAS.h"
13 #include "EOconstarray.h"
21 memset(canpositionmap, 0xff,
sizeof(canpositionmap));
28 std::uint8_t numberof[eoas_sensors_numberof];
29 memset(numberof, 0,
sizeof(numberof));
33 const eOas_inertial3_arrayof_descriptors_t*
tmp = &servCfg.
ethservice.configuration.data.as.inertial3.arrayofdescriptor;
34 EOconstarray* array = eo_constarray_Load(
reinterpret_cast<const EOarray*
>(
tmp));
35 uint8_t size = eo_constarray_Size(array);
36 for(uint8_t i=0; i<size; i++)
38 eOas_inertial3_descriptor_t *des = (eOas_inertial3_descriptor_t*)eo_constarray_At(array, i);
42 if(des->typeofsensor < eoas_sensors_numberof)
44 if(des->on.any.place == eobrd_place_can)
46 canpositionmap[des->typeofsensor][des->on.can.port][des->on.can.addr] = numberof[des->typeofsensor];
47 numberof[des->typeofsensor]++;
49 else if(des->on.any.place == eobrd_place_eth)
51 ethpositionmap[des->typeofsensor] = numberof[des->typeofsensor];
52 numberof[des->typeofsensor]++;
66 uint8_t canbus, canaddress;
67 type =
static_cast<eOas_sensor_t
>(
data->typeofsensor);
68 if (type != eoas_gyros_st_l3g4200d) {
72 if(
data->typeofsensor >= eoas_sensors_numberof)
76 if(type == eoas_gyros_st_l3g4200d) {
77 index = ethpositionmap[
data->typeofsensor];
80 index = canpositionmap[
data->typeofsensor][canbus][canaddress];
83 return (0xff == index) ? false :
true;
89 if(type == eoas_gyros_st_l3g4200d) {
92 if(canbus >= eOcanports_number)
100 index = canpositionmap[type][canbus][canaddress];
101 return (0xff == index) ? false :
true;
109 auto type =
static_cast<eOas_sensor_t
>(
data->typeofsensor);
111 if (eoas_gyros_st_l3g4200d == type) {
114 canbus =
data->id >> 4;
116 if(canbus >= eOcanports_number)
121 canaddress =
data->id & 0x0f;
129 errorstring =
"embObjIMU";
131 mysens.resize(eoas_sensors_numberof);
132 for(
int t=0; t<eoas_sensors_numberof; t++)
133 { mysens[t].resize(0); }
139 errorstring = error_string;
141 const eOas_inertial3_arrayof_descriptors_t*
tmp = &servCfg.
ethservice.configuration.data.as.inertial3.arrayofdescriptor;
142 EOconstarray* array = eo_constarray_Load(
reinterpret_cast<const EOarray*
>(
tmp));
143 uint8_t size = eo_constarray_Size(array);
144 for(uint8_t i=0; i<size; i++)
146 eOas_inertial3_descriptor_t *des = (eOas_inertial3_descriptor_t*)eo_constarray_At(array, i);
150 if(des->typeofsensor < eoas_sensors_numberof)
154 newSensor.
name = servCfg.
id[i];
160 switch (des->typeofsensor) {
172 if(des->typeofsensor == eoas_imu_qua)
173 newSensor.
values.resize(4);
175 newSensor.
values.resize(3);
177 mysens[des->typeofsensor].push_back(newSensor);
185 yError() << errorstring.c_str() <<
"Out of Range error: " << oor.what();
191 std::lock_guard<std::mutex> lck (mutex);
192 return mysens[type].size();
199 std::lock_guard<std::mutex> lck (mutex);
202 return mysens[type].at(sens_index).state;
204 catch (
const std::out_of_range& oor)
207 return yarp::dev::MAS_ERROR;
215 std::lock_guard<std::mutex> lck (mutex);
216 name = mysens[type].at(sens_index).name;
219 catch (
const std::out_of_range& oor)
229 std::lock_guard<std::mutex> lck (mutex);
230 frameName = mysens[type].at(sens_index).framename;
233 catch (
const std::out_of_range& oor)
243 { std::lock_guard<std::mutex> lck (mutex);
244 out = mysens[type].at(sens_index).values;
245 timestamp = mysens[type].at(sens_index).timestamp;
247 catch (
const std::out_of_range& oor)
257 std::lock_guard<std::mutex> lck (mutex);
261 info->values[0] = newdata->x / info->conversionFactor;
262 info->values[1] = newdata->y / info->conversionFactor;
263 info->values[2] = newdata->z / info->conversionFactor;
264 info->timestamp = yarp::os::Time::now();
272 std::lock_guard<std::mutex> lck (mutex);
279 case eoas_accel_mtb_int:
280 case eoas_accel_mtb_ext:
281 info->state = status.calib.acc;
285 info->state = status.calib.mag;
289 case eoas_gyros_st_l3g4200d:
290 case eoas_gyros_mtb_ext:
291 info->state = status.calib.gyr;
296 info->state = status.calib.acc + status.calib.gyr + status.calib.mag;
299 info->state = status.general;
319 yError() <<
"embObjIMU" <<
getBoardInfo() <<
": missing some configuration parameter. Check logs and your config file.";
325 eOas_inertial3_config_t cfg ={0};
329 for(
size_t i=0; i<servCfg.
inertials.size(); i++)
331 eo_common_word_bitset(&cfg.enabled, i);
334 eOprotID32_t id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_inertial3, 0, eoprot_tag_as_inertial3_config);
337 yError() <<
"embObjIMU" <<
getBoardInfo() <<
"FATAL: sendConfing2board() had an error while calling setcheckRemoteValue() for config the board";
344 yError() <<
"embObjIMU" <<
getBoardInfo() <<
"sendConfing2board() correctly configured enabled sensors with period" << cfg.datarate;
354 vector<eOprotID32_t> id32v(0);
355 eOprotID32_t id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_inertial3, 0, eoprot_tag_as_inertial3_status);
357 id32v.push_back(id32);
361 yError() <<
"embObjIMU" <<
getBoardInfo() <<
"initRegulars() fails to add its variables to regulars: cannot proceed any further";
368 yError() <<
"embObjIMU" <<
getBoardInfo() <<
"initRegulars() added" << id32v.size() <<
" regular rops to the board";
370 for (
size_t r = 0; r<id32v.size(); r++)
372 uint32_t item = id32v.at(r);
373 eoprot_ID2information(item, nvinfo,
sizeof(nvinfo));
374 yDebug() <<
"\t it added regular rop for" << nvinfo;
391 return yarp::dev::MAS_OK;
395 #undef DEBUG_PRINT_STATE
396 #undef DEBUG_PRINT_STATE_FULL
400 static int count[eoas_sensors_numberof]={0};
406 #if defined(DEBUG_PRINT_STATE)
414 yError() <<
getBoardInfo() <<
"sensor " << eoas_sensor2string(type) <<
"is not calibrated because its calib status reg is =" << eo_state<<
"(reg: 0 = not calib, 3 = fully calib)";
416 #if defined(DEBUG_PRINT_STATE_FULL)
417 else if(1 == eo_state)
419 yWarning() <<
getBoardInfo() <<
"sensor " << eoas_sensor2string(type) <<
"is poorly calibrated because its calib status reg is =" << eo_state<<
"(reg: 0 = not calib, 3 = fully calib)";
423 yInfo() <<
getBoardInfo() <<
"sensor " << eoas_sensor2string(type) <<
"is calibrated because its calib status reg is =" << eo_state<<
"(reg: 0 = not calib, 3 = fully calib)";
432 yError() <<
getBoardInfo() <<
"sensor " << eoas_sensor2string(type) <<
"is not calibrated because sum of the 3 calib status regs is =" << eo_state<<
"(reg: 0 = not calib, 3=fully calib)";
434 #if defined(DEBUG_PRINT_STATE_FULL)
435 else if(eo_state < 6)
437 yWarning() <<
getBoardInfo() <<
"sensor " << eoas_sensor2string(type) <<
"is poorly calibrated because sum of the 3 calib status regs is =" << eo_state<<
"(reg: 0 = not calib, 3 = fully calib)";
441 yInfo() <<
getBoardInfo() <<
"sensor " << eoas_sensor2string(type) <<
"is calibrated because sum of the 3 calib status regs is =" << eo_state<<
"(reg: 0 = not calib, 3 = fully calib)";
bool parseService(yarp::os::Searchable &config, servConfigMais_t &maisconfig)
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
bool init(servConfigImu_t &servCfg)
bool getIndex(const eOas_inertial3_data_t *data, uint8_t &index, eOas_sensor_t &type)
static bool getCanAddress(const eOas_inertial3_data_t *data, uint8_t &canbus, uint8_t &canaddress)
bool outOfRangeErrorHandler(const std::out_of_range &oor) const
void init(servConfigImu_t &servCfg, string error_string)
bool getSensorFrameName(size_t sens_index, eOas_sensor_t type, std::string &frameName) const
bool getSensorMeasure(size_t sens_index, eOas_sensor_t type, yarp::sig::Vector &out, double ×tamp) const
bool getSensorName(size_t sens_index, eOas_sensor_t type, std::string &name) const
bool updateStatus(eOas_sensor_t type, uint8_t index, eOas_inertial3_sensorstatus_t &status)
bool update(eOas_sensor_t type, uint8_t index, eOas_inertial3_data_t *newdata)
size_t getNumOfSensors(eOas_sensor_t type) const
uint8_t getSensorStatus(size_t sens_index, eOas_sensor_t type) const
std::string getBoardInfo(void) const
eth::AbstractEthResource * res
void debugPrintStateNotOK(eOas_sensor_t type, uint8_t eo_state)
yarp::dev::MAS_status sensorState_eo2yarp(eOas_sensor_t type, uint8_t eo_state)
eo_imu_privData(std::string name)
bool fromConfig(yarp::os::Searchable &config, servConfigImu_t &servCfg)
bool sendConfing2board(servConfigImu_t &servCfg)
eOmn_serv_parameter_t ethservice
std::vector< eOas_inertial3_descriptor_t > inertials
std::vector< std::string > id
std::vector< std::string > sensorName