Exemple #1
0
import pandas as pd
from readSto import readStoFile
import numpy as np
from interpDFrame import interpDFrame
import matplotlib.pyplot as plt

# Plot simulated muscle activation vs. EMG signal

# Right Foot Strike (RFS) times
RFS1 = 0.863
RFS2 = 1.546

# ------------------------------------------------------
# Import CMC states file
cmc_results_dir = '../CMC/run/results'
cmc = readStoFile(cmc_results_dir + '/cmc_states.sto')

# Load emg activity
emg = pd.read_csv('emg_run.txt', sep='\t')

min_time = np.amax([np.amin(cmc['time']), np.amin(emg['time'])])

# recalc values as a function of the gait cycle percent
cmc_interp = interpDFrame(cmc, RFS1, RFS2, min_time)
emg_interp = interpDFrame(emg, RFS1, RFS2, min_time)

cmc_pct = cmc_interp['percentgaitcycle']
emg_pct = emg_interp['percentgaitcycle']

# ------------------------------------------------------
# Plot EMG (cyan) vs. CMC (blue) muscle activity
Exemple #2
0
pelvis_trans = ['pelvis_tx', 'pelvis_ty', 'pelvis_tz']
pelvis_rot = ['pelvis_tilt', 'pelvis_list', 'pelvis_rotation']
lumbar = ['lumbar_extension', 'lumbar_bending', 'lumbar_rotation']
le = [
    'hip_flexion_r', 'hip_adduction_r', 'hip_rotation_r', 'knee_angle_r',
    'ankle_angle_r', 'hip_flexion_l', 'hip_adduction_l', 'hip_rotation_l',
    'knee_angle_l', 'ankle_angle_l'
]
ue = [
    'arm_flex_r', 'arm_add_r', 'arm_rot_r', 'elbow_flex_r', 'pro_sup_r',
    'arm_flex_l', 'arm_add_l', 'arm_rot_l', 'elbow_flex_l', 'pro_sup_l'
]

# load ik/rra kinematic errors
rra_results_dir = '../RRA/run/results_rra_2'
rra_run_pErr = readStoFile(rra_results_dir + '/rra_run_2_pErr.sto')
#for n in rra_run_pErr.columns : print n

rra_run_pErr_pelvisTrans = rra_run_pErr[pelvis_trans].values
rra_run_pErr_pelvisRot = rra_run_pErr[pelvis_rot].values
rra_run_pErr_lumbarRot = rra_run_pErr[lumbar].values
rra_run_pErr_leRot = rra_run_pErr[le].values
rra_run_pErr_ueRot = rra_run_pErr[ue].values

# print to console
print
print
print 'runing ik/rra errors'
print 'max rms pelvis error'
print '   ', 100 * np.amax(matRMS(rra_run_pErr_pelvisTrans)), ' (trans, cm)'
print '   ', 100 * np.amax(matRMS(rra_run_pErr_pelvisRot)), ' (rot, deg)'
cmc_results_dir = '../CMC/walk/results'

# Right Foot Strike (RFS) times
RFS1 = 0.248
RFS2 = 1.3925

# ---------------------------------------------------------
# Load simulation outputs from file,
# normalize time to % gait cycle,
# and calculate net muscle-generated joint moments

#----------------------------------------------------------
# ID
id_filename = id_results_dir + '/inverse_dynamics.sto'

df = readStoFile(id_filename)
#df.columns

# put columns of interest into a new dataframe
time = df['time']
# min time is the same for id and cmc
min_time = np.amin(time)
hipflex = df['hip_flexion_r_moment']
hipflex.name = 'hipflex'
kneeext = -df['knee_angle_r_moment']
kneeext.name = 'kneeext'
ankleext = -df['ankle_angle_r_moment']
ankleext.name = 'ankleext'

# make dataframe from the id joint moments
idJointMoments = pd.concat([time, hipflex, kneeext, ankleext], axis=1)