MimicMeasure command

SCONE is a software tool for predictive simulations of biomechanical movement. It uses OpenSim for modeling and simulation, and performs optimization using various control strategies, including feed-forward control, proprioceptic feedback control, and bal
User avatar
Andrea Morelli
Posts: 89
Joined: Thu Jan 24, 2008 1:10 pm

MimicMeasure command

Post by Andrea Morelli » Thu Aug 06, 2020 1:08 am

Good Morning.
I'm trying to work with the MimicMeasure command to import a jump from an opensim scaled subject (I have both kinetics and GRF data) and then let SCONE calculate muscle contribution / energy cost / work done.

How should the code be written ? There's any tutorial or example ?

1) Should I use the cmaoptimizer function ?
2) Simulation objective max duration time should be set or it is derived from opensim .sto file ?
3) It Is correct to introduce a compositmeasure function to minimise muscle states in mimicmeasure function and penalise muscle effort to compute the activation ?

below my code:

Thank you
Andrea

Code: Select all

CmaOptimizer {
signature_prefix = DATE_TIME
# use previous result
# init_file = data/CMJ/ResultStandingHigh_CMJ_Jump.par 
SimulationObjective {
# max_duration = 10
# Model used in simulation
OpenSimModel {
model_file = data/CMJ/Human0916_CMJ.osim
}
# Composite measure for straight pose jumping
CompositeMeasure {
dual_sided = 1
minimize = 1 # Minimize this measure
# MimicMeasure for Jump
MimicMeasure {
file = data/CMJ/inverse_dynamics.sto
#
include_states = *.
}
# Penalize high effort
EffortMeasure {
measure_type = TotalForce
}
}
}
}
Last edited by Andrea Morelli on Thu Aug 27, 2020 1:47 am, edited 1 time in total.

User avatar
Thomas Geijtenbeek
Posts: 425
Joined: Wed Mar 12, 2014 8:08 am

Re: MimicMeasure command

Post by Thomas Geijtenbeek » Thu Aug 06, 2020 2:26 am

Unfortunately there's no tutorial yet, but you're on the right track. See also the documentation for an explanation of the individual parameters. Here's an example:

Code: Select all

CompositeMeasure {
	MimicMeasure {
		name = Mimic
		weight = 100
		file = ...
		include_states = "*" # select the states you want to mimic
		threshold = 0.01
		average_error_limit = 0.01
	}
	
	# cost-of-transport
	EffortMeasure {
		name = Effort
		weight = 0.1
		measure_type = Wang2012
	}
}
1) Yes, the optimization / model part are the same as any other scenario.
2) You should set the max_duration too, because the MimicMeasure can stop measuring before the actual simulation has finished. The average_error_limit parameter can also be used to terminate the simulation early.
3) Yes, you should use a CompositeMeasure for that -- just make sure the weights are set correctly. In the example above, the MimicMeasure is dominant initially because it has a larger weight, but once it gets below a certain threshold (0.01), the MimicMeasure becomes zero and the optimization will be only on Effort. You can always check the contribution of the individual Measures in the Evaluation Report window (new in 1.5.0).

User avatar
Andrea Morelli
Posts: 89
Joined: Thu Jan 24, 2008 1:10 pm

Re: MimicMeasure command

Post by Andrea Morelli » Fri Aug 07, 2020 1:57 am

Hi Thomas.
Thank you for the answer.
Great,
I've inserted file name ... of the gait example subject01_walk1_RRA_Actuation_force

but I receive an error message:
"objectives has no free parameters"

Sorry for the dummy question, is possible for me is not so clear the use of a .sto file what is the .sto files I have to include in the optimisation ?
Results of the RRA analysis from opensim ? The ID results.sto (that include only force data) ?

Another question, I should use in the analysis the scaled model of the subject into scone with adjusted pelvis COM (at least for walk), should'nt I ? What's the "correct procedure" ?

I have also force platform data, I can include also that to "improve" the analysis ?

Thank you
Andrea

Code: Select all

CmaOptimizer {
	signature_prefix = DATE_TIME
	# use previous result
	# init_file = data/CMJ/ResultStandingHigh_CMJ_Jump.par 
	
	SimulationObjective {
		
		# Model used in simulation
		OpenSimModel {
			model_file = data/CMJ/Human0916_CMJ.osim
		}
		
		# Composite measure for mimic and cost of transport
		CompositeMeasure {
			MimicMeasure {
				name = Mimic
				weight = 100
				file = subject01_walk1_RRA_Actuation_force
				include_states = "*" # select the states you want to mimic
				threshold = 0.01
				average_error_limit = 0.01
			}
	
			# cost-of-transport
			EffortMeasure {
				name = Effort
				weight = 0.1
				measure_type = Wang2012
			}
		}
	}
	
}

User avatar
Thomas Geijtenbeek
Posts: 425
Joined: Wed Mar 12, 2014 8:08 am

Re: MimicMeasure command

Post by Thomas Geijtenbeek » Fri Aug 07, 2020 2:38 am

You do still need to define a Controller in SCONE. The idea of the MimicMeasure is that you optimize the control parameters of a given Controller so that you mimic a predefined motion as good as possible. The controller must therefore be suitable for the task.

The .sto should contain all state values you wish to track, which is usually kinematics and/or muscle activation. You can also select which ones to use with the "include" setting of the MimicMeasure.

Ground reaction forces are not part of the model 'state' (they are derived), so they are not tracked.

Gait is much harder to track than jumping, because the steps need to be synchronized.

User avatar
Andrea Morelli
Posts: 89
Joined: Thu Jan 24, 2008 1:10 pm

Re: MimicMeasure command

Post by Andrea Morelli » Fri Aug 07, 2020 2:44 am

Hi Thomas.
ok, thank you.
I'll try to define a controller.
Thank you.
Andrea

User avatar
Andrea Morelli
Posts: 89
Joined: Thu Jan 24, 2008 1:10 pm

Re: MimicMeasure command

Post by Andrea Morelli » Sat Aug 08, 2020 5:16 am

Hi Thomas.
I'm using tutorial 6a script controller code for reference.
mimic file is xxxx_q.sto that should contain model/bones displamcement/velocities
The script in this case should referent to the

Code: Select all

CmaOptimizer {
	signature_prefix = DATE_TIME
	# use previous result
	# init_file = data/CMJ/ResultStandingHigh_CMJ_Jump.par 
	
	SimulationObjective {
		
		# Model used in simulation
		OpenSimModel {
			model_file = data/CMJ/Human0916_CMJ.osim
		}
		
		# Controller based on lua script
		ScriptController {
			script_file = "data/CMJ/ScriptController_CMJ_Jump.lua"
		}
		
		# Composite measure for mimic and cost of transport
		CompositeMeasure {
			# mimic the .sto file
			MimicMeasure {
				name = Mimic
				start_time = 3
				stop_time = 5
				weight = 100
				file = data/CMJ/xxx_DropJump1_RRA_Kinematics_q.sto
				include_states = "*" # select the states you want to mimic
				threshold = 0.01
				average_error_limit = 0.01
			}
			
			# cost-of-transport
			EffortMeasure {
				name = Effort
				weight = 0.1
				measure_type = Wang2012
			}
		}
		
	}
	
}
If I want to optimise actuators I need to referent to them in the script like in the example ?

Code: Select all


-- SCONE script for a simple feed-forward controller.
-- See Tutorial 6a - Script - High Jump

function init( model, par )
	-- keep a list of offsets and slopes to compute the excitation
	offset = {}
	slope = {}

	-- keep a list of all actuators
	actuators = {}

	-- iterate over all actuators in the model
	for i = 1, model:actuator_count() do
		-- store the actuator in the list
		actuators[ i ] = model:actuator( i )

		-- create parameters for both slope and offset
		local name = actuators[ i ]:name()
		offset[ i ] = par:create_from_mean_std( name .. "-offset", 0.3, 0.1, 0, 1 )
		slope[ i ] = par:create_from_mean_std( name .. "-slope", 0, 1, -10, 10 )
	end
end

function update( model )
	-- get the current simulation time
	local t = model:time()

	-- iterate over all actuators
	for i = 1, #actuators do
		local excitation = offset[ i ] + t * slope[ i ]
		actuators[ i ]:add_input( excitation )
	end
end

Thank you
Andrea

User avatar
Thomas Geijtenbeek
Posts: 425
Joined: Wed Mar 12, 2014 8:08 am

Re: MimicMeasure command

Post by Thomas Geijtenbeek » Wed Aug 12, 2020 6:12 am

It's probably easiest to use the jumping example of Tutorial 2. This automatically optimizes all the actuators -- you only need to replace the measure with the new one.

User avatar
Andrea Morelli
Posts: 89
Joined: Thu Jan 24, 2008 1:10 pm

Re: MimicMeasure command

Post by Andrea Morelli » Thu Aug 27, 2020 1:44 am

Good morning Thomas,
back at "work" on the model....

Trying to insert a Controller for the optimization.
I've some additional question:
- is correct to set max_duration (now set to 5) in SimulatoinObjective or it's only mandatory to set start_time and stop_time MimicMeasure ? Without max_duration optimisation starts from very high scores (i.e. 9999999.9999) and seems not converging.
- should increase control_points in PieceWiseConstant function number from 2 ?

Thank you
Andrea

Code: Select all

CmaOptimizer {
	signature_prefix = DATE_TIME
	# use previous result
	init_file = data/CMJ/ResultStandingHigh_CMJ_Jump.par 
	
	SimulationObjective {
		max_duration = 5 #from 2
		
		# Model used in simulation
		OpenSimModel {
			model_file = data/CMJ/Human0916_CMJ.osim
		}
		
		# Controller for the Model
		FeedForwardController {
			symmetric = 0
			
			# Function for feed-forward pattern
			PieceWiseConstant {
				control_points = 2 # from 2
				control_point_y = 0.3~0.01<0,1> # Initial y value of control points
				control_point_dt = 0.2~0.01<0.001,1> # Initial delta time between control points
			}
		}
		
		# Composite measure for mimic and cost of transport
		CompositeMeasure {
			# mimic the .sto file
			MimicMeasure {
				name = Mimic
				start_time = 2
				stop_time = 5
				weight = 100
				file = data/CMJ/Pirovano2392_DropJump1_RRA_Kinematics_q.sto
				include_states = "*" # select the states you want to mimic
				threshold = 0.01
				average_error_limit = 0.01
			}
			
			# cost-of-transport
			EffortMeasure {
				name = Effort
				weight = 0.1
				measure_type = Wang2012
			}
		}
		
	}
	
}
Last edited by Andrea Morelli on Thu Aug 27, 2020 5:15 am, edited 1 time in total.

User avatar
Thomas Geijtenbeek
Posts: 425
Joined: Wed Mar 12, 2014 8:08 am

Re: MimicMeasure command

Post by Thomas Geijtenbeek » Thu Aug 27, 2020 4:04 am

You do need to set the max_duration; otherwise the simulation might go on forever and you will never get a result. The start/stop time in the measure only defines during which part of the simulation the specific measure is actually measuring and does not affect the duration of the simulation.

The number of control points depends on your motion, but it's always best to start with a number as small as possible to get better optimization results.

User avatar
Andrea Morelli
Posts: 89
Joined: Thu Jan 24, 2008 1:10 pm

Re: MimicMeasure command

Post by Andrea Morelli » Thu Aug 27, 2020 5:16 am

ok.
I suppose it but I wan't sure :-)

Is the controller "working" (or should work) like that ?

Thank you
Andrea

POST REPLY