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 exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) pylog.warning("Isotonic muscle contraction to be implemented") # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # Evalute for a single muscle stimulation muscle_stimulation = 1. #sys.muscle.L_OPT=0.05 # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 0.25 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal # Create a V_ce vector V_ce_1d = np.zeros(100) PF_ce_1d = np.zeros(100) AF_ce_1d = np.zeros(100) # Create load vector Load = np.linspace(1, 600, num=100) """1.d) velocity-tension analysis """ for i in range(0, len(Load)): # Set the initial condition x0 = [ muscle_stimulation, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0 ] # Evalute for a single load load = Load[i] # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=muscle_stimulation, load=load) #print(sys.muscle.L_OPT+sys.muscle.L_SLACK) #print(result.l_mtc[-1]-(sys.muscle.L_OPT+sys.muscle.L_SLACK)) if (result.l_mtc[-1] < sys.muscle.L_OPT + sys.muscle.L_SLACK): V_ce_1d[i] = min(result.v_ce) else: V_ce_1d[i] = max(result.v_ce) PF_ce_1d[i] = result.passive_force[-1] AF_ce_1d[i] = result.active_force[-1] # Plotting plt.figure('Isotonic muscle experiment') plt.plot(result.time, result.v_ce) plt.title('Isotonic muscle experiment') plt.xlabel('Time [s]') plt.ylabel('Contractile element velocity') plt.grid() # Plot velocity versus tension plt.figure() plt.plot(V_ce_1d, Load) plt.title('Isotonic muscle experiment') plt.xlabel('Contractile element velocity') plt.ylabel('Load') plt.grid() plt.axvline(0, color='r', linestyle='--') # Plot velocity versus tension plt.figure() plt.plot(V_ce_1d, PF_ce_1d + AF_ce_1d) #plt.plot(V_ce_1d, PF_ce_1d) #plt.plot(V_ce_1d, AF_ce_1d, '--') plt.title('Isotonic muscle experiment') plt.xlabel('Contractile element velocity') plt.ylabel('Total Force') plt.grid() #plt.legend(['total','passive', 'active']) plt.axvline(0, color='r', linestyle='--') """ 1.f) velocity-tension as a function of muscle activation """ # Create solution vector #R_glob=np.zeros((5,50)) # Create muscle activation vector dS = np.linspace(0.1, 1, num=5) # Create a V_ce vector V_ce = np.zeros((5, 100)) PF_ce = np.zeros((5, 100)) AF_ce = np.zeros((5, 100)) for i in range(0, len(Load)): for j in range(0, len(dS)): # Evalute for a single load load = Load[i] # Evalute for a single muscle stimulation muscle_stimulation = dS[j] # Set the initial condition x0 = [ muscle_stimulation, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0 ] # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=muscle_stimulation, load=load) #R_glob[j,i]=result.tendon_force[len(result.tendon_force)-1] #print(sys.muscle.L_OPT+sys.muscle.L_SLACK) #print(result.l_mtc[-1]-(sys.muscle.L_OPT+sys.muscle.L_SLACK)) if (result.l_mtc[-1] < sys.muscle.L_OPT + sys.muscle.L_SLACK): V_ce[j, i] = min(result.v_ce) else: V_ce[j, i] = max(result.v_ce) PF_ce[j, i] = result.passive_force[-1] AF_ce[j, i] = result.active_force[-1] # # Plotting # plt.figure('Isotonic muscle experiment') # plt.plot(result.time, result.v_ce) # plt.title('Isotonic muscle experiment') # plt.xlabel('Time [s]') # plt.ylabel('Contractile element velocity') # plt.grid() # Plot velocity versus tension plt.figure() for i in range(0, 5): plt.plot(V_ce[i, :], PF_ce[i, :] + AF_ce[i, :]) plt.title('Isotonic muscle experiment') plt.xlabel('Contractile element velocity') plt.ylabel('Force') plt.grid() plt.legend([ 'Stimulation = 0.1', 'Stimulation = 0.28', 'Stimulation = 0.46', 'Stimulation = 0.64', 'Stimulation = 0.82', 'Stimulation = 1' ])
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 exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) pylog.warning("Isotonic muscle contraction to be implemented") # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length # Evaluate for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 1.25 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) # Set max_vce max_vce = [] # --------------------------------------------- # Small load experiment # --------------------------------------------- load_table_small = [5, 10, 20, 50, 100] # Begin plotting plt.figure('Isotonic muscle experiment - load [10, 200] [N]') max_vce_small = ex1d_for(sys, x0, time, time_step, time_stabilize, muscle_stimulation, load_table_small, False) plt.title('Isotonic muscle experiment - load [5, 140] [N]') plt.xlabel('Time [s]') plt.ylabel('Muscle contractile velocity [m/s]') plt.legend(loc='upper right') plt.grid() # --------------------------------------------- # Big load experiment # --------------------------------------------- load_table_big = [150, 200, 220, 250, 500, 1000, 1500] # Begin plotting plt.figure('Isotonic muscle experiment - load [150, 1500] [N]') max_vce += ex1d_for(sys, x0, time, time_step, time_stabilize, muscle_stimulation, load_table_big, True) plt.title('Isotonic muscle experiment - load [150, 1500] [N]') plt.xlabel('Time [s]') plt.ylabel('Muscle contractile velocity [m/s]') plt.legend(loc='upper right') plt.grid() # --------------------------------------------- # Plot velocity - tension relation # --------------------------------------------- load = np.arange(5, 2500, 200) (max_vce, active_force) = ex1d_for(sys, x0, time, time_step, time_stabilize, muscle_stimulation, load, False) fig = plt.figure('Velocity - Tension') ax = fig.add_subplot(111) # Plot comments and line at 0 value min_val = 0.0 if min(map(abs, max_vce)) not in max_vce: min_val = -min(map(abs, max_vce)) else: min_val = min(map(abs, max_vce)) xy = (load[max_vce.index(min_val)], min_val) xytext = (load[max_vce.index(min_val)] + 50, min_val) ax.annotate('load = {:0.1f}'.format(152.2), xy=xy, xytext=xytext) plt.title('Velocity [m/s] - Tension [N]') plt.xlabel('Tension [N]') plt.ylabel('Velocity [m/s]') plt.grid() plt.plot(load, max_vce) plt.plot(load[max_vce.index(min_val)], min_val, 'o')
def exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) pylog.warning("Isotonic muscle contraction to be implemented") # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # 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 load load = 100. # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 0.3 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=muscle_stimulation, load=load) # 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() # Run 1.d load = np.arange(0,1000,20) plotVceLoad(load,[0.1,0.5,1])
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 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 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 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()
import matplotlib.pyplot as plt import numpy as np import cmc_pylog as pylog from muscle import Muscle from mass import Mass 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,
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 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 exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) pylog.warning("Isotonic muscle contraction to be implemented") # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # 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 load load = 250/9.81 # Evalute for a single muscle stimulation muscle_stimulation = 1.0 # Set the initial condition x0 = [0.0, sys.muscle.l_opt, sys.muscle.l_opt + sys.muscle.l_slack, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 0.4 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) load = np.linspace(100/9.81,1700/9.81,50) Stimu = np.linspace(0,1,6) Vce = np.zeros((len(load),len(Stimu))) plt.figure('Isotonix Globale') for j in range(len(Stimu)): # Vce = np.empty(len(load)) # Vcemax = np.empty(len(load)) # Vcemin = np.empty(len(load)) for i in range(len(load)): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=Stimu[j], load=load[i] ) print(result.l_mtu[-1]) print(sys.muscle.l_opt + sys.muscle.l_slack) if (result.l_mtu[-1] > sys.muscle.l_opt + sys.muscle.l_slack): Vce[i,j]=(max(result.v_ce)) else: Vce[i,j] = min(result.v_ce) Vce[:,j] plt.plot(Vce[:,j],load, label ="MS %s" %round(Stimu[j],1)) plt.legend(loc = "upper left") plt.xlabel('Vitesse max [m/s]') plt.ylabel('Load [kg]') # Plotting plt.figure('Isotonic muscle experiment') #plt.plot(result.time, # result.v_ce) plt.plot(Vce,load) plt.title('Isotonic muscle experiment') plt.xlabel('Vitesse max [m/s]') plt.ylabel('Load [kg]') #plt.xlabel('Time [s]') #plt.ylabel('Muscle contracticle velocity [lopts/s]') plt.grid() #MUSCLE-Force Velocity relationship : plt.figure('Muscle Force-Velocity') plt.plot(result.v_ce,result.active_force, label ="Active Force") plt.plot(result.v_ce,result.active_force+result.passive_force, label = "Passive + Active") plt.plot(result.v_ce,result.passive_force, label = "Passive Force") plt.legend(loc = "upper left") plt.xlabel('Vitesse m') plt.ylabel('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()) # 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 exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) pylog.warning("Isotonic muscle contraction to be implemented") # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # 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 load load = 250 / 9.81 # Evalute for a single muscle stimulation muscle_stimulation = 1.0 # Set the initial condition x0 = [0.0, sys.muscle.l_opt, sys.muscle.l_opt + sys.muscle.l_slack, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 0.4 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=muscle_stimulation, load=load) # 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 contracticle velocity [lopts/s]') plt.grid() ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ### code for 1d pylog.info( "1d. relationship between muscle contractile velocity and external load" ) load_start = 1 load_stop = 501 load_step = 10 load_range = np.arange(load_start, load_stop, load_step) muscle_stimulation = 1.0 vels = [] tendon_forces = [] active_forces = [] passive_forces = [] total_forces = [] for temp_load in load_range: temp_result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=muscle_stimulation, load=temp_load) temp_tendon_force = temp_result.tendon_force[-1] temp_active_force = temp_result.active_force[-1] temp_passive_force = temp_result.passive_force[-1] temp_total_force = temp_active_force + temp_passive_force tendon_forces = tendon_forces + [temp_tendon_force] active_forces = active_forces + [temp_active_force] passive_forces = passive_forces + [temp_passive_force] total_forces = total_forces + [temp_total_force] temp_l_mtu = temp_result.l_mtu[-1] if temp_l_mtu < sys.muscle.l_opt + sys.muscle.l_slack: vels = vels + [np.min(temp_result.v_ce)] else: vels = vels + [np.max(temp_result.v_ce)] plt.figure( '1d. Isotonic muscle experiment for tension and contractile velocities' ) plt.plot(vels, tendon_forces) plt.plot(vels, load_range) plt.plot(vels, active_forces) plt.plot(vels, passive_forces) plt.plot(vels, total_forces) plt.title( 'Isotonic muscle experiment for tension and contractile velocities') plt.xlabel('Muscle contracticle velocity [lopts/s]') plt.ylabel('Tension [N]') plt.legend(("Tendon Force", "Load", "Active Force", "Passive Force", "Total force")) plt.grid() plt.show() ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ###################################################################### ### code for 1f pylog.info( "1f. relationship between muscle contractile velocity and external load with different stimulations" ) muscle_stimulations = np.arange(0, muscle_stimulation + 0.1, 0.1) load_start = 1 load_stop = 501 load_step = 10 load_range = np.arange(load_start, load_stop, load_step) all_vels = [] all_tendon_forces = [] for temp_muscle_stimulation in muscle_stimulations: temp_vels = [] temp_tendon_forces = [] for temp_load in load_range: temp_result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=temp_muscle_stimulation, load=temp_load) temp_tendon_force = temp_result.tendon_force[-1] temp_tendon_forces = temp_tendon_forces + [temp_tendon_force] temp_l_mtu = temp_result.l_mtu[-1] if temp_l_mtu < sys.muscle.l_opt + sys.muscle.l_slack: temp_vels = temp_vels + [np.min(temp_result.v_ce)] else: temp_vels = temp_vels + [np.max(temp_result.v_ce)] all_vels = all_vels + [temp_vels] all_tendon_forces = all_tendon_forces + [temp_tendon_forces] plt.figure( '1f. Isotonic muscle experiment for loads and contractile velocities with different stimulations' ) for i in range(len(muscle_stimulations)): plt.plot(all_vels[i], load_range) plt.title( 'Isotonic muscle experiment for loads and contractile velocities with different stimulations' ) plt.xlabel('Muscle contracticle velocity [lopts/s]') 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( '1f. Isotonic muscle experiment for tendon forces and contractile velocities with different stimulations' ) for i in range(len(muscle_stimulations)): plt.plot(all_vels[i], all_tendon_forces[i]) plt.title( 'Isotonic muscle experiment for tendon forces and contractile velocities with different stimulations' ) plt.xlabel('Muscle contracticle velocity [lopts/s]') 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()
def exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length # Velocity-tension curve # Evalute for various loads load_min = 1 load_max = 301 N_load = 50 load_list = np.arange(load_min, load_max, (load_max - load_min) / N_load) # Evalute for Stimulation = 1.0 stimulation = 1.0 # Set the initial condition x0 = [0.0, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 0.3 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) max_velocity = np.zeros(N_load) tendonF = np.zeros(N_load) for ind_load, load in enumerate(load_list): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=stimulation, load=load) if (result.l_mtc[-1] < (sys.muscle.L_OPT + sys.muscle.L_SLACK)): max_velocity[ind_load] = np.max(-result.v_ce) else: max_velocity[ind_load] = np.min(-result.v_ce) tendonF[ind_load] = result.tendon_force[-1] # Plotting plt.figure('Isotonic Muscle Experiment 1d') v_min = np.amin(max_velocity) v_max = np.amax(max_velocity) plt.plot(max_velocity * 100 / -muscle.V_MAX, tendonF * 100 / muscle.F_MAX) plt.axvline(linestyle='--', color='r', linewidth=2) plt.text(v_min * 100 / -muscle.V_MAX, 20, r'lengthening', fontsize=14) plt.text(v_max * 100 / -muscle.V_MAX * 1 / 3, 20, r'shortening', fontsize=14) plt.xlabel('Maximal velocity [% of $V_{max}$]') plt.ylabel('Tendon Force [% of $F_{max}$]') plt.title( 'Velocity-tension curve for isotonic muscle experiment (Stimulation = 1.0)' ) plt.grid()
def exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) pylog.warning("Isotonic muscle contraction to be implemented") # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # 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 load load = 100. # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 0.5 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) loads = np.arange(20, 351, 10) velocities = [] for index, load in enumerate(loads): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=muscle_stimulation, load=load) if (result.l_mtc[-1] < sys.muscle.L_OPT + sys.muscle.L_SLACK): velocities.append(np.max(result.v_ce)) print('max') else: velocities.append(np.min(result.v_ce)) print('min') #Muscle contracile Velocity - Tension (load) relationship plt.figure('Isotonic muscle experiment') plt.title('Isotonic muscle experiment') plt.xlabel('Muscle Contractile Velocity [m/s]') plt.ylabel('Tension (load) [N]') plt.plot(velocities, loads) plt.grid() #For different stimulations 1.f muscle_stimulation = np.arange(0, 1.1, 0.2) plt.figure('Isotonic muscle exp with different stimulations') plt.title('Isotonic muscle experiment with different stimulations') for stim in muscle_stimulation: velocities = [] for index, load in enumerate(loads): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=stim, load=load) if (result.l_mtc[-1] < sys.muscle.L_OPT + sys.muscle.L_SLACK): velocities.append(np.max(result.v_ce)) else: velocities.append(np.min(result.v_ce)) plt.xlabel('Muscle Contractile Velocity [m/s]') plt.ylabel('Tension (load) [N]') plt.plot(velocities, loads) plt.legend(('0', '0.2', '0.4', '0.6', '0.8', '1.0')) plt.grid()
def exercise1f(): """ Exercise 1f """ # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # Velocity-tension curve # Evalute for various loads load_min = 1 load_max = 501 N_load = 50 load_list = np.arange(load_min, load_max, (load_max - load_min) / N_load) # Evalute for various muscle stimulation N_stim = 4 muscle_stimulation = np.round(np.arange(N_stim) / (N_stim - 1), 2) # Set the initial condition x0 = [0.0, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0] # Set the time for integration t_start = 0.0 t_stop = 0.3 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) max_velocity = np.zeros((N_stim, N_load)) tendonF = np.zeros((N_stim, N_load)) for i, stim in enumerate(muscle_stimulation): for ind_load, load in enumerate(load_list): # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=stim, load=load) if (result.l_mtc[-1] < (sys.muscle.L_OPT + sys.muscle.L_SLACK)): max_velocity[i, ind_load] = np.max(-result.v_ce) else: max_velocity[i, ind_load] = np.min(-result.v_ce) tendonF[i, ind_load] = result.tendon_force[-1] # Plotting plt.figure('Isotonic Muscle Experiment 1f') v_min = np.amin(max_velocity) v_max = np.amax(max_velocity) for i, stim in enumerate(muscle_stimulation): plt.plot(max_velocity[i, :] * 100 / -muscle.V_MAX, tendonF[i, :] * 100 / muscle.F_MAX, label='Tendon Force - Stimulation = {}'.format(stim)) plt.xlim(v_min * 100 / -muscle.V_MAX, v_max * 100 / -muscle.V_MAX) plt.ylim(0, 200) plt.axvline(linestyle='--', color='r', linewidth=2) plt.text(v_min * 100 / -muscle.V_MAX * 2 / 3, 170, r'lengthening', fontsize=16) plt.text(v_max * 100 / -muscle.V_MAX * 1 / 8, 170, r'shortening', fontsize=16) plt.xlabel('Maximal velocity [% of $V_{max}$]') plt.ylabel('Tendon Force [% of $F_{max}$]') plt.title( 'Velocity-tension curves for isotonic muscle experiment with various muscle stimulations' ) plt.legend() 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 exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) pylog.warning("Isotonic muscle contraction to be implemented") # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # 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 load #load = 15. # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 0.35 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) ####custom code##### load_range = np.arange(1, 361, 5) my_velocity = [] plt.figure('Isotonic muscle experiment') for load in load_range: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=muscle_stimulation, load=load) my_velocity.append(max(abs(result.v_ce))) i, = np.where(result.v_ce == my_velocity[-1]) if i.shape == (0, ): #checks for negative velocity my_velocity[-1] *= -1 plt.plot(result.time, result.v_ce, label='Load: %s' % load) # Plotting #plt.plot(result.time, result.v_ce) plt.title('Isotonic muscle experiment') plt.xlabel('Time [s]') plt.ylabel('Muscle contractilve velocity') plt.grid() plt.figure('Isotonic Experiment') plt.plot(load_range, my_velocity) plt.xlabel('Load[Kg]') plt.ylabel('Maximal Muscle Contractile Velocity[m/s]') 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 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 exercise1f(): """ Exercise 1f What happens to the force-velocity relationship when the stimulation is varied between [0 - 1]?""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) # Instantiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # You can still access the muscle inside the system by doing # >>> sys.muscle.L_OPT # To get the muscle optimal length # Evaluate for a single load load = 100. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 1.25 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) # --------------------------------------------- # maximum force over stimulation # --------------------------------------------- # Evaluate for different muscle stimulation muscle_stimulation = np.arange(0, 1.1, 0.1) max_active_force = [] max_passive_force = [] max_sum_force = [] # Begin plotting for s in muscle_stimulation: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=s, load=load) if abs(min(result.active_force)) > max(result.active_force): max_active_force.append(min(result.active_force)) else: max_active_force.append(max(result.active_force)) if abs(min(result.passive_force)) > max(result.passive_force): max_passive_force.append(min(result.passive_force)) else: max_passive_force.append(max(result.passive_force)) max_sum_force.append(max_active_force[-1] + max_passive_force[-1]) plt.figure('Isotonic muscle active force - stimulation [0, 1]') plt.plot(muscle_stimulation, max_active_force, label='maximum active force') plt.plot(muscle_stimulation, max_passive_force, label='maximum passive force') plt.plot(muscle_stimulation, max_sum_force, label='maximum sum force') plt.xlabel('Stimulation [-]') plt.ylabel('Muscle sum forces [N]') plt.legend(loc='upper right') plt.grid() # --------------------------------------------- # force - velocity over stimulation # --------------------------------------------- muscle_stimulation = np.arange(0, 1.1, 0.1) # Begin plotting for s in muscle_stimulation: # Run the integration result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=s, load=load) plt.figure('Isotonic muscle active force - velocity') plt.plot(result.v_ce[200:-1], result.active_force[200:-1], label='stimulation {:0.1f}'.format(s)) plt.figure('Isotonic muscle passive force - velocity') plt.plot(result.v_ce[200:-1], result.passive_force[200:-1], label='stimulation {:0.1f}'.format(s)) plt.figure('Isotonic muscle sum forces - velocity') plt.plot(result.v_ce[200:-1], result.active_force[200:-1] + result.passive_force[200:-1], label='stimulation {:0.1f}'.format(s)) plt.figure('Isotonic muscle active force - velocity') plt.xlabel('Velocity contractile element [m/s]') plt.ylabel('Active force [N]') plt.legend(loc='upper right') plt.grid() plt.figure('Isotonic muscle passive force - velocity') plt.xlabel('Velocity contractile element [m/s]') plt.ylabel('Passive force [N]') plt.legend(loc='upper right') plt.grid() plt.figure('Isotonic muscle sum forces - velocity') plt.xlabel('Velocity contractile element [m/s]') plt.ylabel('Sum forces [N]') plt.legend(loc='upper right') plt.grid() # --------------------------------------------- # Plot velocity - tension relation # --------------------------------------------- muscle_stimulation = np.arange(0, 1.1, 0.25) load = np.arange(5, 1500, 20) plt.figure('Velocity - Tension') # Begin plotting for s in muscle_stimulation: (max_vce, active_force) = ex1d_for(sys, x0, time, time_step, time_stabilize, s, load, False) plt.plot(load, max_vce, label="stimulation {:0.1f}".format(s)) plt.title('Velocity [m/s] - Load [N]') plt.xlabel('Load [N]') plt.ylabel('Velocity [m/s]') plt.legend(loc='lower right') plt.grid()
def exercise1d(): """ Exercise 1d Under isotonic conditions external load is kept constant. A constant stimulation is applied and then suddenly the muscle is allowed contract. The instantaneous velocity at which the muscle contracts is of our interest.""" # Defination of muscles muscle_parameters = MuscleParameters() print(muscle_parameters.showParameters()) mass_parameters = MassParameters() print(mass_parameters.showParameters()) # Create muscle object muscle = Muscle(muscle_parameters) # Create mass object mass = Mass(mass_parameters) # Instatiate isotonic muscle system sys = IsotonicMuscleSystem() # Add the muscle to the system sys.add_muscle(muscle) # Add the mass to the system sys.add_mass(mass) # 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 load load = 100. # Evalute for a single muscle stimulation muscle_stimulation = 1. # Set the initial condition x0 = [0.0, sys.muscle.L_OPT, sys.muscle.L_OPT + sys.muscle.L_SLACK, 0.0] # x0[0] - -> activation # x0[1] - -> contractile length(l_ce) # x0[2] - -> position of the mass/load # x0[3] - -> velocity of the mass/load # Set the time for integration t_start = 0.0 t_stop = 0.3 time_step = 0.001 time_stabilize = 0.2 time = np.arange(t_start, t_stop, time_step) # Run the integration load_array=np.arange(0.1,3000/sys.mass.parameters.g,5) vel_ce=[] act_force_int=[] stimulation=[0.,0.2,0.4,0.6,0.8,1.] colors=['r','g','b','c','m','y'] for loadx in load_array: result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=muscle_stimulation, load=loadx) if (loadx==150.1 or loadx==155.1): plt.figure("Single Exp") plt.title("Result for a single experiment") plt.plot(result.time,result.v_ce*(-1)) plt.xlabel("Time [s]") plt.ylabel("Velocity [m/s]") plt.legend(('Shortening','Lengthening')) pylog.info(result.l_mtc[-1]) plt.grid() plt.show() if result.l_mtc[-1] < ( muscle_parameters.l_opt + muscle_parameters.l_slack): #pylog.info("min condition") vel_ce.append(min(result.v_ce[:])*(-1)) act_force_int.append(max(result.active_force)) else: vel_ce.append(max(result.v_ce[:])*(-1)) act_force_int.append(max(result.active_force)) # pylog.info("max condition") plt.figure('Isotonic muscle experiment') plt.plot(vel_ce,load_array*mass_parameters.g) plt.plot(vel_ce,act_force_int) plt.title('Isotonic Muscle Experiment') plt.xlabel('Contractile Element Velocity [m/s]') plt.ylabel('Force[N]') plt.legend(("External Load","Internal Active Force")) plt.grid() plt.show() plt.figure('Varying Stimulation') leg=[] for i,stim in enumerate(stimulation): pylog.info("Stim is {}".format(stim)) vel_ce=[] act_force_int=[] for loadx in load_array: result = sys.integrate(x0=x0, time=time, time_step=time_step, time_stabilize=time_stabilize, stimulation=stim, load=loadx) if result.l_mtc[-1] < ( muscle_parameters.l_opt + muscle_parameters.l_slack): #pylog.info("min condition") vel_ce.append(min(result.v_ce[:])*(-1)) act_force_int.append(max(result.active_force)) else: vel_ce.append(max(result.v_ce[:])*(-1)) act_force_int.append(max(result.active_force)) plt.plot(vel_ce,load_array*mass_parameters.g,colors[i],label='Stimulation={}'.format(stim)) plt.plot(vel_ce,act_force_int,colors[i],linestyle=":",label='Stimulation={}'.format(stim)) leg.append(("Load-velocity plot with simulation={}".format(stim))) leg.append(("Force-velocity with simulation={}".format(stim))) plt.title('Varying Stimulation') plt.legend(leg) plt.xlabel('Contractile Element Velocity [m/s]') plt.ylabel('Force[N]') #("Stimulation = 0","Stimulation = 0.2","Stimulation = 0.4","Stimulation = 0.6","Stimulation = 0.8","Stimulation = 1") 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)