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:

https://github.com/JuliaRobotics/RigidBodySim.jl/blob/e01174abfcf9877bdeba3cf74f4f9b760d1f12ba/src/control.jl#L132-L137

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):

https://github.com/tkoolen/HumanoidLCMSim.jl/blob/c57fd594c78975f0b0f86420281a8506f10fdba8/src/atlassim.jl#L90-L103

(the let block is to work around performance of captured variables in closures · Issue #15276 · JuliaLang/julia · GitHub).

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

https://github.com/JuliaRobotics/RigidBodySim.jl/blob/e01174abfcf9877bdeba3cf74f4f9b760d1f12ba/src/core.jl#L96-L99

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

Thank you! I will try to do this.