srl-freiburg / pedsim_ros

Pedestrian simulator powered by the social force model
https://github.com/srl-freiburg/pedsim_ros
BSD 2-Clause "Simplified" License
447 stars 169 forks source link

How to restart simulation #59

Open mphamhung opened 4 years ago

mphamhung commented 4 years ago

Hi, are there any exposed functions that would let me restart the simulation without killing and relaunching? I'm looking to implementing an openaigym-like interface and want to restart the simulation for each episode.

makokal commented 4 years ago

There is nothing exposed right now, but it should be easy to clear the scene and re-spawn the agents

mphamhung commented 4 years ago

In simulator_node.cpp, I add the following calls too a ros listener callback:

      sm.cleanUp();
      sm.initializeSimulation();
      sm.runSimulation();

Where sm.cleanUp is defined in simulator.cpp as:

void Simulator::cleanUp() {
  SCENE.clear();
}

This seems to get the simulator to reset on callback, except the pedsim simulator node crashes after a few times. I get an exit code -11, which sounds to me like a memory reference problem. Furthermore, each time new agents spawn, their number in rviz also increases?

Is there a different way to clear and respawn?

makokal commented 4 years ago

Yes, this is a little more involved. We need to also reset agent ids in the libpedsim part.