Hi All,
I am trying to write a Matlab script that runs a forward dynamics simulation using a specific controls file. I can run the simulation just fine, but it does not use the controls in the file that I specify. The controls all remain at their default values (= 0.0). When I do the same thing in the GUI, the simulation runs as intended using the controls in the specified file. Here is the relevant section of code from my Matlab script:
tool = ForwardTool();
tool.setModel(osimModel);
tool.setStartTime(0);
tool.setFinalTime(1);
tool.setSolveForEquilibrium(true);
tool.setResultsDir(ResultsDirPath);
tool.setControlsFileName('myControls.sto');
tool.setName('mySimulation');
tool.run();
My assumption was that the command "tool.setControlsFileName('myControls.sto');" would cause the tool to use the controls in that file, but that does not appear to be the case. There are no errors or warnings, the simulation runs, but the controls in the specified file are not used. I am running version 3.1 beta, but I had similar results in version 3.0.1. Any thoughts or suggestions are greatly appreciated!
Best,
Brian
ForwardTool - Specify Controls File
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: ForwardTool - Specify Controls File
Hi Brian,
The ControlFile is there in the forward tool for backward compatibility/historical reasons. The typical workflow (as employed by the GUI) is to create a Controller, add it to the model (using addController) and then you get the expected behavior.
Please let me know if that works for you or if you have further questions.
All the best,
-Ayman
The ControlFile is there in the forward tool for backward compatibility/historical reasons. The typical workflow (as employed by the GUI) is to create a Controller, add it to the model (using addController) and then you get the expected behavior.
Please let me know if that works for you or if you have further questions.
All the best,
-Ayman
- Brian Umberger
- Posts: 48
- Joined: Tue Aug 28, 2007 2:03 pm
Re: ForwardTool - Specify Controls File
Hi Ayman,
Thanks for the reply, that makes sense. I will try it and let you know how I make out.
I do have a quick follow-up question: When the forward tool is run by the GUI and it reads a user specified controls file, which type of controller does it create to apply those controls to the model actuators (ControlSetController, PrescribedController, etc)?
Thanks again!
Brian
Thanks for the reply, that makes sense. I will try it and let you know how I make out.
I do have a quick follow-up question: When the forward tool is run by the GUI and it reads a user specified controls file, which type of controller does it create to apply those controls to the model actuators (ControlSetController, PrescribedController, etc)?
Thanks again!
Brian
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: ForwardTool - Specify Controls File
Hi Brian,
The deserialization code creates a ControlSetController and attaches it to the model. Then it calls
setControlSetFileName(controlsFileName) on it.
Best of luck and please let me know how it goes,
-Ayman
The deserialization code creates a ControlSetController and attaches it to the model. Then it calls
setControlSetFileName(controlsFileName) on it.
Best of luck and please let me know how it goes,
-Ayman
- Brian Umberger
- Posts: 48
- Joined: Tue Aug 28, 2007 2:03 pm
Re: ForwardTool - Specify Controls File
Hi Ayman,
Thanks for the helpful responses. I've been able to apply arbitrary controls to my model by creating a PrescribedController() and defining a PiecewiseLinearFunction(). I think this will work for my current purposes. However, the ControlSetController() did not work for me in Matlab (I'm using the OpenSim 3.1 beta RC3). The command:
muscleController = ControlSetController();
resulted in this error:
Undefined function or variable 'ControlSetController'.
In contrast, issuing the command: muscleController = PrescribedController(); works just fine.
Is there no access to ControlSetController from Matlab, or am I doing something wrong?
Thanks again!
Brian
Thanks for the helpful responses. I've been able to apply arbitrary controls to my model by creating a PrescribedController() and defining a PiecewiseLinearFunction(). I think this will work for my current purposes. However, the ControlSetController() did not work for me in Matlab (I'm using the OpenSim 3.1 beta RC3). The command:
muscleController = ControlSetController();
resulted in this error:
Undefined function or variable 'ControlSetController'.
In contrast, issuing the command: muscleController = PrescribedController(); works just fine.
Is there no access to ControlSetController from Matlab, or am I doing something wrong?
Thanks again!
Brian
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: ForwardTool - Specify Controls File
Hi Brian,
As you found out the ControlSetController was not made available to the Matlab interface.
Based on discussion with the rest of the development team, the plan is to add convenience constructor(s) to the PrescribedController to allow it to use XML files as written by CMC and other tools, and to make this available in the next version. We're trying to move away from using XML files for control over the long term and taking out ControlSetController was a step in this direction.
Hope this explains and please let me know if you have any further questions.
All the best,
-Ayman
As you found out the ControlSetController was not made available to the Matlab interface.
Based on discussion with the rest of the development team, the plan is to add convenience constructor(s) to the PrescribedController to allow it to use XML files as written by CMC and other tools, and to make this available in the next version. We're trying to move away from using XML files for control over the long term and taking out ControlSetController was a step in this direction.
Hope this explains and please let me know if you have any further questions.
All the best,
-Ayman
- Brian Umberger
- Posts: 48
- Joined: Tue Aug 28, 2007 2:03 pm
Re: ForwardTool - Specify Controls File
Hi Ayman,
Thanks again for the response, that makes perfect sense. Hopefully it is not too cumbersome to add a convenience constructor for something that you are trying to move away from anyway. In the meantime, that addition will be helpful.
Cheers,
Brian
Thanks again for the response, that makes perfect sense. Hopefully it is not too cumbersome to add a convenience constructor for something that you are trying to move away from anyway. In the meantime, that addition will be helpful.
Cheers,
Brian