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
-
Nathan Timmers
- Posts: 12
- Joined: Thu Apr 04, 2019 11:10 am
Post
by Nathan Timmers » Thu Feb 13, 2020 6:55 am
Hi,
I am quite new to using SCONE and programming in Lua. There is one thing that keeps bugging me.
Whenever I load a module inside my ScriptController the optimizer returns
flat fitness. I have tried several things now, even up to the point that the loaded module is empty, but still flat fitness. Only when I remove the require command it does optimize properly
My SCONE file:
Code: Select all
CmaOptimizer {
signature_prefix = DATE_TIME
#init_file = data/Gait_10_no_force_20sec.par
#init_file = data/Gait_10_amp_no_force_30sec.par
SimulationObjective {
max_duration = 20
# Model used in simulation
OpenSimModel {
model_file = data/Human0914.osim
#fixed_control_step_size = 0.005 # higher step sizes give better performance
enable_external_forces = 1 # Required when applying external forces
# Optimize initial state parameters
state_init_file = data/InitStateGait10.sto
initial_state_offset = 0~0.01<-0.5,0.5>
initial_state_offset_exclude = "*_tx;*_ty;*_u"
}
CompositeController {
# Controller for gait, based on [Geyer & Herr 2010]
<< data/ControllerGH2010.scone >>
ScriptController {
name = PerturbationDevice
script_file = "data/ScriptTest.lua"
}
}
# Measure for gait
<< data/MeasureGait.scone >>
}
}
My ScriptTest.lua file:
Code: Select all
function init(model, par)
legInit = require "Leg"
end
function update(model)
return false
end
function store_data( frame )
-- store some values for analysis
end
My Leg.lua file (also tried an empty file):
What is going on? The require command seems to upset the optimization process. Any tips on how to get it working?
-
Thomas Geijtenbeek
- Posts: 451
- Joined: Wed Mar 12, 2014 8:08 am
Post
by Thomas Geijtenbeek » Thu Feb 13, 2020 7:25 am
Hi Nathan,
The 'require' command indeed isn't officially supported in SCONE. I suspect the optimizer produces an error because it cannot find the required file, as this isn't copied to the optimization folder. More details should be in the optimization.log file.
I can see how this is hard to derive from the 'flat fitness' message alone. I'll see if I can make a more descriptive error message in a future version of SCONE.
-
Nathan Timmers
- Posts: 12
- Joined: Thu Apr 04, 2019 11:10 am
Post
by Nathan Timmers » Thu Feb 13, 2020 8:40 am
Hi Thomas,
Thanks for the fast reply. You're right indeed, it cannot find the "Leg.lua" file. Do you have any suggestions on how to work around this? I was hoping to avoid writing all the code in one script, but that seems necessary if the 'require' command is not supported.
-
Nathan Timmers
- Posts: 12
- Joined: Thu Apr 04, 2019 11:10 am
Post
by Nathan Timmers » Fri Feb 14, 2020 3:07 am
I tried adding the absolute path of the 'require' files using a solution found on the internet:
Code: Select all
package.path = package.path .. ";<... absolute path ....>/data/lua_files/?.lua;"
which solved the issue of flat fitness. However, this approach seems to mess with the optimizer as well, since the model no longer tries to walk but rather falls quicker every iteration.
-
Thomas Geijtenbeek
- Posts: 451
- Joined: Wed Mar 12, 2014 8:08 am
Post
by Thomas Geijtenbeek » Tue Feb 18, 2020 8:26 am
Hi Nathan,
Using an absolute path is definitely
not recommended, since the file is reloaded before each optimization iteration. Changing the file later will cause the optimization to malfunction and the results to be irreproducible.
Unfortunately, using a single script file is the only way to go for now. I have added a feature request to support this in the upcoming version of SCONE; see
https://github.com/opensim-org/SCONE/issues/183 for details.
-
Thomas Geijtenbeek
- Posts: 451
- Joined: Wed Mar 12, 2014 8:08 am
Post
by Thomas Geijtenbeek » Tue Mar 03, 2020 2:45 pm
This feature supported in SCONE 1.4.0, simply add the files to
external_files in ScriptMeasure / ScriptController:
Code: Select all
external_files = [ required_file_1.lua required_file_2.lua ... ]