Search code examples
drake

Adding items to simulation at runtime


From my, limited, understanding of Drake's working we need to add all the actors in its world as plant / leaf in a system and pass that diagram & its context to the Simulator. So, how would you create items at runtime? Or is that not feasible at the moment? Context is robotic picking connected to external application so simulator never knows which items are going to be presented to the arm in a box.

Many Thanks.


Solution

  • It's true adding new models into the MultibodyPlant after it's been finalized is not supported as of today (though we are very slowing working towards it; PR#20771 is progress in that direction).

    The current recommendation is to:

    • add all bodies that you might want to interact when you first construct the plant
    • set the positions of the unneeded bodies in some safe location (e.g. away from the robot), and Lock the bodies/joints. Locked bodies/joints should have a minimal impact on simulation performance.
    • when it's time to "add the new object", you stop the simulation, unlock the joint and set its new position, then restart the simulation by calling simulator.AdvanceTo().

    I have also seen more sophisticated versions of this that actually rebuild the MultibodyPlant (and Diagram) one the simulator is stopped, then map over the Context from the first diagram into the Context of the second, then start the simulation again.