123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- # -*- coding:utf-8 -*-
- import matplotlib.pyplot as plt
- import ctypes
- import numpy.ctypeslib as npct
- import time
- import threading
- import numpy as np
- import time
- fig = plt.figure()
- ax = fig.add_subplot(1, 1, 1)
- ax.axis("equal")
- plt.ion()
- is_exit = 0
- listen_status = 1
- right_acc_z_data = [0] * 500
- left_acc_z_data = [0] * 500
- left_zupt_data = [0] * 500
- right_zupt_data = [0] * 500
- x = list(range(500))
- left_x_data = []
- left_y_data = []
- right_x_data = []
- right_y_data = []
- CAL_STATUS = 1
- SHOW_TATUS = 2
- cal_or_read = CAL_STATUS
- def update_pos():
- plt.ioff()
- plt.clf()
- ax.scatter(left_x_data, left_y_data, c='r')
- ax.scatter(right_x_data, right_y_data, c='b')
- plt.show()
- def calGameData():
- global is_exit, listen_status, cal_or_read
- num = 0
- path = './data_set/'
- dir_name = 'android_com.ouj.dance_1640243695795.txt'
- ctypes.cdll.LoadLibrary(
- r"C:\Users\Administrator\source\repos\CMakeTestProject\CMakeTestProject\bin\SDK_LIB.dll")
- lib = ctypes.cdll.LoadLibrary(r"C:\Users\Administrator\source\repos\CMakeTestProject\CMakeTestProject\bin\python_interface.dll")
- lib.getGamePos.restype = ctypes.c_float
- lib.DanceObject(2) # 初始化静态变量为跳舞毯游戏
- lib.gameProcess.argtypes = [ctypes.c_int,
- npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
- npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
- npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
- ctypes.c_int, ctypes.c_int,ctypes.c_int,
- npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
- npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
- npct.ndpointer(dtype=np.int, ndim=1, flags="C_CONTIGUOUS"),
- ctypes.c_int, ctypes.c_int, ctypes.c_int,
- ctypes.c_int, ctypes.c_int, ctypes.c_int
- ]
- with open(path + dir_name, "r") as f:
- for line in f.readlines():
- data = line.strip('\n')
- data = data.split(',')
- data = list(map(int, data))
- # print(data)
- right_pos_data = np.array(data[0:3], dtype=np.int)
- right_att_data = np.array(data[3:6], dtype=np.int)
- right_acc_data = np.array(data[6:9], dtype=np.int)
- right_front_mag = int(data[9])
- right_back_mag = int(data[10])
- right_zupt = int(data[11])
- left_pos_data = np.array(data[12:15], dtype=np.int)
- left_att_data = np.array(data[15:18], dtype=np.int)
- left_acc_data = np.array(data[18:21], dtype=np.int)
- left_front_mag = int(data[21])
- left_back_mag = int(data[22])
- left_zupt = int(data[23])
- down = int(data[24])
- jump = int(data[25])
- rssi = int(data[26])
- posTimeStamp = int(data[27])
- right_step = int(data[28])
- left_step = int(data[29])
- # 缓存加速度
- left_acc_z_data[0:499] = left_acc_z_data[1:500]
- left_acc_z_data[-1] = left_acc_data[2] / 2048.0
- right_acc_z_data[0:499] = right_acc_z_data[1:500]
- right_acc_z_data[-1] = right_acc_data[2] / 2048.0 + 1
- left_zupt_data[0:499] = left_zupt_data[1:500]
- left_zupt_data[-1] = left_zupt
- right_zupt_data[0:499] = right_zupt_data[1:500]
- right_zupt_data[-1] = right_zupt + 1
- lib.gameProcess(posTimeStamp, right_pos_data, right_att_data, right_acc_data, right_zupt, right_front_mag, right_back_mag,
- left_pos_data, left_att_data, left_acc_data, left_zupt, left_front_mag, left_back_mag,
- jump, down, rssi)
- left_pos_x = lib.getGamePos(1, 0)
- left_pos_y = lib.getGamePos(1, 1)
- left_x_data.append(left_pos_x)
- left_y_data.append(left_pos_y)
- right_pos_x = lib.getGamePos(0, 0)
- right_pos_y = lib.getGamePos(0, 1)
- right_x_data.append(right_pos_x)
- right_y_data.append(right_pos_y)
- cal_or_read = SHOW_TATUS
- update_pos()
- time.sleep(0.01)
- print("num = ", num)
- num=num+1
- while listen_status == 0:
- pass
- is_exit = 1
- import os
- def file_name(file_dir):
- for root, dirs, files in os.walk(file_dir):
- print(np.shape(files), type(files), files)
- if __name__ == '__main__':
- calGameData()
- while is_exit == 0:
- pass
- plt.pause(0)
|