osrf / mbzirc

Simulator for the MBZIRC Maritime Grand Challenge
Apache License 2.0
72 stars 47 forks source link

Auto exit sim when run has finished #181

Closed iche033 closed 2 years ago

iche033 commented 2 years ago

Signed-off-by: Ian Chen ichen@osrfoundation.org

Added a exit_on_finish param to GamelogicPlugin. When set to true, simulation should automatically shutdown once the run has finished, i.e all tasks completed or max run duration reached.

I also had to add some logic to the launch files to shutdown the all ROS launch processes once the ign gazebo exits. This is needed by cloudsim as it expects that a run has ended when a docker container exits. It can then continue to do things like uploading logs to s3.

I added a coast_cloud.sdf with exit_on_finish set to true for testing on cloudsim. It's currently just a copy of coast.

To test:

  1. Launch coast_cloud.sdf with a few robots

    ros2 launch mbzirc_ign competition.launch.py world:=coast_cloud config_file:=`ros2 pkg prefix mbzirc_ign`/share/mbzirc_ign/config/coast/config_team.yaml
  2. Manually end the run:

    ign service -s /mbzirc/finish --reqtype ignition.msgs.Boolean --reptype ignition.msgs.Boolean --timeout 3000 --req 'data: 1'
  3. Wait ~10 seconds. Gazebo should exit and ROS2 launch processes should be shutdown. You should get your terminal back.