> For the complete documentation index, see [llms.txt](https://campus-rover.gitbook.io/lab-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://campus-rover.gitbook.io/lab-notebook/fiiva/reset-world-gazebo.md).

# reset-world-gazebo.md

## Author: Seho Kim

When you are making games or programs with python using ROS, you may need to reset your world at certain point in your code. The easiest way to reset your Gazebo world would be ctrl+R. However, this may cause unwanted error such as killing one of your node or losing connection.

![ctrl+R Error](https://i.ibb.co/4RDfHwL/reset-world-error.jpg)

To prevent this, you can open up a new terminal and call service:

```
rosservice call /gazebo/reset_world
```

However, you may not want users to manually call service above each time you are required to reset.

\##To Programmatically Reset Your Gazebo Sometimes, your program should reset your Gazebo when certain conditions are met. In order to achieve this, implementing code below will do its job.

```
import rospy
from std_srvs.srv import Empty

rospy.wait_for_service('/gazebo/reset_world')
reset_world = rospy.ServiceProxy('/gazebo/reset_world', Empty)
reset_world()
```

### Empty

We import Empty from std\_srvs.srv to send signal to correct services. Empty type is one of the most common service pattern for sending signal to ROS Node. Empty service does not exchange any actual data between service and a client.

### rospy.wait\_for\_service('/gazebo/reset\_world')

Line above allows code to wait until specific service is active.

### reset\_world = rospy.ServiceProxy('/gazebo/reset\_world', Empty)

Here we declare reset\_world as service definition. First parameter is service name we want to call. In our case, we call '/gazebo/reset\_world' to reset our Gazebo world. Second parameter is for srv which usually contain a request message and a response message. For resetting Gazebo world, we do not need any request message nor response message. For resetting Gazebo world, second parameter should be 'Empty'


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://campus-rover.gitbook.io/lab-notebook/fiiva/reset-world-gazebo.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
