def plotRelationLceAPForces(muscle_stretch,muscle_stimulation=1.,l_opt=0.11): # Defination of muscles parameters = MuscleParameters() # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) sys.muscle.L_OPT = l_opt # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Store the results l_ce = [] active = [] passive = [] tendon = [] # Run the experiment for different length of the MTU for l in muscle_stretch: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=l) l_ce.append(result.l_ce[-1]) active.append(result.active_force[-1]) passive.append(result.passive_force[-1]) tendon.append(result.tendon_force[-1]) plt.figure('Active/passive forces as function of l_ce\n'+ '(activation: {}, l_opt: {})' .format(muscle_stimulation,l_opt)) plt.plot(l_ce, active,label='active force') plt.plot(l_ce, passive,label='passive force') plt.plot(l_ce, tendon,label='tendon force') plt.legend() plt.title('Isometric muscle experiment\nActive/passive forces as function '+ 'of l_ce\n(activation: {}, l_opt: {})'.format(muscle_stimulation,l_opt)) plt.xlabel('l_ce [m]') plt.ylabel('Force [N]') axes = plt.gca() axes.set_xlim([0.05,0.2]) axes.set_ylim([0,1700]) plt.grid()
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length muscle_stretches = np.arange(.12, .30, .002) #muscle_tendon_forces = [] #Erase or comment muscle_active_forces = [] muscle_passive_forces = [] total_force = [] contractile_element_length = [] # Evalute for a single muscle stretch for muscle_stretch in muscle_stretches: # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.3 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) # muscle_tendon_forces.append(result.tendon_force[-1])#Erase or comment muscle_active_forces.append(result.active_force[-1]) muscle_passive_forces.append(result.passive_force[-1]) total_force.append(result.active_force[-1] + result.passive_force[-1]) contractile_element_length.append(result.l_ce[-1]) # plotXY(time,result.l_ce,'Time [s]','Contractile Element Length [m]','Active', # 'Isometric Muscle: Contractile Element Length vs Time', # 'Isometric Muscle: Contractile Element Length vs Time') # plotXY(result.l_ce,result.active_force,'Contractile Element Length [m]','Active Force [N]','Active', # 'Isometric Muscle: Contractile Element Length vs Force', # 'Isometric Muscle: Contractile Element Length vs Force') # plt.plot(result.l_ce, result.passive_force, label='passive') # plt.plot(result.l_ce, result.active_force+result.passive_force, label='total') # Plotting plt.figure('Isometric Muscle: L_ce vs Force') plt.plot(contractile_element_length, muscle_active_forces, label='active') plt.plot(contractile_element_length, muscle_passive_forces, label='passive') plt.plot(contractile_element_length, total_force, label='total') plt.title('Isometric Muscle: Stretch Length vs Force') plt.xlabel('Contractile Element Length [m]') plt.ylabel('Muscle Force [N]') plt.legend(loc='upper right') plt.grid()
def exercise1c(): """describe how fiber length influences the force-length curve. Compare a muscle comprised of short muscle fibers to a muscle comprised of long muscle fibers. Change the parameter, you can use system_parameters.py::MuscleParameters before instantiating the muscle No more than 2 plots are required. """ # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length muscle_lengths = np.arange(.1, .26, .03) max_muscle_active_forces = [] max_muscle_passive_forces = [] max_total_force = [] max_force_stretch = [] # Evalute for a single muscle stretch for muscle_length in muscle_lengths: parameters.l_opt = muscle_length muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) if muscle_length < .16: start_stretch_length = .16 else: start_stretch_length = muscle_length muscle_stretches = np.arange( start_stretch_length, 1.2 * muscle_length + .16, (1.2 * muscle_length + .16 - start_stretch_length) / 40) muscle_active_forces = [] muscle_passive_forces = [] total_force = [] # Evalute for a single muscle stretch for muscle_stretch in muscle_stretches: # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.3 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) muscle_active_forces.append(result.active_force[-1]) muscle_passive_forces.append(result.passive_force[-1]) total_force.append(result.active_force[-1] + result.passive_force[-1]) max_muscle_active_forces.append(max(muscle_active_forces)) active_max_index = muscle_active_forces.index( max(muscle_active_forces)) max_muscle_passive_forces.append( muscle_passive_forces[active_max_index]) max_total_force.append(total_force[active_max_index]) max_force_stretch.append(muscle_stretches[active_max_index]) # Plotting max force for each muscle length over different stretch values. Uncomment to see (adds ~8 plots) # plt.figure('Isometric muscle experiment. L_opt = %.2f'%(muscle_length)) # plt.plot(muscle_stretches, muscle_active_forces, label='active') # plt.plot(muscle_stretches, muscle_passive_forces, label='passive') # plt.plot(muscle_stretches, total_force, label='total') # plt.title('Isometric muscle experiment 1C, L_opt = %.2f'%(muscle_length)) # plt.xlabel('Stretch Length [m]') # plt.ylabel('Muscle Force [N]') # plt.legend(loc='upper left') # plt.grid() # Plotting active on its own plt.figure('Isometric muscle experiment, Active Force') plt.plot(muscle_stretches, muscle_active_forces, label=('L_opt = %.2f' % (muscle_length))) plt.title('Isometric muscle experiment: Active Force vs L_Opt') plt.xlabel('Stretch Length [m]') plt.ylabel('Active Muscle Force [N]') plt.legend(loc='upper left') plt.grid() # Plotting passive on its own plt.figure('Isometric muscle experiment, Passive Force') plt.plot(muscle_stretches, muscle_passive_forces, label=('L_opt = %.2f' % (muscle_length))) plt.title('Isometric muscle experiment: Passive Force vs L_Opt') plt.xlabel('Stretch Length [m]') plt.ylabel('Passive Muscle Force [N]') plt.legend(loc='upper left') plt.grid() # Plot max vals plt.figure('Isometric muscle experiment max Force') plt.plot(muscle_lengths, max_muscle_active_forces, label='active') #plt.plot(muscle_lengths, max_muscle_passive_forces, label='passive') #plt.plot(muscle_lengths, max_total_force, label='total') plt.title('Isometric muscle experiment 1C, Max') plt.xlabel('Muscle Optimal Length [m]') plt.ylabel('Max Muscle Force [N]') plt.legend(loc='upper left') plt.grid() # print(max_muscle_active_forces) # Plot max stretch lengths of max vals plt.figure('Isometric muscle experiment max Force stretch') plt.plot(muscle_lengths, max_force_stretch, label='active') #plt.plot(muscle_lengths, max_muscle_passive_forces, label='passive') #plt.plot(muscle_lengths, max_total_force, label='total') plt.title('Isometric muscle experiment 1C, Max Stretch') plt.xlabel('Muscle Optimal Length [m]') plt.ylabel('Muscle Stretch of Max Force [m]') plt.legend(loc='upper left') plt.grid()
def exercise1b(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length stimulations = np.arange(.0, 1.0, .02) stretches = np.arange(.12, .36, .05) #default length is 0.24 allStretches = [] allStims = [] allActForces = [] allPassForces = [] allNetForces = [] for stretch in stretches: # Evalute for a single muscle stretch muscle_active_forces = [] muscle_passive_forces = [] total_force = [] l_ce = [] for stimulation in stimulations: # Evalute for a single muscle stimulation muscle_stimulation = stimulation # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.3 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=stretch) muscle_active_forces.append(result.active_force[-1]) muscle_passive_forces.append(result.passive_force[-1]) total_force.append(result.active_force[-1] + result.passive_force[-1]) l_ce.append(result.l_ce[-1]) allStretches.append(stretch) allStims.append(stimulation) allActForces.append(result.active_force[-1]) allPassForces.append(result.passive_force[-1]) allNetForces.append(total_force[-1]) # # Plotting results of individual trials to verify steady state assumption # plt.figure('Force over time with different stimulations and lengths %.2f' %stretch) # plt.plot(time, result.active_force, label='Active: Stim = %.2f'%stimulation + ' L = %.2f'%stretch) # plt.plot(time, result.passive_force, label='Passive: Stim = %.2f'%stimulation + ' L = %.2f'%stretch) # plt.plot(time, result.active_force+result.passive_force, label='Net: Stim = %.2f'%stimulation + ' L = %.2f'%stretch) # plt.title('Force over time with different stimulations and lengths') # plt.xlabel('Time [s]') # plt.ylabel('Active Muscle Force [N]') # plt.legend(loc='upper right') # plt.grid() # Plotting plt.figure('Isometric Muscle: Stimulation vs Force') plt.subplot(3, 1, 1) plt.plot(stimulations, muscle_active_forces, label='L_mtu = %.2f' % stretch) plt.title('Isometric Muscle: Stimulation vs Force') plt.xlabel('Stimulation') plt.ylabel('Active Force [N]') plt.legend(loc='upper right') plt.grid() plt.subplot(3, 1, 2) plt.plot(stimulations, muscle_passive_forces, label='L_mtu = %.2f' % stretch) plt.xlabel('Stimulation') plt.ylabel('Passive Force [N]') plt.legend(loc='upper right') plt.grid() plt.subplot(3, 1, 3) plt.plot(stimulations, total_force, label='L_mtu = %.2f' % stretch) plt.xlabel('Stimulation') plt.ylabel('Total Force [N]') plt.legend(loc='upper right') plt.grid() allActForces = np.array(allActForces).reshape( (stretches.size, stimulations.size)) allPassForces = np.array(allPassForces).reshape( (stretches.size, stimulations.size)) allNetForces = np.array(allNetForces).reshape( (stretches.size, stimulations.size)) stimulations, stretches = np.meshgrid(stimulations, stretches) fig1b = plt.figure('1b. Stim vs Active Force Surface Plot') ax = fig1b.gca(projection='3d') ax = fig1b.add_subplot(111, projection='3d') ax.plot_surface(stimulations, stretches, allActForces, cmap=cm.coolwarm, linewidth=0.5, antialiased=False) ax.set_xlabel('Stimulation') ax.set_ylabel('Muscle Length (m)') ax.set_zlabel('Active Force (N)') plt.title('Stimulation vs Active Force') fig1b = plt.figure('1b. Stim vs Passive Force Surface Plot') ax = fig1b.gca(projection='3d') ax = fig1b.add_subplot(111, projection='3d') ax.plot_surface(stimulations, stretches, allPassForces, cmap=cm.coolwarm, linewidth=0.5, antialiased=False) ax.set_xlabel('Stimulation') ax.set_ylabel('Muscle Length (m)') ax.set_zlabel('Passive Force (N)') plt.title('Stimulation vs Passive Force') fig1b = plt.figure('1b. Stim vs Total Force Surface Plot') ax = fig1b.gca(projection='3d') ax = fig1b.add_subplot(111, projection='3d') ax.plot_surface(stimulations, stretches, allNetForces, cmap=cm.coolwarm, linewidth=0.5, antialiased=False) ax.set_xlabel('Stimulation') ax.set_ylabel('Muscle Length (m)') ax.set_zlabel('Net Force (N)') plt.title('Stimulation vs Total Force')
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.5 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Evalute for a single muscle stimulation muscle_stimulation = np.arange(0, 1., 0.2) # Several muscle stretch muscle_stretches = np.arange(0, 0.3, 0.01) active_active = [] for stim in muscle_stimulation: active_forces = [] passive_forces = [] total = [] lengths = [] for stretch in muscle_stretches: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=stim, muscle_length=stretch) active_forces.append(result.active_force[-1]) passive_forces.append(result.passive_force[-1]) total.append(result.active_force[-1] + result.passive_force[-1]) lengths.append(result.l_ce[-1]) active_active.append(active_forces) # Plotting plt.figure('Isometric muscle experiment 1') plt.plot(lengths, active_forces) plt.plot(lengths, passive_forces) plt.plot(lengths, total) plt.title('Isometric muscle experiment stimulation') plt.xlabel('Muscle stretch') plt.ylabel('Muscle force') plt.legend(('Active', 'Passive', 'Total')) plt.grid() plt.show() # Plotting plt.figure('Isometric muscle experiment 2') for i in range(len(muscle_stimulation)): plt.plot(lengths, active_active[i]) plt.title('Isometric muscle experiment') plt.xlabel('Muscle stretch') plt.ylabel('Muscle force') plt.legend(muscle_stimulation) plt.grid() plt.show() # Plotting #plt.figure('Isotonic muscle experiment') #plt.plot(result.time, result.v_ce) #plt.title('Isotonic muscle experiment') #plt.xlabel('Time [s]') #plt.ylabel('Muscle contractilve velocity') #plt.grid() #muscle with longer l_opt muscle.L_OPT = 0.5 muscle_stimulation = 1. lce = [] totalF = [] activeF = [] passiveF = [] for stretch in muscle_stretches: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=stretch) activeF.append(result.active_force[-1]) passiveF.append(result.passive_force[-1]) lce.append(result.l_ce[-1]) totalF.append(result.active_force[-1] + result.passive_force[-1]) plt.figure('muscle with l_opt=0.5') plt.title('muscle with l_opt=0.5') plt.plot(lce, activeF) plt.plot(lce, passiveF) plt.plot(lce, totalF) plt.xlabel('Muscle Stretch') plt.ylabel('Force') plt.ylim((0, 4000)) plt.legend(('Active Force', 'Passive Force', 'Total Force')) plt.grid() #muscle with shorter l_opt t_start = 0.0 t_stop = 1 time_step = 0.005 time = np.arange(t_start, t_stop, time_step) muscle_stretches = np.arange(0, 0.3, 0.01) muscle.L_OPT = 0.075 muscle_stimulation = 1. lce = [] totalF = [] activeF = [] passiveF = [] plt.figure('muscle with l_opt=0.075') for stretch in muscle_stretches: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=stretch) activeF.append(result.active_force[-1]) passiveF.append(result.passive_force[-1]) lce.append(result.l_ce[-1]) totalF.append(result.active_force[-1] + result.passive_force[-1]) plt.title('muscle with l_opt=0.075') plt.plot(lce, activeF) plt.plot(lce, passiveF) plt.plot(lce, totalF) plt.xlabel('Muscle Stretch') plt.ylabel('Force') plt.ylim((0, 4000)) plt.legend(('Active Force', 'Passive Force', 'Total Force')) plt.grid()
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.l_opt # To get the muscle optimal length #x0 = [0.0, sys.muscle.L_OPT] # Evalute for a single muscle stretch muscle_stretch = 0.2 # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.l_opt] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) # Plotting plt.figure('Isometric muscle experiment') plt.plot(result.time, result.l_ce) plt.title('Isometric muscle experiment') plt.xlabel('Time [s]') plt.ylabel('Muscle contracticle length [m]') plt.grid() muscle_stretches = np.arange(0, muscle_stretch, 0.001) ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ### code for 1a pylog.info( "1a. relationship between forces and contractile element length") length_start = 0.0 length_stop = 0.3 length_step = 0.005 muscle_lengths = np.arange(length_start, length_stop, length_step) active_forces = [] passive_forces = [] total_forces = [] element_lengths = [] for temp_length in muscle_lengths: temp_result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=temp_length) temp_active_force = temp_result.active_force[-1] temp_passive_force = temp_result.passive_force[-1] tenp_total_force = temp_active_force + temp_passive_force temp_element_length = temp_result.l_ce[-1] active_forces = active_forces + [temp_active_force] passive_forces = passive_forces + [temp_passive_force] total_forces = total_forces + [tenp_total_force] element_lengths = element_lengths + [temp_element_length] plt.figure("1a. Isometric muscle experiment (muscle_stimulation == 1)") plt.plot(element_lengths, active_forces) plt.plot(element_lengths, passive_forces) plt.plot(element_lengths, total_forces) plt.title('Isometric Muscle Experiment (muscle_stimulation == 1)') plt.xlabel('Muscle contracticle length [m]') plt.ylabel('Tension [N]') plt.legend(("Active Force", "Passive Force", "Total force")) plt.grid() plt.show() ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ### code for 1b pylog.info( "1b. relationship between forces and contractile element length with different stimulations" ) length_start = 0.0 length_stop = 0.3 length_step = 0.005 muscle_lengths = np.arange(length_start, length_stop, length_step) muscle_stimulations = np.arange(0, muscle_stimulation + 0.1, 0.1) all_active_forces = [] all_passive_forces = [] all_total_forces = [] all_element_lengths = [] for temp_muscle_stimulation in muscle_stimulations: temp_active_forces = [] temp_passive_forces = [] temp_total_forces = [] temp_element_lengths = [] for temp_length in muscle_lengths: temp_result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=temp_muscle_stimulation, muscle_length=temp_length) temp_active_force = temp_result.active_force[-1] temp_passive_force = temp_result.passive_force[-1] tenp_total_force = temp_active_force + temp_passive_force temp_element_length = temp_result.l_ce[-1] temp_active_forces = temp_active_forces + [temp_active_force] temp_passive_forces = temp_passive_forces + [temp_passive_force] temp_total_forces = temp_total_forces + [tenp_total_force] temp_element_lengths = temp_element_lengths + [temp_element_length] all_active_forces = all_active_forces + [temp_active_forces] all_passive_forces = all_passive_forces + [temp_passive_forces] all_total_forces = all_total_forces + [temp_total_forces] all_element_lengths = all_element_lengths + [temp_element_lengths] plt.figure( '1b. Isometric muscle experiment for active forces with different stimulations' ) for i in range(len(muscle_stimulations)): plt.plot(all_element_lengths[i], all_active_forces[i]) plt.title( 'Isometric muscle experiment for active forces with different stimulations' ) plt.xlabel('Muscle contracticle length [m]') plt.ylabel('Tension [N]') temp_legends = [ 'stimulation = ' + format((temp_stimulation), '.1f') for temp_stimulation in muscle_stimulations ] plt.legend(temp_legends) plt.grid() plt.show() plt.figure( '1b. Isometric muscle experiment for passive forces with different stimulations' ) for i in range(len(muscle_stimulations)): plt.plot(all_element_lengths[i], all_passive_forces[i]) plt.title( 'Isometric muscle experiment for passive forces with different stimulations' ) plt.xlabel('Muscle contracticle length [m]') plt.ylabel('Tension [N]') temp_legends = [ 'stimulation = ' + format((temp_stimulation), '.1f') for temp_stimulation in muscle_stimulations ] plt.legend(temp_legends) plt.grid() plt.show() plt.figure( '1b. Isometric muscle experiment for total forces with different stimulations' ) for i in range(len(muscle_stimulations)): plt.plot(all_element_lengths[i], all_total_forces[i]) plt.title( 'Isometric muscle experiment for total forces with different stimulations' ) plt.xlabel('Muscle contracticle length [m]') plt.ylabel('Tension [N]') temp_legends = [ 'stimulation = ' + format((temp_stimulation), '.1f') for temp_stimulation in muscle_stimulations ] plt.legend(temp_legends) plt.grid() plt.show() ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ### code for 1c pylog.info( "1c. relationship between forces and contractile element length with different fiber lengths" ) short_opt = 0.05 medium_opt = 0.1 long_opt = 0.15 opt_range = [short_opt, medium_opt, long_opt] muscle_stimulation = 1. length_start = 0.0 length_stop = 0.3 length_step = 0.005 muscle_lengths = np.arange(length_start, length_stop, length_step) for temp_opt in opt_range: parameters = MuscleParameters(l_opt=temp_opt) muscle = Muscle(parameters) sys = IsometricMuscleSystem() sys.add_muscle(muscle) #muscle.L_OPT = temp_opt temp_active_forces = [] temp_passive_forces = [] temp_total_forces = [] temp_element_lengths = [] for temp_length in muscle_lengths: temp_result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=temp_length) temp_active_force = temp_result.active_force[-1] temp_passive_force = temp_result.passive_force[-1] tenp_total_force = temp_active_force + temp_passive_force temp_element_length = temp_result.l_ce[-1] temp_active_forces = temp_active_forces + [temp_active_force] temp_passive_forces = temp_passive_forces + [temp_passive_force] temp_total_forces = temp_total_forces + [tenp_total_force] temp_element_lengths = temp_element_lengths + [temp_element_length] plt.figure( "1c. Isometric muscle experiment with musle fiber length = " + format((temp_opt), '.2f')) plt.plot(temp_element_lengths, temp_active_forces) plt.plot(temp_element_lengths, temp_passive_forces) plt.plot(temp_element_lengths, temp_total_forces) plt.xlabel('Muscle contracticle length [m]') plt.ylabel('Tension [N]') plt.title("Isometric muscle experiment with musle fiber length = " + format((temp_opt), '.2f')) plt.legend(("Active Force", "Passive Force ", "Total Force ")) plt.grid() plt.show()
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length # Evalute for a single muscle stretch muscle_stretch = 0.2 # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) # muscle_length=np.arange(0,0.4,0.001) F_active=[] F_passive=[] F_total=[] F_length=[] # Exercice 1 a pylog.info("Ex 1a") for length in muscle_length: result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=length) F_active.append(result.active_force[-1]) F_passive.append(result.passive_force[-1]) F_total.append(result.active_force[-1]+result.passive_force[-1]) F_length.append(result.l_ce[-1]) if length==0.2: plt.figure('Single integration experiment') plt.title("Single Integration Experiment for Muscle length = 0.11") plt.plot(result.time,result.active_force) plt.plot(result.time,result.passive_force) plt.xlabel('Time [s]') plt.ylabel('Muscle force [N]') plt.legend(("Active Force","Passive Force")) plt.grid() plt.show() plt.figure("Isometric muscle experiment") plt.title("Isometric Muscle Experiments for Different Lengths") plt.plot(F_length,F_active) plt.plot(F_length,F_passive) plt.plot(F_length,F_total) plt.title('Isometric muscle experiment') plt.xlabel('Contractile Element Length [m]') plt.ylabel('Muscle force [N]') plt.legend(("Active","Passive","Total force")) plt.grid() plt.show() pylog.info("Ex 1b") # Exercise 1. b plt.figure("Isometric muscle experiment by changing the stimulation") different_stimulation=np.arange(0,1.2,0.2) # for stimulation in different_stimulation: for stimulation in different_stimulation: F_total=[] F_length=[] pylog.info("stimulation is {}".format(stimulation)) for length in muscle_length: result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=stimulation, muscle_length=length) F_total.append(result.active_force[-1]+result.passive_force[-1]) F_length.append(result.l_ce[-1]) plt.plot(F_length,F_total) plt.title("Isometric Muscle Experiments with different Stimulation values") plt.xlabel('Length [m]') plt.ylabel('Total muscle force [N]') plt.legend(("stimulation = 0","stimulation = 0.2","stimulation = 0.4","stimulation = 0.6","stimulation = 0.8","stimulation = 1")) plt.grid() plt.show() # 1/c fiber_opt_small=0.07 fiber_opt_medium=0.11 fiber_opt_long=0.16 lopt_list=[fiber_opt_small,fiber_opt_medium,fiber_opt_long] muscle_stimulation = 1 for lopt in lopt_list: print("RUNNING lopt=",lopt) parameters = MuscleParameters(l_opt=lopt) muscle = Muscle(parameters) sys = IsometricMuscleSystem() sys.add_muscle(muscle) F_active=[] F_passive=[] F_total=[] F_length=[] for length in muscle_length: result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=length) F_active.append(result.active_force[-1]) F_passive.append(result.passive_force[-1]) F_total.append(result.active_force[-1]+result.passive_force[-1]) F_length.append(result.l_ce[-2]) plt.figure("Isometric muscle experiment with length {}".format(lopt)) plt.plot(F_length,F_active) plt.plot(F_length,F_passive) plt.plot(F_length,F_total) plt.xlabel('Contractile Element Length [m]') plt.ylabel('Total Muscle Force [N]') plt.title("Isometric muscle experiment with length {}".format(lopt)) plt.legend(("Active","Passive","Total force")) plt.grid() plt.show()
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Evalute for a single muscle stimulation muscle_stimulation = 0.5 # Create time vector t_start = 0.0 t_stop = 0.3 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # Create stretch coefficient vector dL = np.linspace(-0.5, 0.5, num=50) len_ce = np.zeros(dL.size) # Create a steady state muscle force vector R_glob_1a = np.zeros((50)) R_pass_1a = np.zeros((50)) R_activ_1a = np.zeros((50)) """ 1.a) Effect of stretching coefficient on the muscle force """ for i in range(0, len(dL)): # Evalute for a single muscle stretch muscle_stretch = (sys.muscle.L_OPT + sys.muscle.L_SLACK) * (1 + dL[i]) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) R_glob_1a[i] = result.tendon_force[-1] R_pass_1a[i] = result.passive_force[-1] R_activ_1a[i] = result.active_force[-1] len_ce[i] = result.l_ce[-1] # # Plot Isometric muscle experiment # plt.figure('Isometric muscle experiment') # plt.plot(result.time, result.tendon_force) # plt.title('Isometric muscle experiment') # plt.xlabel('Time [s]') # plt.ylabel('Muscle force') # Plot force-length curve plt.figure('Forces as a function of stretching coefficient') # Passive Force plt.plot(dL, R_pass_1a) # Active Force plt.plot(dL, R_activ_1a) # Total force plt.plot(dL, R_glob_1a) plt.xlabel('Stretch coeffcient [%]') plt.ylabel('Muscle force [N]') plt.legend(['Passive Force', 'Active Force', 'Total Force']) plt.ylim([0, 4000]) plt.xlim([-0.4, 0.4]) plt.figure('Forces as a function of the contractile element length') # Passive Force plt.plot(len_ce, R_pass_1a) # Active Force plt.plot(len_ce, R_activ_1a) # Total force plt.plot(len_ce, R_glob_1a) plt.ylim([0, 4000]) plt.xlim([0.06, 0.18]) plt.xlabel('Contractile element Lenght [m]') plt.ylabel('Muscle force [N]') plt.legend(['Passive Force', 'Active Force', 'Total Force']) #plt.savefig('Forces_stretch_coeff') """1.b) Effect of muscle stimulation [-1,0] on muscle force as a function of stretch coefficient""" # Create a steady state muscle force vector R_glob_1b = np.zeros((5, 50)) R_pass_1b = np.zeros((5, 50)) R_act_1b = np.zeros((5, 50)) # Create muscle activation vector dS = np.linspace(0, 1, num=5) for i in range(0, len(dL)): for j in range(0, len(dS)): # Evalute for a single muscle stimulation muscle_stimulation = dS[j] # Evalute for a single muscle stretch muscle_stretch = (sys.muscle.L_OPT + sys.muscle.L_SLACK) * (1 + dL[i]) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) R_glob_1b[j, i] = result.tendon_force[-1] R_pass_1b[j, i] = result.passive_force[-1] R_act_1b[j, i] = result.active_force[-1] # Plot force-length curve for different muscle activation plt.figure('Forces as a function of dL for different muscle stimulation') plt.plot(dL, R_glob_1b[0, :]) plt.plot(dL, R_glob_1b[1, :]) plt.plot(dL, R_glob_1b[2, :]) plt.plot(dL, R_glob_1b[3, :]) plt.plot(dL, R_glob_1b[4, :]) plt.xlabel('Stretch coeffcient [%]') plt.ylabel('Muscle force [N]') plt.legend([ 'Stimulation = 0', 'Stimulation = 0.25', 'Stimulation = 0.5', 'Stimulation = 0.75', 'Stimulation = 1' ]) plt.title('Total forces') plt.ylim([0, 4000]) plt.figure( 'Active forces as a function of dL for different muscle stimulation') plt.plot(dL, R_act_1b[0, :]) plt.plot(dL, R_act_1b[1, :]) plt.plot(dL, R_act_1b[2, :]) plt.plot(dL, R_act_1b[3, :]) plt.plot(dL, R_act_1b[4, :]) plt.xlabel('Stretch coeffcient [%]') plt.ylabel('Muscle force [N]') plt.legend([ 'Stimulation = 0', 'Stimulation = 0.25', 'Stimulation = 0.5', 'Stimulation = 0.75', 'Stimulation = 1' ]) plt.title('Active forces') plt.figure( 'Passive forces as a function of dL for different muscle stimulation') plt.plot(dL, R_pass_1b[0, :]) plt.plot(dL, R_pass_1b[1, :]) plt.plot(dL, R_pass_1b[2, :]) plt.plot(dL, R_pass_1b[3, :]) plt.plot(dL, R_pass_1b[4, :]) plt.xlabel('Stretch coeffcient [%]') plt.ylabel('Muscle force [N]') plt.legend([ 'Stimulation = 0', 'Stimulation = 0.25', 'Stimulation = 0.5', 'Stimulation = 0.75', 'Stimulation = 1' ]) plt.title('Passive forces') """ 1.c) Effect of fiber length on force-length curve """ # Evalute for a single muscle stimulation muscle_stimulation = 0.5 # Create fiber length vector #dl=np.linspace(0.1,1,num=10) dl = [0.07, 0.11, 0.15] # Create a steady state muscle force vectors R_glob_1c = np.zeros((len(dl), len(dL))) # Create active force vectors R_act_1c = np.zeros((len(dl), len(dL))) # Create passive force vectors R_pas_1c = np.zeros((len(dl), len(dL))) # Create contractile element length vectors len_ce = np.zeros((len(dl), len(dL))) for i in range(0, len(dL)): for j in range(0, len(dl)): # Change the fiber length sys.muscle.L_OPT = dl[j] # Evalute for a single muscle stretch muscle_stretch = (sys.muscle.L_OPT + sys.muscle.L_SLACK) * (1 + dL[i]) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) R_glob_1c[j, i] = result.tendon_force[-1] R_act_1c[j, i] = result.active_force[-1] R_pas_1c[j, i] = result.passive_force[-1] len_ce[j, i] = result.l_ce[-1] plt.figure('Forces as a function of dL for different fiber lengths') for i in range(0, len(dl)): plt.plot(dL, R_glob_1c[i, :]) plt.xlabel('Strecth coeffcient') plt.ylabel('Muscle force') plt.legend(['Opt_len: 0.07', 'Opt_len: 0.11', 'Opt_len : 0.15']) plt.figure('Forces wrt CE length for different optimal lengths') for i in range(0, len(dl)): plt.plot(len_ce[i, :], R_glob_1c[i, :]) plt.legend(['Opt_len: 0.07', 'Opt_len: 0.11', 'Opt_len : 0.15']) for i in range(0, len(dl)): plt.axvline(dl[i], color='r', linestyle='--') mvs = np.max(R_act_1c, axis=1) mv = np.unique(np.round(mvs)) plt.axhline(mv, color='black', linestyle='--') plt.ylim([0, 3000]) plt.xlabel('Contractile elememnt length [m]') plt.ylabel('Muscle force [n]') plt.figure('Active forces') for i in range(0, len(dl)): plt.plot(len_ce[i, :], R_act_1c[i, :]) plt.xlabel('Contractile elememnt length [m]') plt.ylabel('Muscle force [n]') plt.legend(['Opt_len: 0.07', 'Opt_len: 0.11', 'Opt_len : 0.15']) plt.figure('Passive forces') for i in range(0, len(dl)): plt.plot(len_ce[i, :], R_pas_1c[i, :]) plt.xlabel('Contractile elememnt length [m]') plt.ylabel('Muscle force [n]') plt.legend(['Opt_len: 0.07', 'Opt_len: 0.11', 'Opt_len : 0.15'])
def exercise1a(): """ Exercise 1a """ # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Force-length curves # Evalute for various muscle stretch stretch_min = muscle.L_OPT stretch_max = muscle.L_OPT * 3 N_stretch = 100 muscle_stretch = np.arange(stretch_min, stretch_max, (stretch_max - stretch_min) / N_stretch) # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) activeF = np.zeros(N_stretch) passiveF = np.zeros(N_stretch) tendonF = np.zeros(N_stretch) lceF = np.zeros(N_stretch) for index_strech, stretch in enumerate(muscle_stretch): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=1.0, muscle_length=stretch) activeF[index_strech] = result.active_force[-1] passiveF[index_strech] = result.passive_force[-1] tendonF[index_strech] = result.tendon_force[-1] lceF[index_strech] = result.l_ce[-1] # Plotting plt.figure('Isometric Muscle Experiment 1a') plt.plot(lceF * 100 / muscle.L_OPT, activeF * 100 / muscle.F_MAX, label='Active Force') plt.plot(lceF * 100 / muscle.L_OPT, passiveF * 100 / muscle.F_MAX, label='Passive Force') plt.plot(lceF * 100 / muscle.L_OPT, tendonF * 100 / muscle.F_MAX, label=' Tendon Force') plt.axvline(100, linewidth=1, linestyle='--', color='r') plt.axvline(145, linewidth=1, linestyle='--', color='r') plt.xlabel('Contractile element length [% of $L_{opt}$]') plt.ylabel('Force [% of $F_{max}$]') plt.title( 'Force-length curves for isometric muscle experiment (Stimulation = 1.0)' ) plt.legend() plt.grid()
def exercise1c(): """ Exercice 1c """ # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Force-length curves # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) N_stretch = 40 activeF = np.zeros(N_stretch) passiveF = np.zeros(N_stretch) tendonF = np.zeros(N_stretch) lceF = np.zeros(N_stretch) # Evaluate for various optimal length l_opt_list = np.array([0.1, 0.3]) # Subplots grid n_plot = len(l_opt_list) n_subplot = int((np.sqrt(n_plot - 1)) + 1) if (n_plot <= n_subplot * (n_subplot - 1)): fig, axes = plt.subplots(n_subplot, n_subplot - 1) n_subplot2 = n_subplot - 1 else: fig, axes = plt.subplots(n_subplot, n_subplot) n_subplot2 = n_subplot for i, l_opt in enumerate(l_opt_list): # Evaluate for various muscle stretch muscle.L_OPT = l_opt stretch_min = muscle.L_OPT stretch_max = muscle.L_OPT * 3 muscle_stretch = np.arange(stretch_min, stretch_max, (stretch_max - stretch_min) / N_stretch) for stretch in range(len(muscle_stretch)): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=1., muscle_length=muscle_stretch[stretch]) activeF[stretch] = result.active_force[-1] passiveF[stretch] = result.passive_force[-1] tendonF[stretch] = result.tendon_force[-1] lceF[stretch] = result.l_ce[-1] plt.subplot(n_subplot, n_subplot2, i + 1) plt.plot(lceF, 100 * activeF / muscle.F_MAX, label='Active Force') plt.plot(lceF, 100 * passiveF / muscle.F_MAX, label='Passive Force') plt.plot(lceF, 100 * tendonF / muscle.F_MAX, label='Tendon Force') plt.axvline(l_opt, linestyle="--", color="r") plt.xlim([l_opt - 0.3, l_opt + 0.3]) plt.ylim([0, 120]) plt.xlabel('Contractile element length') plt.ylabel('Force [% of $F_{max}$]') plt.title('Optimal length = {} [m]'.format(l_opt)) plt.legend() plt.grid() plt.suptitle( 'Force-length curves for isometric muscle experiment with various muscle optimal lengths' ) fig.tight_layout()
def exercise1b(): """ Exercise 1b """ # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Force-length curves # Evalute for various muscle stretch stretch_min = muscle.L_OPT * 0.5 stretch_max = muscle.L_OPT * 2.8 N_stretch = 40 muscle_stretch = np.arange(stretch_min, stretch_max, (stretch_max - stretch_min) / N_stretch) # Evaluate for various muscle stimulation N_stim = 6 muscle_stimulation = np.round(np.arange(N_stim) / (N_stim - 1), 2) # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # Set the time for integration t_start = 0.0 t_stop = 0.3 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) activeF = np.zeros(N_stretch) passiveF = np.zeros(N_stretch) tendonF = np.zeros(N_stretch) lceF = np.zeros(N_stretch) # Plotting plt.figure('Isometric Muscle Experiment 1b') colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k'] for stim in range(len(muscle_stimulation)): pylog.info('Stimulation = {}'.format(stim)) activeF = np.zeros(N_stretch) tendonF = np.zeros(N_stretch) for stretch in range(len(muscle_stretch)): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation[stim], muscle_length=muscle_stretch[stretch]) activeF[stretch] = result.active_force[-1] if (stim == 0): passiveF[stretch] = result.passive_force[-1] tendonF[stretch] = result.tendon_force[-1] lceF[stretch] = result.l_ce[-1] color = colors[stim] plt.plot(lceF * 100 / muscle.L_OPT, 100 * activeF / muscle.F_MAX, color, label='Active Force - Stimulation = ' + str(round(muscle_stimulation[stim], 2))) plt.plot(lceF * 100 / muscle.L_OPT, 100 * passiveF / muscle.F_MAX, '+' + 'k', label='Passive Force') plt.title( 'Force-length curves for isometric muscle experiment with various muscle stimulations' ) plt.xlabel('Contractile element length [% of $L_{opt}$]') plt.ylabel('Force [% of $F_{max}$]') plt.legend() plt.grid()
def isometric_experiment(muscle_stimulation=1., ce_stretch_max=1.5, ce_stretch_min=0.5, nb_pts=1000, time_param=TimeParameters(), l_opt=None): """ Runs a experiments in isometric mode for multiple stretches, returns the results Parameters: - muscle_stimulation: applied stimulation. - ce_stretch_max: the maximal stretch to apply to the contractile element. - ce_stretch_min: the minimal stretch to apply to the contractile element. - nb_pts: the number of times the experiment should be ran between the min and max stretch. (i.e number of points in the results) - time_param: A TimeParameters object to pass the intended time parameters for every experiment. - l_opt: The optimal length of the contractile element. If None the default one is taken Returns every parameters for the experiments. """ # System definition parameters = MuscleParameters() if l_opt is not None: parameters.l_opt = l_opt muscle = Muscle(parameters) sys = IsometricMuscleSystem() sys.add_muscle(muscle) # Experiment parameters muscle_stretch_max = find_ce_stretch_iso(sys, ce_stretch_max, time_param) muscle_stretch_min = find_ce_stretch_iso(sys, ce_stretch_min, time_param) stretches = np.arange(muscle_stretch_min, muscle_stretch_max, muscle_stretch_max / nb_pts) x0 = [0] * StatesIsometric.NB_STATES.value x0[StatesIsometric.STIMULATION.value] = 0 x0[StatesIsometric.L_CE.value] = sys.muscle.L_OPT # Containers active_force = [] passive_force = [] total_force = [] l_ce = [] l_slack = [] l_mtc = [] # Experiences pylog.info( "Running isometric experiments for stretches (this might take a while)..." ) for stretch in stretches: result = sys.integrate(x0=x0, time=time_param.times, time_step=time_param.t_step, stimulation=muscle_stimulation, muscle_length=stretch) active_force.append(result.active_force[-1]) passive_force.append(result.passive_force[-1]) total_force.append(result.tendon_force[-1]) l_ce.append(result.l_ce[-1]) l_mtc.append(result.l_mtc[-1]) l_slack.append(result.l_mtc[-1] - result.l_ce[-1]) return active_force, passive_force, total_force, l_ce, l_slack, l_mtc
from cmcpack import DEFAULT, parse_args from cmcpack.plot import save_figure from system_parameters import MuscleParameters, MassParameters from isometric_muscle_system import IsometricMuscleSystem from isotonic_muscle_system import IsotonicMuscleSystem parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) stretch_min = muscle.L_OPT stretch_max = muscle.L_OPT * 3 N_stretch = 40 muscle_stretch = np.arange(stretch_min, stretch_max, (stretch_max - stretch_min) / N_stretch) # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.l_opt # To get the muscle optimal length # Evalute for a single muscle stretch muscle_stretch = 0.35 # Evalute for a single muscle stimulation muscle_stimulation = 1. sys.muscle.l_opt=0.15 # Set the initial condition x0 = [0.0, sys.muscle.l_opt] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value print(x0) # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) # Plotting plt.figure('Isometric muscle experiment') plt.plot(result.l_ce/sys.muscle.l_opt, result.active_force, label = "Active Force") plt.plot(result.l_ce/sys.muscle.l_opt, result.passive_force, label = "Passive Force") plt.plot(result.l_ce/sys.muscle.l_opt, result.passive_force + result.active_force, label = "Total Force") plt.legend(loc="upper left") plt.title('Isometric muscle experiment') plt.xlabel('length') plt.ylabel('Force [N]') plt.grid() plt.show plt.figure('Isometric Muscle experiment 2') stim = np.linspace(0,1,11) print(stim) for i in range(10): muscle_stimulation = stim[i] j = 0.1*i j = round(j,1) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) plt.plot(result.l_ce,result.active_force, label ="MS %s" %j) a plt.xlabel('length') plt.ylabel('Force [N]') plt.show
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length # Evalute for a single muscle stretch muscle_stretch = 0.2 # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) ####custom code##### fiber_length = np.arange(0.01, 0.11, 0.01) my_velocity = [] plt.figure('Isotonic muscle experiment') for lopt in fiber_length: # Run the integration sys.muscle.L_OPT = lopt result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) plt.figure('Isometric muscle experiment') plt.plot(result.time, result.tendon_force, label='fiber length: %.2f' % lopt) plt.title('Isometric muscle experiment') plt.xlabel('Time [s]') plt.ylabel('Muscle Force') plt.legend() # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) # Plotting plt.figure('Isometric muscle experiment') plt.plot(result.time, result.tendon_force) plt.title('Isometric muscle experiment') plt.xlabel('Time [s]') plt.ylabel('Muscle Force') plt.grid()
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length # Evalute for a single muscle stretch muscle_stretch = 0.2 # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) # Plotting plt.figure('Isometric muscle experiment') plt.plot(result.time, result.tendon_force,label='tendon force') plt.plot(result.time, result.passive_force,label='passive force') plt.plot(result.time, result.active_force,label='active force') plt.plot(result.time, result.l_ce,label='l_ce') plt.legend() plt.title('Isometric muscle experiment') plt.xlabel('Time [s]') plt.ylabel('Muscle Force') plt.grid() # Run 1.a and 1.b - relation between l_ce and active/oassive forces ms=np.arange(start=0.0,stop=0.32,step=0.005) plotRelationLceAPForces(muscle_stretch=ms,muscle_stimulation=0.1) plotRelationLceAPForces(muscle_stretch=ms,muscle_stimulation=0.5) plotRelationLceAPForces(muscle_stretch=ms,muscle_stimulation=1.) # Run 1.c plotRelationLceAPForces(ms,l_opt=0.09) plotRelationLceAPForces(ms,l_opt=0.13)
def exercise1a(): """ Exercise 1a The goal of this exercise is to understand the relationship between muscle length and tension. Here you will re-create the isometric muscle contraction experiment. To do so, you will have to keep the muscle at a constant length and observe the force while stimulating the muscle at a constant activation.""" # Defination of muscles parameters = MuscleParameters() pylog.warning("Loading default muscle parameters") pylog.info(parameters.showParameters()) pylog.info("Use the parameters object to change the muscle parameters") # Create muscle object muscle = Muscle(parameters) pylog.warning("Isometric muscle contraction to be completed") # Instatiate isometric muscle system sys = IsometricMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length # Evalute for a single muscle stretch muscle_stretch = 0.25 # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT] # x0[0] --> muscle stimulation intial value # x0[1] --> muscle contracticle length initial value # Set the time for integration t_start = 0.0 t_stop = 0.2 time_step = 0.001 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) # Plotting plt.figure('Isometric muscle experiment') plt.plot(result.time, result.tendon_force) plt.title('Isometric muscle experiment') plt.xlabel('Time [s]') plt.ylabel('Tendon Force') plt.grid() ########################################################################" muscle_stretch_listA = range(5, 20) muscle_stretch_list = np.array(muscle_stretch_listA) muscle_stretch_list = muscle_stretch_list / 50 active_forces = [] passive_forces = [] tendon_forces = [] # Run the integration for muscle_stretch in muscle_stretch_list: result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=muscle_stimulation, muscle_length=muscle_stretch) active_forces.append(result.active_force[-1]) passive_forces.append(result.passive_force[-1]) tendon_forces.append(result.tendon_force[-1]) # Plotting plt.figure('Isometric muscle experiment, varying length') plt.plot(muscle_stretch_list, active_forces) plt.plot(muscle_stretch_list, passive_forces) plt.plot(muscle_stretch_list, tendon_forces) plt.title('Isometric muscle experiment, varying length') plt.xlabel('Muscle stretch') plt.ylabel('Active, passive and total tendon forces') plt.legend(['active forces', 'passive forces', 'total forces']) plt.grid() stimulation_listA = range(0, 11) stimulation_list = np.array(stimulation_listA) stimulation_list = stimulation_list / 10 plt.figure('Isometric muscle experiment, varying stimulation and length') plt.title('Isometric muscle experiment, varying stimulation and length') plt.xlabel('Muscle stretch') plt.ylabel('Total force') legend = [] for stimul in stimulation_list: tendon_forces = [] for muscle_stretch in muscle_stretch_list: result = sys.integrate(x0=x0, time=time, time_step=time_step, stimulation=stimul, muscle_length=muscle_stretch) tendon_forces.append(result.tendon_force[-1]) plt.plot(muscle_stretch_list, tendon_forces) legend.append('Stimulation of ' + str(stimul)) plt.legend(legend)