run_special_motion_jump.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_1642733392336.txt'
  31. #dir_name = 'android_com.ouj.paoku_1642735574865.txt'
  32. #dir_name = 'android_com.ouj.paoku_1642494915250.txt'
  33. ctypes.cdll.LoadLibrary(
  34. r"C:\Users\Administrator\source\repos\CMakeTestProject\CMakeTestProject\bin\SDK_LIB.dll")
  35. lib = ctypes.cdll.LoadLibrary(
  36. r"C:\Users\Administrator\source\repos\CMakeTestProject\CMakeTestProject\bin\python_interface.dll")
  37. lib.getShoesJump.restype = ctypes.c_int
  38. lib.DanceObject(1) # 初始化静态变量为跳舞毯游戏
  39. lib.getShoesJump.argtypes = [ctypes.c_int, npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  40. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  41. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  42. ctypes.c_int, ctypes.c_int,
  43. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  44. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  45. npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
  46. ctypes.c_int, ctypes.c_int,
  47. ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int
  48. ]
  49. with open(path + dir_name, "r") as f:
  50. for line in f.readlines():
  51. data = line.strip('\n')
  52. data = data.split(',')
  53. data = list(map(int, data))
  54. # print(data)
  55. right_pos_data = np.array(data[0:3], dtype=np.int)
  56. right_att_data = np.array(data[3:6], dtype=np.int)
  57. right_acc_data = np.array(data[6:9], dtype=np.int)
  58. right_front_mag = int(data[9])
  59. right_back_mag = int(data[10])
  60. right_zupt = int(data[11])
  61. left_pos_data = np.array(data[12:15], dtype=np.int)
  62. left_att_data = np.array(data[15:18], dtype=np.int)
  63. left_acc_data = np.array(data[18:21], dtype=np.int)
  64. left_front_mag = int(data[21])
  65. left_back_mag = int(data[22])
  66. left_zupt = int(data[23])
  67. down = int(data[24])
  68. jump = int(data[25])
  69. rssi = int(data[26])
  70. posTimeStamp = int(data[27])
  71. right_step = int(data[28])
  72. left_step = int(data[29])
  73. '''
  74. lib.gameProcess(posTimeStamp, right_pos_data, right_att_data, right_acc_data, right_zupt, right_front_mag,
  75. left_pos_data, left_att_data, left_acc_data, left_zupt, left_front_mag,
  76. jump, down, rssi, 0)
  77. '''
  78. down_tag = lib.getShoesJump(posTimeStamp, right_pos_data, right_att_data, right_acc_data, right_zupt, right_front_mag,
  79. left_pos_data, left_att_data, left_acc_data, left_zupt, left_front_mag,
  80. right_front_mag, left_front_mag, right_back_mag, left_back_mag)
  81. shoes_down.append(down_tag * 30000)
  82. phone_down.append(jump * 18000)
  83. left_front_mag_buff.append(left_front_mag)
  84. right_front_mag_buff.append(right_front_mag)
  85. left_back_mag_buff.append(left_back_mag)
  86. right_back_mag_buff.append(right_back_mag)
  87. if __name__ == '__main__':
  88. calGameData()
  89. fig, ax = plt.subplots()
  90. ax.plot(right_front_mag_buff, label = 'right_front_mag')
  91. ax.plot(left_front_mag_buff, label = 'left_front_mag')
  92. ax.plot(right_back_mag_buff, label = 'right_back_mag')
  93. ax.plot(left_back_mag_buff, label = 'left_back_mag')
  94. ax.plot(shoes_down, label = 'shoes_down')
  95. ax.plot(phone_down, label='phone_down')
  96. ax.legend()
  97. plt.grid()
  98. plt.show()
  99. plt.pause(0)