mtdef.py
Go to the documentation of this file.
00001 """Constant and messages definition for MT communication."""
00002 
00003 
00004 class DeviceState:
00005     """State of the device"""
00006     # measurement state
00007     Measurement = 0
00008     # config state
00009     Config = 1
00010 
00011 
00012 class MID:
00013     """Values for the message id (MID)"""
00014     # Error message, 1 data byte
00015     Error = 0x42
00016 
00017     # State MID
00018     # Wake up procedure
00019     WakeUp = 0x3E
00020     # Wake up ack to put device in config mode
00021     WakeUpAck = 0x3F
00022     # Switch to config state
00023     GoToConfig = 0x30
00024     # Switch to measurement state
00025     GoToMeasurement = 0x10
00026     # Reset device
00027     Reset = 0x40
00028 
00029     # Informational messages
00030     # Request device id
00031     ReqDID = 0x00
00032     # DeviceID, 4 bytes: HH HL LH LL
00033     DeviceID = 0x01
00034     # Request product code in plain text
00035     ReqProductCode = 0x1C
00036     # Product code (max 20 bytes data)
00037     ProductCode = 0x1D
00038     # Request firmware revision
00039     ReqFWRev = 0x12
00040     # Firmware revision, 3 bytes: major minor rev
00041     FirmwareRev = 0x13
00042 
00043     # Device specific messages
00044     # Restore factory defaults
00045     RestoreFactoryDef = 0x0E
00046     # Baudrate, 1 byte
00047     SetBaudrate = 0x18
00048     # Run the built-in self test (MTi-1/10/100 series)
00049     RunSelftest = 0x24
00050     # Self test results, 2 bytes
00051     SelftestAck = 0x25
00052     # Error mode, 2 bytes, 0000, 0001, 0002, 0003 (default 0001)
00053     SetErrorMode = 0xDA
00054     # Transmit delay (RS485), 2 bytes, number of clock ticks (1/29.4912 MHz)
00055     SetTransmitDelay = 0xDC
00056     # Set state of OptionFlags (MTi-1/2/3), 4 + 4 bytes
00057     SetOptionFlags = 0x48
00058     # Location ID, 2 bytes, arbitrary, default is 0
00059     SetLocationID = 0x84
00060 
00061     # Synchronization messages
00062     # Synchronization settings (MTi-1/10/100 series only), N*12 bytes
00063     SetSyncSettings = 0x2C
00064 
00065     # Configuration messages
00066     # Request configuration
00067     ReqConfiguration = 0x0C
00068     # Configuration, 118 bytes
00069     Configuration = 0x0D
00070     # Sampling period (MTi/MTi-G only), 2 bytes
00071     SetPeriod = 0x04
00072     # Extended output mode (MTi-10/100), 2 bytes, bit 4 for extended UART
00073     SetExtOutputMode = 0x86
00074     # Output configuration (MTi-1/10/100 series only), N*4 bytes
00075     SetOutputConfiguration = 0xC0
00076     # Configure NMEA data output (MTi-10/100), 2 bytes
00077     SetStringOutputType = 0x8E
00078     # Set sensor of local alignment quaternion
00079     SetAlignmentRotation = 0xEC
00080     # Output mode (MTi/MTi-G only), 2 bytes
00081     SetOutputMode = 0xD0
00082     # Output settings (MTi/MTi-G only), 4 bytes
00083     SetOutputSettings = 0xD2
00084 
00085     # Data messages
00086     # Request MTData message (for 65535 skip factor)
00087     ReqData = 0x34
00088     # Legacy data packet
00089     MTData = 0x32
00090     # Newer data packet (MTi-10/100 series only)
00091     MTData2 = 0x36
00092 
00093     # Filter messages
00094     # Reset orientation, 2 bytes
00095     ResetOrientation = 0xA4
00096     # Request or set UTC time from sensor (MTI-G and MTi-10/100 series)
00097     SetUTCTime = 0x60
00098     # Set correction ticks to UTC time
00099     AdjustUTCTime = 0xA8
00100     # UTC Time (MTI-G and MTi-10/100 series), 12 bytes
00101     UTCTime = 0x61
00102     # Request the available XKF scenarios on the device
00103     ReqAvailableScenarios = 0x62
00104     # Available Scenarios
00105     AvailableScenarios = 0x63
00106     # Current XKF scenario, 2 bytes
00107     SetCurrentScenario = 0x64
00108     # Magnitude of the gravity used for the sensor fusion mechanism, 4 bytes
00109     SetGravityMagnitude = 0x66
00110     # Latitude, Longitude and Altitude for local declination and gravity
00111     # (MTi-10/100 series only), 24 bytes
00112     SetLatLonAlt = 0x6E
00113     # Initiate No Rotation procedure (not on MTi-G), 2 bytes
00114     SetNoRotation = 0x22
00115 
00116 
00117 class DeprecatedMID:
00118     """Deprecated message Ids."""
00119     # Informational messages
00120     # Compatibility for XBus Master users
00121     InitMT = 0x02
00122     InitMTResults = 0x03
00123     # Request data length according to current configuration
00124     ReqDataLength = 0x0A
00125     # Data Length, 2 bytes
00126     DataLength = 0x0B
00127     # Request GPS status (MTi-G only)
00128     ReqGPSStatus = 0xA6
00129     # GPS status (MTi-G only)
00130     GPSStatus = 0xA7
00131 
00132     # Synchronization messages
00133     # SyncIn setting (MTi only), (1+) 2 or 4 bytes depending on request
00134     SetSyncInSettings = 0xD6
00135     # SyncOut setting (MTi/MTi-G only), (1+) 2 or 4 bytes depending on request
00136     SetSyncOutSettings = 0xD8
00137 
00138     # Configuration messages
00139     # Skip factor (MTi/MTi-G only), 2 bytes
00140     SetOutputSkipFactor = 0xD4
00141     # Object alignment matrix, 9*4 bytes
00142     SetObjectAlignment = 0xE0
00143 
00144     # XKF Filter messages
00145     # Heading (MTi only), 4 bytes
00146     SetHeading = 0x82
00147     # Lever arm of the GPSin sensor coordinates (MTi-G and MTi-700 only),
00148     # 3*4 bytes
00149     SetLeverArmGPS = 0x68
00150     # Magnetic declination (MTi-G only), 4 bytes
00151     SetMagneticDeclination = 0x6A
00152     # Latitude, Longitude and Altitude for local declination and gravity
00153     # Processing flags (not on firmware 2.2 or lower for MTi/MTi-g), 1 byte
00154     SetProcessingFlags = 0x20
00155 
00156 
00157 def getName(cls, value):
00158     '''Return the name of the first found member of class cls with given
00159     value.'''
00160     for k, v in cls.__dict__.iteritems():
00161         if v == value:
00162             return k
00163     return ''
00164 
00165 
00166 def getMIDName(mid):
00167     '''Return the name of a message given the message id.'''
00168     name = getName(MID, mid)
00169     if name:
00170         return name
00171     if mid & 1:
00172         name = getName(MID, mid-1)
00173         if name:
00174             return name+'Ack'
00175     return 'unknown MID'
00176 
00177 
00178 class Baudrates(object):
00179     """Baudrate information and conversion."""
00180     # Baudrate mapping between ID and value
00181     Baudrates = [
00182         (0x80, 921600),
00183         (0x0A, 921600),
00184         (0x00, 460800),
00185         (0x01, 230400),
00186         (0x02, 115200),
00187         (0x03,  76800),
00188         (0x04,  57600),
00189         (0x05,  38400),
00190         (0x06,  28800),
00191         (0x07,  19200),
00192         (0x08,  14400),
00193         (0x09,   9600),
00194         (0x0B,   4800),
00195         (0x80, 921600)]
00196 
00197     @classmethod
00198     def get_BRID(cls, baudrate):
00199         """Get baudrate id for a given baudrate."""
00200         for brid, br in cls.Baudrates:
00201             if baudrate == br:
00202                 return brid
00203         raise MTException("unsupported baudrate.")
00204 
00205     @classmethod
00206     def get_BR(cls, baudrate_id):
00207         """Get baudrate for a given baudrate id."""
00208         for brid, br in cls.Baudrates:
00209             if baudrate_id == brid:
00210                 return br
00211         raise MTException("unknown baudrate id.")
00212 
00213 
00214 class OutputMode:
00215     """Values for the output mode."""
00216     Temp = 0x0001
00217     Calib = 0x0002
00218     Orient = 0x0004
00219     Auxiliary = 0x0008
00220     Position = 0x0010
00221     Velocity = 0x0020
00222     Status = 0x0800
00223     RAWGPS = 0x1000  # supposed to be incompatible with previous
00224     RAW = 0x4000  # incompatible with all except RAWGPS
00225 
00226 
00227 class OutputSettings:
00228     """Values for the output settings."""
00229     Timestamp_None = 0x00000000
00230     Timestamp_SampleCnt = 0x00000001
00231     Timestamp_UTCTime = 0x00000002
00232     OrientMode_Quaternion = 0x00000000
00233     OrientMode_Euler = 0x00000004
00234     OrientMode_Matrix = 0x00000008
00235     CalibMode_AccGyrMag = 0x00000000
00236     CalibMode_GyrMag = 0x00000010
00237     CalibMode_AccMag = 0x00000020
00238     CalibMode_Mag = 0x00000030
00239     CalibMode_AccGyr = 0x00000040
00240     CalibMode_Gyr = 0x00000050
00241     CalibMode_Acc = 0x00000060
00242     CalibMode_Mask = 0x00000070
00243     DataFormat_Float = 0x00000000
00244     DataFormat_12_20 = 0x00000100  # not supported yet
00245     DataFormat_16_32 = 0x00000200  # not supported yet
00246     DataFormat_Double = 0x00000300  # not supported yet
00247     AuxiliaryMode_NoAIN1 = 0x00000400
00248     AuxiliaryMode_NoAIN2 = 0x00000800
00249     PositionMode_LLA_WGS84 = 0x00000000
00250     VelocityMode_MS_XYZ = 0x00000000
00251     Coordinates_NED = 0x80000000
00252 
00253 
00254 class XDIGroup:
00255     """Values for the XDI groups."""
00256     Temperature = 0x0800
00257     Timestamp = 0x1000
00258     OrientationData = 0x2000
00259     Pressure = 0x3000
00260     Acceleration = 0x4000
00261     Position = 0x5000
00262     GNSS = 0x7000
00263     AngularVelocity = 0x8000
00264     GPS = 0x8800
00265     SensorComponentReadout = 0xA000
00266     AnalogIn = 0xB000  # deprecated
00267     Magnetic = 0xC000
00268     Velocity = 0xD000
00269     Status = 0xE000
00270 
00271 
00272 class MTException(Exception):
00273     def __init__(self, message):
00274         self.message = message
00275 
00276     def __str__(self):
00277         return self.message
00278 
00279 
00280 class MTTimeoutException(MTException):
00281     def __init__(self, message):
00282         self.message = message
00283 
00284     def __str__(self):
00285         return 'Timeout: %s' % self.message
00286 
00287 
00288 class MTErrorMessage(MTException):
00289     ErrorCodes = {
00290         0: "Operation was performed successfully",
00291         1: "No bus communication possible",
00292         2: "InitBus and/or SetBID are not issued",
00293         3: "Period sent is invalid",
00294         4: "The message is invalid or not implemented",
00295         16: "A slave did not respond to WaitForSetBID",
00296         17: "An incorrect answer received after WaitForSetBID",
00297         18: "After four bus-scans still undetected Motion Trackers",
00298         20: "No reply to SetBID message during SetBID procedure",
00299         21: "Other than SetBIDAck received",
00300         24: "Timer overflow - period too short to collect all data from Motion Trackers",
00301         25: "Motion Tracker responds with other than SlaveData message",
00302         26: "Total bytes of data of Motion Trackers including sample counter exceeds 255 bytes",
00303         27: "Timer overflows during measurement",
00304         28: "Timer overflows during measurement",
00305         29: "No correct response from Motion Tracker during measurement",
00306         30: "Timer overflows during measurement",
00307         32: "Baud rate does not comply with valid range",
00308         33: "An invalid parameter is supplied",
00309         35: "TX PC Buffer is full",
00310         36: "TX PC Buffer overflow, cannot fit full message",
00311         37: "Wireless subsystem failed",
00312         40: "The device generated an error, try updating the firmware",
00313         41: "The device generates more data than the bus communication can handle (baud rate may be too low)",
00314         42: "The sample buffer of the device was full during a communication outage",
00315         43: "The external trigger is not behaving as configured",
00316         44: "The sample stream detected an error in the ordering of sample data",
00317         45: "A dip in the power supply was detected and recovered from",
00318         46: "A current limiter has been activated, shutting down the device",
00319         47: "Device temperature is not within operational limits",
00320         48: "Battery level reached lower limit",
00321         49: "Specified filter profile ID is not available on the device or the user is trying to duplicate an existing filter profile type",
00322         50: "The settings stored in the device's non volatile memory are invalid",
00323         256: "A generic error occurred",
00324         257: "Operation not implemented in this version (yet)",
00325         258: "A timeout occurred",
00326         259: "Operation aborted because of no data read",
00327         260: "Checksum fault occurred",
00328         261: "No internal memory available",
00329         262: "The requested item was not found",
00330         263: "Unexpected message received (e.g. no acknowledge message received)",
00331         264: "Invalid id supplied",
00332         265: "Operation is invalid at this point",
00333         266: "Insufficient buffer space available",
00334         267: "The specified i/o device can not be opened",
00335         268: "The specified i/o device can not be opened",
00336         269: "An I/O device is already opened with this object",
00337         270: "End of file is reached",
00338         271: "A required settings file could not be opened or is missing some data",
00339         272: "No data is available",
00340         273: "Tried to change a read-only value",
00341         274: "Tried to supply a NULL value where it is not allowed",
00342         275: "Insufficient data was supplied to a function",
00343         276: "Busy processing, try again later",
00344         277: "Invalid instance called",
00345         278: "A trusted data stream proves to contain corrupted data",
00346         279: "Failure during read of settings",
00347         280: "Could not find any MVN-compatible hardware",
00348         281: "Found only one responding Xbus Master",
00349         282: "No xsens devices found",
00350         283: "One or more sensors are not where they were expected",
00351         284: "Not enough sensors were found",
00352         285: "Failure during initialization of Fusion Engine",
00353         286: "Something else was received than was requested",
00354         287: "No file opened for reading/writing",
00355         288: "No serial port opened for reading/writing",
00356         289: "No file or serial port opened for reading/writing",
00357         290: "A required port could not be found",
00358         291: "The low-level port handler failed to initialize",
00359         292: "A calibration routine failed",
00360         293: "The in-config check of the device failed",
00361         294: "The operation is once only and has already been performed",
00362         295: "The single connected device is configured as a slave",
00363         296: "More than one master was detected",
00364         297: "A device was detected that was neither master nor slave",
00365         298: "No master detected",
00366         299: "A device is not sending enough data",
00367         300: "The version of the object is too low for the requested operation",
00368         301: "The object has an unrecognised version, so it's not safe to perform the operation",
00369         302: "The process was aborted by an external event, usually a user action or process termination",
00370         303: "The requested functionality is not supported by the device",
00371         304: "A packet counter value was missed",
00372         305: "An error occurred while trying to put the device in measurement mode",
00373         306: "A device could not start recording",
00374         311: "Radio channel is in use by another system",
00375         312: "Motion tracker disconnected unexpectedly",
00376         313: "Too many motion trackers connected",
00377         314: "A device could not be put in config mode",
00378         315: "Device has gone out of range",
00379         316: "Device is back in range, resuming normal operation",
00380         400: "The device is shutting down "
00381     }
00382 
00383     def __init__(self, code):
00384         self.code = code
00385         self.message = self.ErrorCodes.get(code, 'Unknown error: 0x%02X' % code)
00386 
00387     def __str__(self):
00388         return 'Error message 0x%02X: %s' % (self.code, self.message)


xsens_driver
Author(s):
autogenerated on Sat Aug 19 2017 03:01:10