imu_slave.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from nbus_slave import *
  2. class ImuSlave(NbusSlave):
  3. def __init__(self, module, comm_port):
  4. NbusSlave.__init__(self, module, comm_port)
  5. def evaluate_param_value(self, sensor, param, val):
  6. value = -1
  7. if param == PARAM_RANGE:
  8. value = 2 ** (val + 1) # +/- 2, 4, 8, 16g
  9. if param == PARAM_SAMPLERATE:
  10. if val == 1:
  11. value = 562.5
  12. if val == 3:
  13. value = 281.3
  14. if val == 5:
  15. value = 187.5
  16. if val == 7:
  17. value = 140.6
  18. if val == 10:
  19. value = 102.3
  20. if val == 15:
  21. value = 70.3
  22. if val == 22:
  23. value = 48.9
  24. if val == 31:
  25. value = 32.2
  26. if val == 63:
  27. value = 17.6
  28. if val == 127:
  29. value = 8.8
  30. if val == 255:
  31. value = 4.4
  32. if val == 513:
  33. value = 2.2
  34. if val == 1022:
  35. value = 1.1
  36. if val == 2044:
  37. value = 0.55
  38. if val == 4095:
  39. value = 0.27
  40. if param == PARAM_FILTER:
  41. value = (val - 1)
  42. self.slave_params[sensor][param] = value
  43. return value
  44. def cmd_sensor_get_data_IMU(self, sensor_index):
  45. [x, y, z] = self._cmd_sensor_get_data(sensor_index)
  46. z = z - 16384 / (self.slave_params[sensor_index][PARAM_RANGE]/2)
  47. if x > 32768:
  48. x = x - 65535
  49. if y > 32768:
  50. y = y - 65535
  51. if z > 32768:
  52. z = z - 65535
  53. x = x/16384 * (self.slave_params[sensor_index][PARAM_RANGE]/2)
  54. y = y/16384 * (self.slave_params[sensor_index][PARAM_RANGE]/2)
  55. z = z/16384 * (self.slave_params[sensor_index][PARAM_RANGE]/2)
  56. return [x, y, z]