for run in test_vel:
    data[str(run)] = pd.DataFrame(columns=['imu_ang_z', 'elapsed'])
    t0 = time.time()
    ptu_on = False
    imu_ang_z = np.zeros(N)

    for i in range(N):
        if ptu_on == False:
            #            print(time.time()-t0)
            if time.time() - t0 > 2:
                ptu_on = True
                ptu.cmd('@01SSPD' + str(test_vel[cnt]) + '\r')
                print('@01SSPD' + str(test_vel[cnt]) + '\r')
                ptu.cmd('@01J+\r')
#        print('test22')
        imu_ang_z[i] = imu.grab_ang_r().z  #this is the line failing
        #        print('test33')
        time.sleep(0.005)
    t1 = time.time()
    ptu.cmd('@01STOP\r')
    hz = N / (t1 - t0)
    data[str(run)]['elapsed'] = np.linspace(0, t1 - t0, len(imu_ang_z))
    data[str(run)]['imu_ang_z'] = imu_ang_z
    cnt += 1
    time.sleep(2)
    print(cnt)

time.sleep(0.5)

plt.figure()
for run in test_vel:
Exemplo n.º 2
0
#Initiate pandas dataframe to store IMU data in
data = pd.DataFrame(columns=[
    'accel_x', 'accel_y', 'accel_z', 'angr_x', 'angr_y', 'angr_z', 'mag_x',
    'mag_y', 'mag_z', 'elapsed'
])

t_start = time.time()
print('Recording VN100 IMU data for', record_time, 'seconds')
while (time.time() - t_start) < record_time:

    #Grab time at beginning of each iteration to keep sampling time frequency consistent
    t0 = time.time()

    #Grab imu data
    imu.grab_accel()
    imu.grab_ang_r()
    imu.grab_mag()

    #Grab timestamp and add row to dataframe
    elapsed = time.time() - t_start
    data_add = [
        imu.accel.x, imu.accel.y, imu.accel.z, imu.ang_r.x, imu.ang_r.y,
        imu.ang_r.z, imu.mag.x, imu.mag.y, imu.mag.z, elapsed
    ]
    data.loc[datetime.now()] = data_add

    #Sleep until sampling time has expired
    t_diff = time.time() - t0
    if delay - t_diff > 0:
        time.sleep(delay - t_diff)