opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
783 stars 316 forks source link

Support for `Controller`s in Moco #3605

Closed nickbianco closed 6 months ago

nickbianco commented 11 months ago

Adding support for Controllers will require:

  1. Updating the logic in the solvers to allow other controller types (CasADi, tropter).
  2. For each controller, determine how model controls are added (or not added) to the OCP. For example, with a PrescribedController , a user might want the controller to solely provide the controls to the model.
  3. If all Controllers use addInControls to update the model controls, provide the option to create OCP controls on top of the Controller controls.
  4. Provide hooks for the SynergyController class (i.e., support Controllers with Inputs).
nickbianco commented 9 months ago

I've encountered some obstacles while working on PR #3626. While I'm only trying to implement support for PrescribedController in that PR, I want it include a generic implementation that will support upcoming controller types (i.e., SynergyController). This includes controllers that have a list Input for wiring external controls from Moco into the model. However, recent changes to Controller fixing memory leaks using a custom copy construtor prevent me from using Inputs (which do not support custom copy constructors).

Fixing the Controller memory leak without a custom copy constructor means using Sockets to manage the list of Actuators for a particular controller. Unfortunately, OpenSim currently does not support list Sockets, which would be the ideal way to handle this solution. I could create an itermediate class with a Socket for an Actuator, but for the sake of not replacing hacky code with slightly-less-hacky code, I'm going to add support for list Sockets, especially since support for these seemed to be intended in the first place.

Down the rabbit hole we go...