Robotics StackExchange | Archived questions

Gazebo World Reset using ROS

Hello,

I need to reset the world in Gazebo. I know it can be done manually using the Gazebo GUI and doing Ctrl-R but I need to do it programmatically. I have genetic algorithms running in Visual Studio in Windows and I am communicating with ROS mater using rosserial_windows. Now after every generation I need to reset the world since I am evolving controllers for the robot. I am using ROS and Gazebo 5.0. How it can be done?

Thanks,

Asked by Imran Zafar on 2016-12-23 05:50:23 UTC

Comments

Answers

Hello Guys,

I found the solution to programmatically reset gazebo. So I am posting it here for others to benefit:

  1. Create a publisher that publishes an empty message using std_msg::Empty
  2. On the ROS side create a subscriber that listens to this topic lets say "reset_world"
  3. Upon hearing the request the subscriber then calls a service that resets the gazebo world. Below is the code for that service:

std_srvs::Empty empty_packet; if(resetworld_client.call(empty_packet)) { ROS_INFO("Reset World); } else { ROS_INFO("Failed to reset the world"); }

And that's it. This particular code should be in the call back function of the subscriber that you made in ROS.

Asked by Imran Zafar on 2017-01-03 05:31:48 UTC

Comments