25 #if MRPT_HAS_xSENS_MT4
61 DeviceClass() : m_streamInterface(NULL) { }
64 if (m_streamInterface) {
65 delete m_streamInterface;
66 m_streamInterface=NULL;
81 if (m_streamInterface->open(portInfo) !=
XRV_OK)
90 if (m_streamInterface)
91 m_streamInterface->close();
104 const int maxSz = 8192;
124 m_dataBuffer.append(rawIn);
131 XsByteArray raw(m_dataBuffer.data()+popped, m_dataBuffer.size()-popped);
139 messages.push_back(message);
144 m_dataBuffer.pop_front(popped);
146 if (messages.empty())
163 bool foundAck =
false;
166 readDataToBuffer(
data);
167 processBufferedData(
data, msgs);
169 if ((*it).getMessageId() == xmid)
188 return (m_streamInterface->writeData(raw) ==
XRV_OK);
205 bool gotoMeasurement()
223 const char* pc = (
const char*) rcv.getDataBuffer(0);
225 std::string::size_type thingy = result.find(
" ");
227 result.erase(result.begin() + thingy, result.end());
244 return rcv.getDataLong();
260 sndOM.setDataShort((
uint16_t) outputMode);
267 snd.setDataLong((
uint32_t)outputSettings);
282 if (config.size() == 0)
285 snd.setDataShort(0, 2);
291 snd.setDataShort((
uint16_t)config[i].m_dataIdentifier, i*4);
292 snd.setDataShort(config[i].m_frequency, i*4+2);
310 #define my_xsens_device (*static_cast<DeviceClass*>(m_dev_ptr))
311 #define my_xsens_devid (*static_cast<XsDeviceId*>(m_devid_ptr))
314 #if MRPT_HAS_xSENS_MT4
315 #ifdef MRPT_OS_WINDOWS
317 #if defined(_MSC_VER) || defined(__BORLANDC__)
318 #pragma comment (lib,"SetupAPI.lib")
319 #pragma comment (lib,"WinUsb.lib")
327 CIMUXSens_MT4::CIMUXSens_MT4( ) :
339 #if MRPT_HAS_xSENS_MT4
343 THROW_EXCEPTION(
"MRPT has been compiled with 'BUILD_XSENS_MT4'=OFF, so this class cannot be used.");
352 #if MRPT_HAS_xSENS_MT4
354 delete static_cast<DeviceClass*
>(
m_dev_ptr);
367 #if MRPT_HAS_xSENS_MT4
397 packet.setMessage((*it));
404 CObservationIMUPtr obs = CObservationIMU::Create();
406 if (packet.containsOrientation())
408 XsEuler euler = packet.orientationEuler();
420 if (packet.containsCalibratedAcceleration())
422 XsVector acc_data = packet.calibratedAcceleration();
428 if (packet.containsCalibratedGyroscopeData())
430 XsVector gyr_data = packet.calibratedGyroscopeData();
436 if (packet.containsCalibratedMagneticField())
438 XsVector mag_data = packet.calibratedMagneticField();
444 if (packet.containsVelocity())
446 XsVector vel_data = packet.velocity();
452 if (packet.containsTemperature())
457 if (packet.containsAltitude())
463 if (packet.containsSampleTime64())
465 const uint64_t nowUI = packet.sampleTime64();
476 double AtDO = AtUI * 1000.0;
479 else if (packet.containsUtcTime())
503 if (packet.containsLatitudeLongitude())
505 XsVector lla_data = packet.latitudeLongitude();
507 CObservationGPSPtr obsGPS = CObservationGPSPtr(
new CObservationGPS() );
513 if (packet.containsStatus() && packet.status() &
XSF_GpsValid)
518 if (packet.containsUtcTime())
529 rGPS.
UTCTime.
sec = fmod(obs->timestamp / (1000000.0 / 100), 60);
532 if (packet.containsVelocity())
534 XsVector vel_data = packet.velocity();
536 rGPS.
speed_knots = sqrt(vel_data[0] * vel_data[0] + vel_data[1] * vel_data[1]);
541 obsGPS->setMsg(rGPSs);
542 obsGPS->timestamp = obs->timestamp;
543 obsGPS->originalReceivedTimestamp = obs->timestamp;
544 obsGPS->has_satellite_timestamp =
false;
551 std::cout << std::flush;
556 THROW_EXCEPTION(
"MRPT has been compiled with 'BUILD_XSENS_MT4'=OFF, so this class cannot be used.");
565 #if MRPT_HAS_xSENS_MT4
575 if (
m_verbose) cout <<
"[CIMUXSens_MT4] Scanning for USB devices...\n";
578 if (portInfoArray.empty())
579 THROW_EXCEPTION(
"CIMUXSens_MT4: No 'portname' was specified and no XSens device was found after scanning the system!")
581 if (
m_verbose) cout <<
"[CIMUXSens_MT4] Found " << portInfoArray.size() <<
" devices. Opening the first one.\n";
587 portInfoArray.push_back(portInfo);
594 cout <<
"[CIMUXSens_MT4] Opening port " << mtPort.portName().toStdString() << std::endl;
597 throw std::runtime_error(
"Could not open port. Aborting.");
600 if (
m_verbose) cout <<
"[CIMUXSens_MT4] Putting device into configuration mode...\n";
602 throw std::runtime_error(
"Could not put device into configuration mode. Aborting.");
610 if (!mtPort.deviceId().isMtix() && !mtPort.deviceId().isMtMk4())
612 throw std::runtime_error(
"No MTi / MTx / MTmk4 device found. Aborting.");
614 cout <<
"[CIMUXSens_MT4] Found a device with id: " << mtPort.deviceId().toString().toStdString() <<
" @ port: " << mtPort.portName().toStdString() <<
", baudrate: " << mtPort.baudrate() << std::endl;
617 if (
m_verbose) cout <<
"[CIMUXSens_MT4] Device: " <<
my_xsens_device.getProductCode().toStdString() <<
" opened." << std::endl;
620 if (
m_verbose) cout <<
"[CIMUXSens_MT4] Configuring the device..." << std::endl;
621 if (mtPort.deviceId().isMtix())
628 throw std::runtime_error(
"Could not configure MT device. Aborting.");
630 else if (mtPort.deviceId().isMtMk4())
649 throw std::runtime_error(
"Could not configure MTmk4 device. Aborting.");
653 throw std::runtime_error(
"Unknown device while configuring. Aborting.");
657 if (
m_verbose) cout <<
"[CIMUXSens_MT4] Putting device into measurement mode..." << std::endl;
659 throw std::runtime_error(
"Could not put device into measurement mode. Aborting.");
664 catch(std::exception &)
667 std::cerr <<
"Error Could not initialize the device" << std::endl;
672 THROW_EXCEPTION(
"MRPT has been compiled with 'BUILD_XSENS_MT4'=OFF, so this class cannot be used.");
684 configSource.
read_float( iniSection,
"pose_x", 0,
false ),
685 configSource.
read_float( iniSection,
"pose_y", 0,
false ),
686 configSource.
read_float( iniSection,
"pose_z", 0,
false ),
695 #ifdef MRPT_OS_WINDOWS
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
Stores the location of a message in a buffer using a start position and a size.
int m_size
The size of the message, when less than 0 it indicates the expected message size.
Message protocol handling class.
static int composeMessage(XsByteArray &raw, const XsMessage &msg)
Compose a message for transmission.
virtual MessageLocation findMessage(XsMessage &rcv, const XsByteArray &raw) const
Find the first message in the raw byte stream.
The low-level serial communication class.
An IoInterface for dealing specifically with Xsens USB devices.
void appendObservation(const mrpt::utils::CSerializablePtr &obj)
Like appendObservations() but for just one observation.
std::string m_sensorLabel
See CGenericSensor.
A class for interfacing XSens 4th generation Inertial Measuring Units (IMUs): MTi 10-series,...
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
std::string m_portname
The USB or COM port name (if blank -> autodetect)
mrpt::poses::CPose3D m_sensorPose
int m_port_bauds
Baudrate, only for COM ports.
void doProcess()
This method will be invoked at a minimum rate of "process_rate" (Hz)
virtual ~CIMUXSens_MT4()
Destructor.
mrpt::system::TTimeStamp m_timeStartTT
void initialize()
Turns on the xSens device and configure it for getting orientation data.
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...
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...
This class allows loading and storing values and vectors of different types from a configuration text...
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
bool xsEnumerateUsbDevices(XsPortInfoList &ports)
Enumerate Xsens USB devices.
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLsizei const GLchar ** string
XsResultValue
Xsens result values.
XsOutputSettings
Bit values for output settings.
XsOutputMode
Bit values for legacy output mode.
XsXbusMessageId
Xsens Xbus Message Identifiers.
@ XOS_OrientationMode_Euler
@ XOS_Timestamp_PacketCounter
@ XMID_SetOutputConfigurationAck
@ XMID_GotoMeasurementAck
@ XMID_SetOutputSettingsAck
@ XMID_SetOutputConfiguration
@ XSF_GpsValid
Is set when the device has a GPS receiver and the receiver says that there is a GPS position fix.
@ IMU_MAG_Y
y magnetic field value (local/vehicle frame) (gauss)
@ IMU_MAG_Z
z magnetic field value (local/vehicle frame) (gauss)
@ IMU_ALTITUDE
altitude from an altimeter (meters)
@ IMU_X_ACC
x-axis acceleration (local/vehicle frame) (m/sec2)
@ IMU_PITCH_VEL
pitch angular velocity (local/vehicle frame) (rad/sec)
@ IMU_ORI_QUAT_W
Orientation Quaternion W (global/navigation frame)
@ IMU_PITCH
orientation pitch absolute value (global/navigation frame) (rad)
@ IMU_ORI_QUAT_Y
Orientation Quaternion Y (global/navigation frame)
@ IMU_YAW
orientation yaw absolute value (global/navigation frame) (rad)
@ IMU_ORI_QUAT_X
Orientation Quaternion X (global/navigation frame)
@ IMU_TEMPERATURE
temperature (degrees Celsius)
@ IMU_X_VEL
x-axis velocity (global/navigation frame) (m/sec)
@ IMU_Z_ACC
z-axis acceleration (local/vehicle frame) (m/sec2)
@ IMU_ORI_QUAT_Z
Orientation Quaternion Z (global/navigation frame)
@ IMU_Z_VEL
z-axis velocity (global/navigation frame) (m/sec)
@ IMU_ROLL_VEL
roll angular velocity (local/vehicle frame) (rad/sec)
@ IMU_YAW_VEL
yaw angular velocity (local/vehicle frame) (rad/sec)
@ IMU_MAG_X
x magnetic field value (local/vehicle frame) (gauss)
@ IMU_Y_ACC
y-axis acceleration (local/vehicle frame) (m/sec2)
@ IMU_Y_VEL
y-axis velocity (global/navigation frame) (m/sec)
@ IMU_ROLL
orientation roll absolute value (global/navigation frame) (rad)
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time.
mrpt::system::TTimeStamp BASE_IMPEXP buildTimestampFromParts(const mrpt::system::TTimeParts &p)
Builds a timestamp from the parts (Parts are in UTC)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
void XsDataPacket_assignFromXsLegacyDataPacket(struct XsDataPacket *thisPtr, struct LegacyDataPacket const *pack, int index)
#define THROW_EXCEPTION(msg)
Contains classes for various device interfaces.
This namespace contains representation of robot actions and observations.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
unsigned __int16 uint16_t
unsigned __int32 uint32_t
unsigned __int64 uint64_t
Contains an MTData XsMessage and supports functions for extracting contained data.
bool setDataFormat(const XsDataFormat &format, int32_t index=0)
Sets the data format of the device with the given index to format.
void setDeviceId(XsDeviceId deviceId, int32_t index)
Sets the device ID of the device with the given index to deviceid.
void setMessage(const XsMessage &message)
Set the source message to msg.
void setXbusSystem(bool xbus, bool convert=false)
Sets the xbus flag.
Contains data received from a device or read from a file.
Structure for storing a single message.
A structure for storing UTC Time values.
uint32_t m_nano
Nanosecond part of the time.
uint8_t m_minute
The minute (if time is valid)
uint8_t m_day
The day of the month (if date is valid)
uint8_t m_month
The month (if date is valid)
uint8_t m_second
The second (if time is valid)
uint16_t m_year
The year (if date is valid)
uint8_t m_hour
The hour (if time is valid)
double direction_degrees
Measured speed direction (in degrees)
int8_t validity_char
This will be: 'A'=OK or 'V'=void.
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
double speed_knots
Measured speed (in knots)
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
UTC_time UTCTime
The GPS sensor measured timestamp (in UTC time)
content_t fields
Message content, accesible by individual fields.
The parts of a date/time (it's like the standard 'tm' but with fractions of seconds).
uint8_t day_of_week
Seconds (0.0000-59.9999)
int daylight_saving
Day of week (1:Sunday, 7:Saturday)
uint8_t minute
Hour (0-23)
double second
Minute (0-59)
struct XsByteArray XsByteArray
struct XsDeviceId XsDeviceId
@ XRV_OK
Operation was performed successfully.
@ XRV_TIMEOUTNODATA
Operation aborted because of no data read.
struct XsMessageArray XsMessageArray
struct XsOutputConfiguration XsOutputConfiguration
struct XsOutputConfigurationArray XsOutputConfigurationArray
struct XsPortInfoArray XsPortInfoArray
size_t XsSize
XsSize must be unsigned number!