ref:script_controller

Differences

This shows you the differences between two versions of the page.


ref:script_controller [2023/12/14 16:03] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== ScriptController ======
 +[[controller|Controller]] defined through a Lua script. 
 +
 +Runs the script defined in the file defined by ''script_file'', which is relative to the folder of the scone scenario: <code>ScriptController {
 +    script_file = "data/script_file.lua"
 +    external_files = [ "data/my_included_file.lua" ]
 +}
 +</code>Example of a Lua controller script: <code>function init( model, par, side )
 +    -- This function is called at the start of the simulation
 +    -- 'model' can be used to initialize the desired actuators (see LuaModel)
 +    -- 'par' can be used to define parameters for optimization (see LuaPar)
 +    -- 'side' denotes if the controller is for a specific side (-1 = left, 0 = unspecified, 1 = right)
 +end
 +
 +function update( model, time, controller )
 +    -- This function is called at each simulation timestep
 +    -- Use it to update the actuator inputs
 +    -- 'model' can be used to update the desired actuators (see LuaModel)
 +    -- 'time' is the time elapsed since this controller was activated
 +    -- 'controller' can be used to enable/disable child controllers of this ScriptController (see LuaController)
 +    return false -- change to 'return true' to terminate the simulation early
 +end
 +
 +function store_data( current_frame )
 +    -- This function is called at each simulation timestep
 +    -- 'current_frame' can be used to store values for analysis (see LuaFrame)
 +end
 +</code> See also [[lua_model|LuaModel]], [[lua_body|LuaBody]], [[lua_dof|LuaDof]], [[lua_actuator|LuaActuator]], [[lua_muscle|LuaMuscle]], [[lua_frame|LuaFrame]]. See Tutorial 6a and 6b for more information. 
 +
 +**Inherits from** [[composite_controller|CompositeController]].
 +
 +==== Public Attributes ====
 +^ Parameter ^ Type ^ Description ^
 +^ script_file | path | filename of the Lua script, path is relative to the .scone file |
 +^ external_files | ArrayOfFiles | Array of files used by the Lua script; files included by 'require' should be added here as ''external_files = [ file1, file2 ]''. |
 +^ name | String | Name of the controller, uses as a prefix for the control parameters; empty by default. |
 +^ start_time | TimeInSeconds | Time [s] at which [[controller|Controller]] becomes active; default = 0. |
 +^ stop_time | TimeInSeconds | Time [s] at which [[controller|Controller]] becomes inactive; default = until simulation ends. |
 +^ signature_prefix | String | Prefix signature with custom string. Special tags: DATE_TIME, DATE_TIME_EXACT, SCONE_VERSION. |
 +^ signature_postfix | String | Append custom string to signature. Special tags: DATE_TIME, DATE_TIME_EXACT, SCONE_VERSION. |
 +^ signature | String | Set custom signature and omit the auto-generated signature. |
 +
 +<sub>Converted from doxygen using [[https://github.com/tgeijten/dokugen|dokugen]]</sub>