23 #if MRPT_HAS_xSENS_MT3 24 #include "xSens_MT3/cmt1.h" 25 #include "xSens_MT3/cmt2.h" 26 #include "xSens_MT3/cmt3.h" 27 #include "xSens_MT3/cmtdef.h" 28 #include "xSens_MT3/cmtmessage.h" 29 #include "xSens_MT3/cmtpacket.h" 30 #include "xSens_MT3/cmtscan.h" 31 #include "xSens_MT3/xsens_fifoqueue.h" 32 #include "xSens_MT3/xsens_janitors.h" 33 #include "xSens_MT3/xsens_list.h" 34 #include "xSens_MT3/xsens_std.h" 35 #include "xSens_MT3/xsens_time.h" 39 #define cmt3 (*static_cast<xsens::Cmt3*>(m_cmt3_ptr)) 40 #define deviceId (*static_cast<CmtDeviceId*>(m_deviceId_ptr)) 43 #if MRPT_HAS_xSENS_MT3 47 #pragma comment(lib, "SetupAPI.lib") 50 #endif // MRPT_HAS_xSENS_MT3 55 CIMUXSens::CIMUXSens() : m_com_port(), m_timeStartTT(), m_sensorPose()
58 #if MRPT_HAS_xSENS_MT3 64 "MRPT has been compiled with 'BUILD_XSENS_MT3'=OFF, so this class " 74 #if MRPT_HAS_xSENS_MT3 89 #if MRPT_HAS_xSENS_MT3 93 std::this_thread::sleep_for(200ms);
100 unsigned int cont = 0;
106 xsens::Packet packet(1 ,
cmt3.isXm() );
108 res =
cmt3.waitForDataMessage(&packet);
113 nowUI = packet.getRtc();
119 if (packet.containsOriEuler())
121 CmtEuler euler_data = packet.getOriEuler();
124 obs->dataIsPresent[
IMU_YAW] =
true;
128 obs->dataIsPresent[
IMU_ROLL] =
true;
132 if (packet.containsCalAcc())
134 CmtVector acc_data = packet.getCalAcc();
136 obs->rawMeasurements[
IMU_X_ACC] = acc_data.m_data[0];
138 obs->rawMeasurements[
IMU_Y_ACC] = acc_data.m_data[1];
140 obs->rawMeasurements[
IMU_Z_ACC] = acc_data.m_data[2];
145 if (packet.containsCalGyr())
147 CmtVector gir_data = packet.getCalGyr();
149 obs->rawMeasurements[
IMU_YAW_VEL] = gir_data.m_data[2];
153 obs->rawMeasurements[
IMU_ROLL_VEL] = gir_data.m_data[0];
167 obs->timestamp =
m_timeStartTT + std::chrono::milliseconds(AtUI);
176 if (res == XRV_TIMEOUT)
182 if (
cmt3.isPortOpen())
cmt3.closePort();
184 std::cerr <<
"[CIMUXSens::doProcess()] Error: No data " 185 "available [XRV_TIMEOUT]" 190 if (res == XRV_TIMEOUTNODATA)
199 }
while (res == XRV_OK && cont++ < 30);
203 "MRPT has been compiled with 'BUILD_XSENS_MT3'=OFF, so this class " 213 #if MRPT_HAS_xSENS_MT3 215 if (
cmt3.getBaudrate(baudrate) == XRV_OK)
return true;
217 XsensResultValue res;
218 xsens::List<CmtPortInfo> portInfo;
219 unsigned long portCount = 0;
220 unsigned short mtCount = 0;
224 std::cout <<
"Scanning for connected Xsens devices..." << std::endl;
225 xsens::cmtScanPorts(portInfo);
226 portCount = portInfo.length();
227 std::cout <<
"Done" << std::endl;
230 std::cout <<
"No xSens device found" << std::endl;
243 portInfo.append(pInfo);
248 std::cout <<
"Using COM port " 249 << portInfo[0].m_portName <<
" at " 250 << portInfo[0].m_baudrate <<
" baud" << std::endl;
251 std::cout <<
"Opening port..." << std::endl;
254 res =
cmt3.openPort(portInfo[0].m_portName, portInfo[0].m_baudrate);
257 std::cerr <<
"COM Port could not be opened" << std::endl;
261 std::cout <<
"done" << std::endl;
265 <<
"Retrieving MotionTracker count (excluding attached Xbus Master(s))" 267 mtCount =
cmt3.getMtCount();
268 std::cout <<
"MotionTracker count: " << mtCount << std::endl;
273 std::cout <<
"Retrieving MotionTracker device ID" << std::endl;
275 std::cout <<
"Device ID at busId 1: " << (long)
deviceId 280 std::cerr <<
"Device ID could not be gathered" << std::endl;
296 #if MRPT_HAS_xSENS_MT3 298 XsensResultValue res;
300 if (
cmt3.isPortOpen())
return;
308 std::cerr <<
"Error Could not initialize the device" << std::endl;
312 std::cout <<
"xSens IMU detected and connected" << std::endl;
313 CmtOutputMode mode = CMT_OUTPUTMODE_ORIENT | CMT_OUTPUTMODE_CALIB;
314 CmtOutputSettings settings = CMT_OUTPUTSETTINGS_ORIENTMODE_EULER |
315 CMT_OUTPUTSETTINGS_TIMESTAMP_SAMPLECNT |
316 CMT_OUTPUTSETTINGS_CALIBMODE_ACCGYR;
319 res =
cmt3.gotoConfig();
323 std::cerr <<
"An error ocurred when setting the device to config mode" 328 unsigned short sampleFreq;
329 sampleFreq =
cmt3.getSampleFrequency();
332 std::cout <<
"Configuring mode selection" << std::endl;
333 CmtDeviceMode deviceMode(mode, settings, sampleFreq);
338 std::cerr <<
"An error ocurred when configuring the device" 344 res =
cmt3.gotoMeasurement();
349 <<
"An error ocurred when setting the device to measurement mode" 354 std::cout <<
"Getting initial TimeStamp" << std::endl;
356 xsens::Packet packet(1 ,
cmt3.isXm() );
359 res =
cmt3.waitForDataMessage(&packet);
365 }
while (res != XRV_OK);
367 std::cout <<
"Gathering data" << std::endl;
372 "MRPT has been compiled with 'BUILD_XSENS_MT3'=OFF, so this class " 382 const std::string& iniSection)
385 configSource.
read_float(iniSection,
"pose_x", 0,
false),
386 configSource.
read_float(iniSection,
"pose_y", 0,
false),
387 configSource.
read_float(iniSection,
"pose_z", 0,
false),
void appendObservation(const mrpt::serialization::CSerializable::Ptr &obj)
Like appendObservations() but for just one observation.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
void initialize() override
Turns on the xSens device and configure it for getting orientation data.
#define THROW_EXCEPTION(msg)
~CIMUXSens() override
Destructor.
std::string m_sensorLabel
See CGenericSensor.
orientation pitch absolute value (global/navigation frame) (rad)
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection) override
See the class documentation at the top for expected parameters.
bool searchPortAndConnect()
Search the port where the sensor is located and connect to it.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
y-axis acceleration (local/vehicle frame) (m/sec2)
z-axis acceleration (local/vehicle frame) (m/sec2)
A class for interfacing XSens 3rd generation Inertial Measuring Units (IMUs), the "XSens MTi" model...
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
mrpt::system::TTimeStamp m_timeStartTT
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
#define ASSERT_(f)
Defines an assertion mechanism.
pitch angular velocity (local/vehicle frame) (rad/sec)
This class allows loading and storing values and vectors of different types from a configuration text...
constexpr double DEG2RAD(const double x)
Degrees to radians.
void doProcess() override
This method will be invoked at a minimum rate of "process_rate" (Hz)
This namespace contains representation of robot actions and observations.
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
mrpt::poses::CPose3D m_sensorPose
int m_COMbauds
This serial port will be attempted to be opened automatically when this class is first used to reques...
unsigned int m_toutCounter
Timeout counter (for internal use only)
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
orientation yaw absolute value (global/navigation frame) (rad)
orientation roll absolute value (global/navigation frame) (rad)
yaw angular velocity (local/vehicle frame) (rad/sec)
roll angular velocity (local/vehicle frame) (rad/sec)
x-axis acceleration (local/vehicle frame) (m/sec2)