data tracking in ScriptMeasure

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
POST REPLY
User avatar
Ton van den Bogert
Posts: 164
Joined: Thu Apr 27, 2006 11:37 am

data tracking in ScriptMeasure

Post by Ton van den Bogert » Mon Mar 01, 2021 10:04 am

Hi Thomas,

I have been playing with Scone (finally!) and am really impressed with the design and capabilities!

One thing I am exploring is data tracking in a ScriptMeasure. I can't use MimicMeasure, mainly because I want to use heelstrike events in the simulation to synchronize the simulated motion to the tracking data. Secondly because I may want to track measurements that are not state variables.

The Lua init() function needs to load the tracking data from a file, but the IO library seems not to be supported by Scone.

Is there another way to get data into Lua?

I have thought about writing code that generates (lengthy) Lua code to define the tracking data with hard-coded constants, but there may be a better way.

Ton van den Bogert

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

Re: data tracking in ScriptMeasure

Post by Thomas Geijtenbeek » Tue Mar 02, 2021 5:31 am

Hi Ton,

That's great news!

The IO library is indeed not supported by SCONE, but fortunately, generating Lua code is not as bad as it sounds. First, convert your data to a separate file (e.g. 'ExampleDataFile.lua') in the following format:

Code: Select all

local data = {
	channel1 = { 1, 2, 3, 4 },
	channel2 = { 5, 6, 7, 8 }
}
return data
After that, you can cleanly import the data via a 'require' statement to the top of your script:

Code: Select all

data = require 'ExampleDataFile'

-- data can be accessed here (lua indices start at 1!)
first_value = data.channel1[ 1 ]
The only thing to worry about is that your ScriptMeasure should indicate it's using external files, so SCONE will copy them to the output folder:

Code: Select all

ScriptMeasure {
	script_file = "data/ExampleMeasure.lua"
	external_files = [ "data/ExampleDataFile.lua" ]
}
If this doesn't work for you, it's straightforward to add support for the 'io' library in an upcoming version of SCONE. The reason it has been left out so far is for safety concerns, i.e. overwriting or deleting files from Lua scripts.

Finally, here are some (perhaps superfluous) tips, based on previous user experiences with data tracking:
  • It's easiest to record all the data in the 'update(model)' script method, and do all computations in 'result(model)'. This way you know each step size in advance and can quickly lookup the corresponding index in your data.
  • In the Model section of your scenario, you can increase the fixed_measure_step_size to decrease the frequency at which the measure update function is called. This will increase performance.
  • If you define the tracking to be too strict, the resulting muscle activations tend to become high and the motion stiff (even if you've included an additional EffortMeasure). Adding a threshold to the tracking error helps.
  • General disclaimer: shooting-based optimization methods are typically not great at high-precision motion tracking. Direct collocation methods are much more suitable for such scenarios.

User avatar
Ton van den Bogert
Posts: 164
Joined: Thu Apr 27, 2006 11:37 am

Re: data tracking in ScriptMeasure

Post by Ton van den Bogert » Tue Mar 02, 2021 7:57 am

Generating Lua code from the data will definitely work for me. And good to have the data separated from the code this way.

Thanks for the other suggestions and experiences. I will post again when I have my own experience or issues to share.

Ton

POST REPLY