run_special_motion.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # -*- coding:utf-8 -*-
  2. import matplotlib.pyplot as plt
  3. import ctypes
  4. import numpy.ctypeslib as npct
  5. import time
  6. import threading
  7. import numpy as np
  8. import time
  9. listen_status = 1
  10. right_acc_z_data = [0] * 500
  11. left_acc_z_data = [0] * 500
  12. left_zupt_data = [0] * 500
  13. right_zupt_data = [0] * 500
  14. x = list(range(500))
  15. left_x_data = []
  16. left_y_data = []
  17. right_x_data = []
  18. right_y_data = []
  19. CAL_STATUS = 1
  20. SHOW_TATUS = 2
  21. cal_or_read = CAL_STATUS
  22. shoes_down = []
  23. phone_down = []
  24. left_front_mag_buff = []
  25. right_front_mag_buff = []
  26. left_back_mag_buff = []
  27. right_back_mag_buff = []
  28. def calGameData():
  29. path = 'F:\work\matlab\手机数据显示\\'
  30. dir_name = 'android_com.ouj.paoku_1644993592935.txt'
  31. #dir_name = 'android_com.ouj.paoku_1642494915250.txt'
  32. ctypes.cdll.LoadLibrary(
  33. r"C:\Users\Administrator\source\repos\CMakeTestProject\CMakeTestProject\bin\SDK_LIB.dll")
  34. lib = ctypes.cdll.LoadLibrary(
  35. r"C:\Users\Administrator\source\repos\CMakeTestProject\CMakeTestProject\bin\python_interface.dll")
  36. lib.getShoesDown.restype = ctypes.c_int
  37. lib.DanceObject(1) # 初始化静态变量为跳舞毯游戏
  38. lib.getShoesDown.argtypes = [ctypes.c_int, npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  39. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  40. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  41. ctypes.c_int, ctypes.c_int,
  42. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  43. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  44. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  45. ctypes.c_int, ctypes.c_int,
  46. ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int
  47. ]
  48. with open(path + dir_name, "r") as f:
  49. for line in f.readlines():
  50. data = line.strip('\n')
  51. data = data.split(',')
  52. data = list(map(int, data))
  53. # print(data)
  54. right_pos_data = np.array(data[0:3], dtype=np.int)
  55. right_att_data = np.array(data[3:6], dtype=np.int)
  56. right_acc_data = np.array(data[6:9], dtype=np.int)
  57. right_front_mag = int(data[9])
  58. right_back_mag = int(data[10])
  59. right_zupt = int(data[11])
  60. left_pos_data = np.array(data[12:15], dtype=np.int)
  61. left_att_data = np.array(data[15:18], dtype=np.int)
  62. left_acc_data = np.array(data[18:21], dtype=np.int)
  63. left_front_mag = int(data[21])
  64. left_back_mag = int(data[22])
  65. left_zupt = int(data[23])
  66. down = int(data[24])
  67. jump = int(data[25])
  68. rssi = int(data[26])
  69. posTimeStamp = int(data[27])
  70. right_step = int(data[28])
  71. left_step = int(data[29])
  72. '''
  73. lib.gameProcess(posTimeStamp, right_pos_data, right_att_data, right_acc_data, right_zupt, right_front_mag,
  74. left_pos_data, left_att_data, left_acc_data, left_zupt, left_front_mag,
  75. jump, down, rssi, 0)
  76. '''
  77. down_tag = lib.getShoesDown(posTimeStamp, right_pos_data, right_att_data, right_acc_data, right_zupt, right_front_mag,
  78. left_pos_data, left_att_data, left_acc_data, left_zupt, left_front_mag,
  79. right_front_mag, left_front_mag, right_back_mag, left_back_mag)
  80. shoes_down.append(down_tag * 30000)
  81. phone_down.append(down * 18000)
  82. left_front_mag_buff.append(left_front_mag)
  83. right_front_mag_buff.append(right_front_mag)
  84. left_back_mag_buff.append(left_back_mag)
  85. right_back_mag_buff.append(right_back_mag)
  86. if __name__ == '__main__':
  87. calGameData()
  88. fig, ax = plt.subplots()
  89. ax.plot(right_front_mag_buff, label = 'right_front_mag')
  90. ax.plot(left_front_mag_buff, label = 'left_front_mag')
  91. ax.plot(right_back_mag_buff, label = 'right_back_mag')
  92. ax.plot(left_back_mag_buff, label = 'left_back_mag')
  93. ax.plot(shoes_down, label = 'shoes_down')
  94. ax.plot(phone_down, label='phone_down')
  95. ax.legend()
  96. plt.grid()
  97. plt.show()
  98. plt.pause(0)