Page 1 of 1

How to import variable from scriptcontroller to scriptmeasure

Posted: Mon Jan 22, 2024 11:31 pm
by amini_opensim
Hi all

I want to use an objective function that minimize an error in scriptmeasure. Actually, I have defined a new variable at script controller, and I want to use the error (difference between the new variable and joint angle) in scriptmeasure. But as far as I know, I can't import a variable defined in script controller in script measure. Is this correct?

Do you have any idea to save this variable in script controller and use it in the script measure?


Best regards

Re: How to import variable from scriptcontroller to scriptmeasure

Posted: Tue Jan 23, 2024 5:44 am
by tgeijten
Unfortunately, you cannot access these variables, since the controller and measure run independently. The best solution would be to simply recompute the value in the ScriptMeasure.

Re: How to import variable from scriptcontroller to scriptmeasure

Posted: Tue Jan 23, 2024 6:07 am
by amini_opensim
Thanks for your quick reply.

Actually, the variable is computed by some parameters that I want to optimize them. so if I recompute the variable in the scriptmeasure, I will have to define these parameters again and it's false. Unless I can import the optimization parameters to the scripmeasure without re-optimizing them. Is it possible?

Best

Re: How to import variable from scriptcontroller to scriptmeasure

Posted: Thu Feb 01, 2024 2:50 am
by tgeijten
You do actually have access to all the parameters in the ScriptMeasure. Simply use the following init function:

Code: Select all

function init( model, par )
	-- par can be used here
end
I realize this wasn't in the documentation, so I will update it!