Skip to content

Fix visualization python tutorial #1377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions tutorials/python_interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,50 @@ step simulation and check entities and components.

- **Step 1**: Load a world with a fixture

```python
file_path = os.path.dirname(os.path.realpath(__file__))
helper = HelperFixture(os.path.join(file_path, 'gravity.sdf'))
```
```{.python}
file_path = os.path.dirname(os.path.realpath(__file__))
helper = HelperFixture(os.path.join(file_path, 'gravity.sdf'))
```

- **Step 2**: Write your `preupdate`, `update` or `postupdate` code:
```python
def on_post_udpate_cb(_info, _ecm):
# <your code here>
...
```

```python
def on_post_udpate_cb(_info, _ecm):
# <your code here>
...
```

- **Step 3**: Register the function.
```python
helper.on_post_update(on_post_udpate_cb)
```

```python
helper.on_post_update(on_post_udpate_cb)
```

- **Step 4**: Be sure to call finalize before running the server.
```python
helper.finalize()
```

```python
helper.finalize()
```

- **Step 5**: Run the server
```python
server.run(False, 1000, False)
while(server.is_running()):
time.sleep(0.1)
```

```python
server.run(False, 1000, False)
while(server.is_running()):
time.sleep(0.1)
```

# Run the example

In the
[examples/scripts/python_api](https://github.com/ignitionrobotics/ign-gazebo/blob/ign-gazebo6/examples/scripts/python_api)
folder there is a Python script that shows how to make use of this API.

> If you compiled Ignition Gazebo from source you should modify your `PYTHONPATH`:
>
> ```bash
> export PYTHONPATH=$PYTHONPATH:<path to ws>/install/lib/python
> ```
If you compiled Ignition Gazebo from source you should modify your `PYTHONPATH`:

```bash
export PYTHONPATH=$PYTHONPATH:<path to ws>/install/lib/python
```

Now you can run the example:

Expand Down