Page 1 of 1

How to add new state value

Posted: Mon Dec 02, 2019 2:39 am
by opensim_yuta
Hi, everyone.

I'm creating controller for simulation in MATLAB now. I want to store valuable for controller the state to use integrator. I used following function to store, however, value was not stored in Z which is auxiliary continuous state variables, because Z is empty matrix.
osimState.setZ(Vector(1, a)); or osimState.updZ().set(1, a);

Should I define subsystem to store valuable for controller?
If you know how to add or define new valuables to the state, please help me.

Best regards.
-yuta

Re: How to add new state value

Posted: Mon Dec 02, 2019 9:49 am
by tkuchida
The methods setZ() and updZ() do not create state variables- they just provide access to the variables that already exist (if any).
If you know how to add or define new valuables to the state, please help me.
If your controller needs to define its own state variables, you can write a new Component (in C++) that extends the Controller class. You would define a new state variable in extendAddToSystem(). Please see the "Writing your own Component" section of the API Guide: https://simtk.org/api_docs/opensim/api_ ... components. If you decide to pursue this strategy, the ControllerExample code might be a good starting point: https://github.com/opensim-org/opensim- ... lerExample.

Re: How to add new state value

Posted: Mon Dec 02, 2019 10:42 pm
by opensim_yuta
Dear, Thomas.

Thank you for your reply and suggestion.
I understood I can't add state variables by using the functions in MATLAB. I will learn and do as your suggestion.

Best regards
-Yuta