RigidBodySim.jl and disturbances

Hi, is there any way to add friction or other disturbance to the model as the controller is added? Something like:

closed_loop_dynamics = Dynamics(robot, control!, disturbance!)

Perhaps control! is a bit of a misnomer; it’s really just a torque source. The control! function you pass in could first call the actual controller to get the actuator torque vector, and then add additional torques (e.g., your disturbance torques).

Perhaps it would be nice to have a convenience type that stores a bunch of control! functions, satisfies the standard controller call signature, and does the addition of torques for you. @rdeits and I were talking about that at some point but never got around to it. PR’s definitely welcome.

In analog controller simulations it is possible to add directly to the function, the problem is that in my case my disturbance function would act as a “controller in the loop” and my controller would be simulated as a digital controller. It is possible to create two callbacks but both would modify the torque value and this would not give the effect of continuous disturbance on the system. I will do some tests by adding ‘τdcache’ to the Dynamics type and modifying the function used in ODE.

You can still do this with a PeriodicController, you just have to be careful with the associated PeriodicCallback that ensures that the simulation is stopped at the appropriate times for the controller to be run. If you tried calling a PeriodicController from another control! function, you may have gotten this error message:

The last part describes how to make this work; let me know if this is not clear enough.

Here’s an example that implements this (sorry I didn’t think of this earlier):

(the let block is to work around https://github.com/JuliaLang/julia/issues/15276).

By the way, if instead of a simple closure you’re making a callable named type, you can overload controlcallback for that type:

to avoid having to explicitly create the callback and pass it into the ODEProblem constructor.

Thank you! I will try to do this.