mtdef.py
Go to the documentation of this file.
1 """Constant and messages definition for MT communication."""
2 
3 
4 class DeviceState:
5  """State of the device"""
6  # measurement state
7  Measurement = 0
8  # config state
9  Config = 1
10 
11 
12 class MID:
13  """Values for the message id (MID)"""
14  # State MID
15  # Wake up procedure
16  WakeUp = 0x3E
17  # Wake up ack to put device in config mode
18  WakeUpAck = 0x3F
19  # Switch to config state
20  GoToConfig = 0x30
21  # Switch to measurement state
22  GoToMeasurement = 0x10
23  # Reset device
24  Reset = 0x40
25 
26  # Informational messages
27  # Request device id
28  ReqDID = 0x00
29  # DeviceID, 4 bytes: HH HL LH LL
30  DeviceID = 0x01
31  # Request product code in plain text
32  ReqProductCode = 0x1C
33  # Product code (max 20 bytes data)
34  ProductCode = 0x1D
35  # Request hardware version
36  ReqHardwareVersion = 0x1E
37  # Hardware version, 2 bytes: major minor
38  HardwareVersion = 0x1F
39  # Request firmware revision
40  ReqFWRev = 0x12
41  # Firmware revision, 3 bytes: major minor rev
42  FirmwareRev = 0x13
43  # Error message, 1 data byte
44  Error = 0x42
45 
46  # Device specific messages
47  # Restore factory defaults
48  RestoreFactoryDef = 0x0E
49  # Baudrate, 1 byte
50  SetBaudrate = 0x18
51  # Run the built-in self test (MTi-1/10/100 series)
52  RunSelftest = 0x24
53  # Self test results, 2 bytes
54  SelftestAck = 0x25
55  # GNSS platform setting, 2 bytes (only MTi-G-700/710 with FW1.7 or higher)
56  SetGnssPlatform = 0x76
57  # Error mode, 2 bytes, 0000, 0001, 0002, 0003 (default 0001)
58  SetErrorMode = 0xDA
59  # Transmit delay (RS485), 2 bytes, number of clock ticks (1/29.4912 MHz)
60  SetTransmitDelay = 0xDC
61  # Set state of OptionFlags (MTi-1/2/3), 4 + 4 bytes
62  SetOptionFlags = 0x48
63  # Location ID, 2 bytes, arbitrary, default is 0
64  SetLocationID = 0x84
65 
66  # Synchronization messages
67  # Synchronization settings (MTi-1/10/100 series only), N*12 bytes
68  SetSyncSettings = 0x2C
69 
70  # Configuration messages
71  # Request configuration
72  ReqConfiguration = 0x0C
73  # Configuration, 118 bytes
74  Configuration = 0x0D
75  # Sampling period (MTi/MTi-G only), 2 bytes
76  SetPeriod = 0x04
77  # Extended output mode (MTi-10/100), 2 bytes, bit 4 for extended UART
78  SetExtOutputMode = 0x86
79  # Output configuration (MTi-1/10/100 series only), N*4 bytes
80  SetOutputConfiguration = 0xC0
81  # Configure NMEA data output (MTi-10/100), 2 bytes
82  SetStringOutputType = 0x8E
83  # Set sensor of local alignment quaternion
84  SetAlignmentRotation = 0xEC
85  # Output mode (MTi/MTi-G only), 2 bytes
86  SetOutputMode = 0xD0
87  # Output settings (MTi/MTi-G only), 4 bytes
88  SetOutputSettings = 0xD2
89  # Skip factor (MTi/MTi-G only), 2 bytes
90  SetOutputSkipFactor = 0xD4
91 
92  # Data messages
93  # Request MTData message (for 65535 skip factor)
94  ReqData = 0x34
95  # Legacy data packet
96  MTData = 0x32
97  # Newer data packet (MTi-10/100 series only)
98  MTData2 = 0x36
99 
100  # Filter messages
101  # Reset orientation, 2 bytes
102  ResetOrientation = 0xA4
103  # Request or set UTC time from sensor (MTI-G and MTi-10/100 series)
104  SetUTCTime = 0x60
105  # Set correction ticks to UTC time
106  AdjustUTCTime = 0xA8
107  # UTC Time (MTI-G and MTi-10/100 series), 12 bytes
108  UTCTime = 0x61
109  # Request the available XKF scenarios on the device
110  ReqAvailableFilterProfiles = ReqAvailableScenarios = 0x62
111  # Available Scenarios
112  AvailableFilterProfiles = AvailableScenarios = 0x63
113  # Current XKF scenario, 2 bytes
114  SetFilterProfile = SetCurrentScenario = 0x64
115  # Magnitude of the gravity used for the sensor fusion mechanism, 4 bytes
116  SetGravityMagnitude = 0x66
117  # Latitude, Longitude and Altitude for local declination and gravity
118  # (MTi-10/100 series only), 24 bytes
119  SetLatLonAlt = 0x6E
120  # Initiate No Rotation procedure (not on MTi-G), 2 bytes
121  SetNoRotation = 0x22
122  # In-run Compass Calibration (ICC) command, 1 byte
123  IccCommand = 0x74
124 
125 
127  """Deprecated message Ids."""
128  # Informational messages
129  # Compatibility for XBus Master users
130  InitMT = 0x02
131  InitMTResults = 0x03
132  # Request data length according to current configuration
133  ReqDataLength = 0x0A
134  # Data Length, 2 bytes
135  DataLength = 0x0B
136  # Request GPS status (MTi-G only)
137  ReqGPSStatus = 0xA6
138  # GPS status (MTi-G only)
139  GPSStatus = 0xA7
140 
141  # Synchronization messages
142  # SyncIn setting (MTi only), (1+) 2 or 4 bytes depending on request
143  SetSyncInSettings = 0xD6
144  # SyncOut setting (MTi/MTi-G only), (1+) 2 or 4 bytes depending on request
145  SetSyncOutSettings = 0xD8
146 
147  # Configuration messages
148  # Skip factor (MTi/MTi-G only), 2 bytes
149  SetOutputSkipFactor = 0xD4
150  # Object alignment matrix, 9*4 bytes
151  SetObjectAlignment = 0xE0
152 
153  # XKF Filter messages
154  # Heading (MTi only), 4 bytes
155  SetHeading = 0x82
156  # Lever arm of the GPSin sensor coordinates (MTi-G and MTi-700 only),
157  # 3*4 bytes
158  SetLeverArmGPS = 0x68
159  # Magnetic declination (MTi-G only), 4 bytes
160  SetMagneticDeclination = 0x6A
161  # Latitude, Longitude and Altitude for local declination and gravity
162  # Processing flags (not on firmware 2.2 or lower for MTi/MTi-g), 1 byte
163  SetProcessingFlags = 0x20
164 
165 
166 def getName(cls, value):
167  '''Return the name of the first found member of class cls with given
168  value.'''
169  for k, v in cls.__dict__.iteritems():
170  if v == value:
171  return k
172  return ''
173 
174 
175 def getMIDName(mid):
176  '''Return the name of a message given the message id.'''
177  name = getName(MID, mid)
178  if name:
179  return name
180  if mid & 1:
181  name = getName(MID, mid-1)
182  if name:
183  return name+'Ack'
184  return 'unknown MID'
185 
186 
187 class Baudrates(object):
188  """Baudrate information and conversion."""
189  # Baudrate mapping between ID and value
190  Baudrates = [
191  (0x0D, 4000000),
192  (0x0D, 3686400),
193  (0x0C, 2000000),
194  (0x80, 921600),
195  (0x0A, 921600),
196  (0x00, 460800),
197  (0x01, 230400),
198  (0x02, 115200),
199  (0x03, 76800),
200  (0x04, 57600),
201  (0x05, 38400),
202  (0x06, 28800),
203  (0x07, 19200),
204  (0x08, 14400),
205  (0x09, 9600),
206  (0x0B, 4800),
207  (0x80, 921600)]
208 
209  @classmethod
210  def get_BRID(cls, baudrate):
211  """Get baudrate id for a given baudrate."""
212  for brid, br in cls.Baudrates:
213  if baudrate == br:
214  return brid
215  raise MTException("unsupported baudrate.")
216 
217  @classmethod
218  def get_BR(cls, baudrate_id):
219  """Get baudrate for a given baudrate id."""
220  for brid, br in cls.Baudrates:
221  if baudrate_id == brid:
222  return br
223  raise MTException("unknown baudrate id.")
224 
225 
227  """Values for the output mode."""
228  Temp = 0x0001
229  Calib = 0x0002
230  Orient = 0x0004
231  Auxiliary = 0x0008
232  Position = 0x0010
233  Velocity = 0x0020
234  Status = 0x0800
235  RAWGPS = 0x1000 # supposed to be incompatible with previous
236  RAW = 0x4000 # incompatible with all except RAWGPS
237 
238 
240  """Values for the output settings."""
241  Timestamp_None = 0x00000000
242  Timestamp_SampleCnt = 0x00000001
243  Timestamp_UTCTime = 0x00000002
244  OrientMode_Quaternion = 0x00000000
245  OrientMode_Euler = 0x00000004
246  OrientMode_Matrix = 0x00000008
247  CalibMode_AccGyrMag = 0x00000000
248  CalibMode_GyrMag = 0x00000010
249  CalibMode_AccMag = 0x00000020
250  CalibMode_Mag = 0x00000030
251  CalibMode_AccGyr = 0x00000040
252  CalibMode_Gyr = 0x00000050
253  CalibMode_Acc = 0x00000060
254  CalibMode_Mask = 0x00000070
255  DataFormat_Float = 0x00000000
256  DataFormat_12_20 = 0x00000100 # not supported yet
257  DataFormat_16_32 = 0x00000200 # not supported yet
258  DataFormat_Double = 0x00000300 # not supported yet
259  AuxiliaryMode_NoAIN1 = 0x00000400
260  AuxiliaryMode_NoAIN2 = 0x00000800
261  PositionMode_LLA_WGS84 = 0x00000000
262  VelocityMode_MS_XYZ = 0x00000000
263  Coordinates_NED = 0x80000000
264 
265 
266 class XDIGroup:
267  """Values for the XDI groups."""
268  Temperature = 0x0800
269  Timestamp = 0x1000
270  OrientationData = 0x2000
271  Pressure = 0x3000
272  Acceleration = 0x4000
273  Position = 0x5000
274  GNSS = 0x7000
275  AngularVelocity = 0x8000
276  GPS = 0x8800 # deprecated mk.5
277  SensorComponentReadout = 0xA000
278  AnalogIn = 0xB000 # deprecated mk.3
279  Magnetic = 0xC000
280  Velocity = 0xD000
281  Status = 0xE000
282 
283 
284 class MTException(Exception):
285  def __init__(self, message):
286  self.message = message
287 
288  def __str__(self):
289  return self.message
290 
291 
293  def __init__(self, message):
294  self.message = message
295 
296  def __str__(self):
297  return 'Timeout: %s' % self.message
298 
299 
301  ErrorCodes = {
302  0: "Operation was performed successfully",
303  1: "No bus communication possible",
304  2: "InitBus and/or SetBID are not issued",
305  3: "Period sent is invalid",
306  4: "The message is invalid or not implemented",
307  16: "A slave did not respond to WaitForSetBID",
308  17: "An incorrect answer received after WaitForSetBID",
309  18: "After four bus-scans still undetected Motion Trackers",
310  20: "No reply to SetBID message during SetBID procedure",
311  21: "Other than SetBIDAck received",
312  24: "Timer overflow - period too short to collect all data from "
313  "Motion Trackers",
314  25: "Motion Tracker responds with other than SlaveData message",
315  26: "Total bytes of data of Motion Trackers including sample counter "
316  "exceeds 255 bytes",
317  27: "Timer overflows during measurement",
318  28: "Timer overflows during measurement",
319  29: "No correct response from Motion Tracker during measurement",
320  30: "Timer overflows during measurement",
321  32: "Baud rate does not comply with valid range",
322  33: "An invalid parameter is supplied",
323  35: "TX PC Buffer is full",
324  36: "TX PC Buffer overflow, cannot fit full message",
325  37: "Wireless subsystem failed",
326  40: "The device generated an error, try updating the firmware",
327  41: "The device generates more data than the bus communication can "
328  "handle (baud rate may be too low)",
329  42: "The sample buffer of the device was full during a communication "
330  "outage",
331  43: "The external trigger is not behaving as configured",
332  44: "The sample stream detected an error in the ordering of sample "
333  "data",
334  45: "A dip in the power supply was detected and recovered from",
335  46: "A current limiter has been activated, shutting down the device",
336  47: "Device temperature is not within operational limits",
337  48: "Battery level reached lower limit",
338  49: "Specified filter profile ID is not available on the device or "
339  "the user is trying to duplicate an existing filter profile type",
340  50: "The settings stored in the device's non volatile memory are "
341  "invalid",
342  51: "Request for control of the device was denied",
343  256: "A generic error occurred",
344  257: "Operation not implemented in this version (yet)",
345  258: "A timeout occurred",
346  259: "Operation aborted because of no data read",
347  260: "Checksum fault occurred",
348  261: "No internal memory available",
349  262: "The requested item was not found",
350  263: "Unexpected message received (e.g. no acknowledge message "
351  "received)",
352  264: "Invalid id supplied",
353  265: "Operation is invalid at this point",
354  266: "Insufficient buffer space available",
355  267: "The specified i/o device can not be opened",
356  268: "The specified i/o device can not be opened",
357  269: "An I/O device is already opened with this object",
358  270: "End of file is reached",
359  271: "A required settings file could not be opened or is missing some "
360  "data",
361  272: "No data is available",
362  273: "Tried to change a read-only value",
363  274: "Tried to supply a NULL value where it is not allowed",
364  275: "Insufficient data was supplied to a function",
365  276: "Busy processing, try again later",
366  277: "Invalid instance called",
367  278: "A trusted data stream proves to contain corrupted data",
368  279: "Failure during read of settings",
369  280: "Could not find any MVN-compatible hardware",
370  281: "Found only one responding Xbus Master",
371  282: "No xsens devices found",
372  283: "One or more sensors are not where they were expected",
373  284: "Not enough sensors were found",
374  285: "Failure during initialization of Fusion Engine",
375  286: "Something else was received than was requested",
376  287: "No file opened for reading/writing",
377  288: "No serial port opened for reading/writing",
378  289: "No file or serial port opened for reading/writing",
379  290: "A required port could not be found",
380  291: "The low-level port handler failed to initialize",
381  292: "A calibration routine failed",
382  293: "The in-config check of the device failed",
383  294: "The operation is once only and has already been performed",
384  295: "The single connected device is configured as a slave",
385  296: "More than one master was detected",
386  297: "A device was detected that was neither master nor slave",
387  298: "No master detected",
388  299: "A device is not sending enough data",
389  300: "The version of the object is too low for the requested "
390  "operation",
391  301: "The object has an unrecognised version, so it's not safe to "
392  "perform the operation",
393  302: "The process was aborted by an external event, usually a user "
394  "action or process termination",
395  303: "The requested functionality is not supported by the device",
396  304: "A packet counter value was missed",
397  305: "An error occurred while trying to put the device in measurement "
398  "mode",
399  306: "A device could not start recording",
400  311: "Radio channel is in use by another system",
401  312: "Motion tracker disconnected unexpectedly",
402  313: "Too many motion trackers connected",
403  314: "A device could not be put in config mode",
404  315: "Device has gone out of range",
405  316: "Device is back in range, resuming normal operation",
406  317: "The device was disconnected",
407  400: "The device is shutting down "
408  }
409 
410  def __init__(self, code):
411  self.code = code
412  self.message = self.ErrorCodes.get(code,
413  'Unknown error: 0x%02X' % code)
414 
415  def __str__(self):
416  return 'Error message 0x%02X: %s' % (self.code, self.message)
def __init__(self, message)
Definition: mtdef.py:293
def get_BRID(cls, baudrate)
Definition: mtdef.py:210
def getMIDName(mid)
Definition: mtdef.py:175
list Baudrates
Definition: mtdef.py:190
def __init__(self, message)
Definition: mtdef.py:285
def get_BR(cls, baudrate_id)
Definition: mtdef.py:218
def __init__(self, code)
Definition: mtdef.py:410
def getName(cls, value)
Definition: mtdef.py:166
def __str__(self)
Definition: mtdef.py:288
def __str__(self)
Definition: mtdef.py:415


xsens_driver
Author(s):
autogenerated on Mon Sep 9 2019 03:44:33