Page 1 of 1

Adding independent Actuator and Controller to Model:

Posted: Fri Oct 20, 2017 4:43 am
by mlaudu
I have a model that has a number of muscle actuators and I want to add another actuator that applies force on two segments of the model as a function of some of the state variables in the model. I reckon I should define an actuator and a controller for that additional actuator (similar to tugOfWar actuator). So I derive two classes – MyActuator from Actuators class and MyController from Controller class. Now I have two issues:

1. I want MyController to only be associated with MyActuator and not with the Muscle Actuators in the model. If I invoke addActuators() with an object of MyController, all the actuators, including the muscles are associated with MyController which is not what I want. If I invoke SetActuators with an object of MyActuators as an argument this does not work either because the argument of SetActuators is a Set<Actuators> type and not an Actuators type. How do I define a Set<Actuator> type different from an Actuator type or re-cast Actuators type to a Set<Actuators> type? The explanation in ClassNameMapping.pdf only takes me in a circuitous path.

2. Also, I was surprised to see that even though MyController is derived from class Controller, invoking the method setNumControls() with an object of MyController throws an error that only a controller can set its number of controls based on the actuators associated with it.
I will appreciate any help with these issues.

Re: Adding independent Actuator and Controller to Model:

Posted: Mon Oct 30, 2017 10:01 am
by chrisdembia
You're going down the correct path.

Use Controller::addActuator() (as shown in the README example: https://github.com/opensim-org/opensim-core) to tell your Controller that it should control your custom actuator. This only adds your one actuator to the controller, not all the other muscle actuators. This function is called *outside* of your controller, not inside the controller.

I don't think you should call setNumControls yourself. That seems like something handled internally based on the number of actuators that you added to the controller. Simly use addInControls() within your Controller::computeControls() function, as shown in the ControllerExample.

Re: Adding independent Actuator and Controller to Model:

Posted: Tue Oct 31, 2017 8:08 am
by mlaudu
Thanks Chris. That works. But doesn't adInControls() add to the values already occupying the slot in the system-wide model controls? I just overrode Actuator_ setControls() in my Actuator methods to update my actuator control values and it seems to work fine. Thanks for the help.
Musa

Re: Adding independent Actuator and Controller to Model:

Posted: Tue Oct 31, 2017 10:39 am
by chrisdembia
Yes you're correct. What do you mean by overriding setControls()? That doesn't sound right. Is there another controller that's adding controls to your non-muscle actuator and you don't desire this? If you're using CMC, you can tell CMC to ignore certain actuators.

Re: Adding independent Actuator and Controller to Model:

Posted: Tue Oct 31, 2017 11:17 am
by mlaudu
Chris,
Oops! Scratch that off! I had thought I needed to override those methods when I was getting some weird error messages; but got around them. Now I did not need to override them. Thanks for all the insight. Now my code runs well.
By the way, is version 4.0 now considered a stable release or is it still in beta phase?
Thanks.
Musa

Re: Adding independent Actuator and Controller to Model:

Posted: Tue Oct 31, 2017 11:49 am
by chrisdembia
Great to hear that you've got your controller working. OpenSim 4.0 is not released and is not yet in beta.