9 #include <yarp/os/LogStream.h>
10 #include <yarp/os/Thread.h>
11 #include <yarp/os/Time.h>
12 #include <yarp/os/Stamp.h>
19 using namespace yarp::os;
21 using namespace yarp::sig;
24 #define M_PI 3.14159265358979323846264338328
25 #define CTRL_RAD2DEG (180.0/M_PI)
26 #define CTRL_DEG2RAD (M_PI/180.0)
39 _bStreamStarted=
false;
44 _last=
new double [12];
54 _bStreamStarted=
false;
79 float euler_data[3] = {0};
80 float accel_data[3] = {0};
81 float gyro_data [3] = {0};
82 float magn_data [3] = {0};
86 while (!Thread::isStopping ())
89 received = mtcomm.readDataMessage (
data, datalen);
99 std::lock_guard<std::mutex> lck(_semaphore);
102 _last[0] = euler_data[0];
103 _last[1] = euler_data[1];
104 _last[2] = euler_data[2];
106 _last[3] = accel_data[0];
107 _last[4] = accel_data[1];
108 _last[5] = accel_data[2];
115 _last[9] = magn_data[0];
116 _last[10] = magn_data[1];
117 _last[11] = magn_data[2];
134 XSensMTx::XSensMTx() : system_resources{nullptr},
136 m_sensorName{
"sensor_imu_xsens"},
137 m_frameName{
"sensor_imu_xsens"}
144 if (system_resources!=0)
158 std::lock_guard<std::mutex> lck(d.
_semaphore);
161 for (
int i = 0; i < nchannels; i++)
181 printf(
"Not implemented yet\n");
185 bool XSensMTx::start()
195 bool XSensMTx::stop()
212 par.
comPort = config.check (
"serial", Value(11),
213 "numeric identifier of comport").asInt32();
215 par.
comPortString = config.check(
"serial",Value(
"/dev/ttyUSB0"),
216 "device name of comport").asString().c_str();
218 if (config.check(
"sensor_name") && config.find(
"sensor_name").isString())
220 m_sensorName = config.find(
"sensor_name").asString();
222 if (config.check(
"frame_name") && config.find(
"frame_name").isString())
224 m_frameName = config.find(
"frame_name").asString();
232 if (system_resources!=0)
243 fprintf(stderr,
"Failed to open com port %d\n",
251 fprintf(stderr,
"Failed to open com port %s\n",
259 unsigned long tmpOutputMode, tmpOutputSettings;
260 unsigned short tmpDataLength;
264 for (count = 0; count <10; count++ )
268 printf (
"MRCHECK Unable to connect to XSensMtX device, attempt %d.\n", count);
269 yarp::os::Time::delay(0.010);
276 printf (
"XSensMtX init check: no device connected.\n");
280 printf (
"XSensMtX init check: device ok.\n");
282 unsigned short numDevices;
286 printf (
"MTi / MTx has not been detected\nCould not get device mode.\n");
288 printf (
"Not just MTi / MTx connected to Xbus, %d devices found.\nCould not get all device modes.\n", numDevices);
297 printf (
"Sorry, this driver only talks to one MTx device.\n");
304 printf (
"Could not set device mode(s)\n");
312 return XSensMTx::start();
318 if (system_resources==0)
354 return genericGetStatus(sens_index);
359 return genericGetSensorName(sens_index, name);
364 return genericGetFrameName(sens_index, frameName);
381 return genericGetStatus(sens_index);
386 return genericGetSensorName(sens_index, name);
391 return genericGetFrameName(sens_index, frameName);
406 return genericGetStatus(sens_index);
411 return genericGetSensorName(sens_index, name);
416 return genericGetFrameName(sens_index, frameName);
421 return genericGetMeasure(sens_index, rpy, timestamp,
rpyStartIdx);
431 return genericGetStatus(sens_index);
436 return genericGetSensorName(sens_index, name);
441 return genericGetFrameName(sens_index, frameName);
448 yarp::dev::MAS_status XSensMTx::genericGetStatus(
size_t sens_index)
const
452 yError() <<
"xsens: sens_index must be equal to 0, since there is only one sensor in consideration";
453 return yarp::dev::MAS_status::MAS_ERROR;
456 return yarp::dev::MAS_status::MAS_OK;
459 bool XSensMTx::genericGetSensorName(
size_t sens_index, std::string& name)
const
463 yError() <<
"xsens: sens_index must be equal to 0, since there is only one sensor in consideration";
471 bool XSensMTx::genericGetFrameName(
size_t sens_index, std::string& frameName)
const
475 yError() <<
"xsens: sens_index must be equal to 0, since there is only one sensor in consideration";
479 frameName = m_frameName;
484 bool XSensMTx::genericGetMeasure(
size_t sens_index, yarp::sig::Vector &
out,
double ×tamp,
size_t startIdx)
const {
488 yError() <<
"xsens: sens_index must be equal to 0, since there is only one sensor in consideration";
492 auto &d=
RES(system_resources);
494 std::lock_guard<std::mutex> lck(d.
_semaphore);
#define OUTPUTMODE_ORIENT
#define OUTPUTSETTINGS_ORIENTMODE_EULER
#define VALUE_ORIENT_EULER
#define MID_GOTOMEASUREMENT
XSensMTxResources & RES(void *res)
constexpr size_t gyroStartIdx
constexpr size_t accelStartIdx
constexpr size_t magnStartIdx
constexpr size_t rpyStartIdx
short setDeviceMode(unsigned long OutputMode, unsigned long OutputSettings, const unsigned char bid=BID_MASTER)
short openPort(const int portNumber, const unsigned long baudrate=PBR_115K2, const unsigned long inqueueSize=4096, const unsigned long outqueueSize=1024)
short getMode(unsigned long &OutputMode, unsigned long &OutputSettings, unsigned short &dataLength, const unsigned char bid=BID_MASTER)
short getDeviceMode(unsigned short *numDevices=NULL)
short writeMessage(const unsigned char mid, const unsigned long dataValue=0, const unsigned char dataValueLen=0, const unsigned char bid=BID_MASTER)
yarp::os::Stamp _lastStamp
virtual ~XSensMTxResources()
bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector &rpy, double ×tamp) const override
Get orientation sensor measurements.
bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
Get three axis gyroscope measurements.
bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame in which three axis gyroscope measurements are expressed.
size_t getNrOfThreeAxisMagnetometers() const override
Get the number of three axis magnetometers in the device.
size_t getNrOfThreeAxisGyroscopes() const override
Get the number of three axis gyroscopes in the device.
yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const override
Get the status of three axis magnetometer.
bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
Get three axis linear accelerometer measurements.
bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const override
Get the name of three axis magnetometer.
size_t getNrOfThreeAxisLinearAccelerometers() const override
Get the number of three axis linear accelerometers in the device.
bool getChannels(int *nc) override
bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame in which three axis linear accelerometer measurements are expressed.
yarp::os::Stamp getLastInputStamp() override
bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override
Get the name of three axis linear accelerometer.
bool read(yarp::sig::Vector &out) override
bool open(yarp::os::Searchable &config) override
bool getOrientationSensorName(size_t sens_index, std::string &name) const override
Get the name of orientation sensor.
size_t getNrOfOrientationSensors() const override
Get the number of orientation sensors in the device.
bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const override
Get three axis magnetometer measurements.
bool calibrate(int ch, double v) override
yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override
Get the status of three axis gyroscope.
bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override
Get the name of three axis gyroscope.
yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override
Get the status of three axis linear accelerometer.
bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame in which orientation sensor measurements are expressed.
bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame in which three axis magnetometer measurements are expressed.
yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override
Get the status of orientation sensor.
std::string comPortString