3

In Drake/pydrake, all of the examples I have seen create an instance of Simulator and then advance the simulation by a set duration, e.g. sim.AdvanceTo(10) will step the simulation until it has simulated 10 seconds of activity.

How can I instead run a simulation indefinitely, where I don't have a specific duration to advance to, just have the simulation running in its own node and step at a fixed interval forever?

My intention is to just have the simulator running, and then send requests to update commands that will be sent to the robot. Is there a straightforward way to achieve this that won't break the simulation? I figured there would be a public Step function on Simulator, but have only encountered AdvanceTo. My first thought was to try to take the context from a call to AdvanceTo over a short interval, e.g. AdvanceTo(0.01) and then overwrite the context for the next call so that it's updating from the new context instead of the original, but I'm not sure it will work. Maybe there's a more official way to achieve this scheme?

adamconkey
  • 4,104
  • 5
  • 32
  • 61

2 Answers2

2

You can do simulator.AdvanceTo(std::numeric_limits<double>::infinity()); to keep the simulation running indefinitely.

https://github.com/RobotLocomotion/drake/tree/master/examples/kuka_iiwa_arm may be helpful as an example.

Xuchen Han
  • 326
  • 1
  • 6
2

You can do the scheme you proposed. But AdvanceTo() takes a time rather than an interval. To avoid annoying accumulated roundoff you should use an integer step counter and then do AdvanceTo(step_number * dt) where dt is the length of step you would like to take between interruptions.

An alternative would be to use AdvanceTo(infinity) as Xuchen suggested but define some regular update Event that can modify the state when needed.

Sherm
  • 643
  • 4
  • 6