0

I have a robot in my simulation that carries objects to and from places. I would like to spawn an object at a certain position with an initial velocity of 0. The trigger would most likely be a collision detection or when the previous object reaches a certain location. I would also like to despawn objects after being used or if it falls off the robot's end effector (to prevent core dumps after the object drops)

Is there a method in drake to continuously spawn and despawn objects?

Thank you

Yuki
  • 139
  • 6

1 Answers1

0

Drake doesn't have a way to spawn/despawn objects automatically. A few possibilities:

  • (Easiest) Detect triggering events during simulation (the "monitor" function can be handy for that). Take control back, reconstruct the model with the new or removed objects, transfer the state from the old Context to the new one, and restart.
  • Provide all needed objects in the initial model but make unneeded ones inactive (position them far away, set their velocities to zero, and make their accelerations zero*). Detect triggering events using monitor() or witness functions, activate/deactivate objects to emulate spawn/despawn.

* Getting the inactive objects to sit still may take some effort. You could do it with a controller, or by creating a ForceElement that acts like a spring/damper until disabled with a boolean state variable. Others may have better ideas for that.

Sherm
  • 643
  • 4
  • 6
  • Thank you for your reply. Adding on to your comment, would it be possible to instantaneously move the object from the sitting position back into the simulation? Or would I also have to implement a controller for that? – Yuki Mar 09 '20 at 20:54
  • Also, where could I find a good "monitor" example other than "simulator.h" or "simulator_test"? – Yuki Mar 10 '20 at 15:26
  • Yes, you can instantaneously move objects either from an event handler or after a call to Simulator::AdvanceTo() returns (and you can use the monitor() to force a return). You just need to have mutable access to a Context or State. – Sherm Mar 10 '20 at 23:47
  • The monitor() is a new feature and I don't know of any Drake examples that use it. So for now the documentation and simulator_test.cc are all we've got. – Sherm Mar 10 '20 at 23:50