Adding independent Actuator and Controller to Model:

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Musa Audu
Posts: 47
Joined: Mon Nov 24, 2008 11:30 am

Adding independent Actuator and Controller to Model:

Post by Musa Audu » Fri Oct 20, 2017 4:43 am

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.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Adding independent Actuator and Controller to Model:

Post by Christopher Dembia » Mon Oct 30, 2017 10:01 am

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.

User avatar
Musa Audu
Posts: 47
Joined: Mon Nov 24, 2008 11:30 am

Re: Adding independent Actuator and Controller to Model:

Post by Musa Audu » Tue Oct 31, 2017 8:08 am

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

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Adding independent Actuator and Controller to Model:

Post by Christopher Dembia » Tue Oct 31, 2017 10:39 am

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.

User avatar
Musa Audu
Posts: 47
Joined: Mon Nov 24, 2008 11:30 am

Re: Adding independent Actuator and Controller to Model:

Post by Musa Audu » Tue Oct 31, 2017 11:17 am

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

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Adding independent Actuator and Controller to Model:

Post by Christopher Dembia » Tue Oct 31, 2017 11:49 am

Great to hear that you've got your controller working. OpenSim 4.0 is not released and is not yet in beta.

POST REPLY