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


xsens_driver
Author(s):
autogenerated on Thu Jun 6 2019 19:13:05