!pip freeze %pylab inline ls ../data import pandas coordinates = pandas.read_csv('../data/CAREN_Trial04_dof.txt', delimiter='\t', index_col="TimeStamp") speeds = pandas.read_csv('../data/CAREN_Trial04_dofvel.txt', delimiter='\t', index_col="TimeStamp") generalized_forces = pandas.read_csv('../data/CAREN_Trial04_jointmoment.txt', delimiter='\t', index_col="TimeStamp") ground_reaction_forces = pandas.read_csv('../data/CAREN_Trial04_grf.txt', delimiter='\t', index_col="TimeStamp") raw_data = pandas.read_csv('../data/CAREN_Trial04.txt', delimiter='\t', index_col="TimeStamp") for df in [coordinates, speeds, generalized_forces, ground_reaction_forces, raw_data]: print(df) print('=' * 50) coordinates['RKneeFlexion'].plot(figsize=(12.0, 8.0)) raw_data['TreadmillSpeed'].plot(figsize=(12.0, 8.0)) ground_reaction_forces['LFx'][500:1000].plot(figsize=(12.0, 8.0)) ground_reaction_forces['LFy'][500:1000].plot(figsize=(12.0, 8.0)) ground_reaction_forces['LFz'][500:1000].plot(figsize=(12.0, 8.0)) coordinates['RKneeFlexion'].plot(figsize=(12.0, 8.0)) raw_data['TreadmillSpeed'].to_csv('treadmill-speed.csv') !head treadmill-speed.csv import numpy as np speed_array = np.loadtxt('treadmill-speed.csv', delimiter=',') speed_array[:, 0] from dtk import walk reload(walk) walk.gait_landmarks_from_grf(ground_reaction_forces.index.values.astype(float), ground_reaction_forces['RFy'], ground_reaction_forces['LFy'], do_plot=True, min_time=15.0, threshold=5.0) obinna = pandas.read_csv('../data/obinna-walking.txt', delimiter='\t', index_col="TimeStamp", na_values='0.000000') obinna.head() [col for col in obinna.columns if col.endswith('.Ang') or col.endswith('ForY') or col.endswith('.Mom')] obinna['FP2.ForY'][1000:2000].plot(figsize=(12,10)) start = 1100 stop = 2000 right_strikes, left_strikes, right_toe_off, left_toe_off = \ walk.gait_landmarks_from_grf(obinna.index.values.astype(float)[start:stop], obinna['FP1.ForY'][start:stop], obinna['FP2.ForY'][start:stop], do_plot=True, min_time=15.0, threshold=28.0) obinna['FP2.ForY'].to_csv('../data/example_vertical_grf.csv') first_foot_down = obinna[right_strikes[0]:right_toe_off[1]] second_foot_down = obinna[right_strikes[1]:right_toe_off[2]] first_foot_down['FP1.ForY'].shape second_foot_down['FP1.ForY'].shape from dtk import process # this is giving different answers depending on the guess value process.find_timeshift(first_foot_down['FP1.ForY'][:-2].values, second_foot_down['FP1.ForY'].values, 100, guess=0.01, plot=True) figure(figsize=(10, 8)) right_steps = {} for i, heel in enumerate(right_strikes[:-1]): right_steps[i] = obinna[heel:right_toe_off[i + 1]] print(len(right_steps[i])) time = process.time_vector(len(right_steps[i]), 100) right_steps[i].index = time plot(time, right_steps[i]['FP1.ForY'],) #right_steps = pandas.Panel(right_steps) right_steps = pandas.Panel(right_steps) mean_right_steps = right_steps.mean(axis='items') mean_right_steps['FP1.ForY'].plot() right_steps = right_steps.fillna(method='pad') from dtk import walk solver = walk.SimpleControlSolver(right_steps) sensors = ['RKneeFlexion.Ang', 'RHipFlexion.Ang','RAnklePlantarFlexion.Ang'] sensors = ['RKneeFlexion.Ang', 'RAnklePlantarFlexion.Ang'] controls = ['RKneeFlexion.Mom', 'RHipFlexion.Mom', 'RAnklePlantarFlexion.Mom'] gains, sensors = solver.solve(sensors, controls) gains.shape figure(figsize=(10, 8)) plot(gains.reshape(79, 6))