-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #448 from gazebosim/caguero/ros_gz_overview
Extend ROS integration documentation
- Loading branch information
Showing
5 changed files
with
230 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Launch Gazebo from ROS 2 | ||
|
||
Gazebo can be launched from a ROS 2 launch system in multiple ways: | ||
|
||
## Using the launch files included in | ||
[ros_gz_sim](https://github.com/gazebosim/ros_gz/tree/ros2/ros_gz_sim). | ||
|
||
The package `ros_gz_sim` contains two launch files named `gz_server.launch.py` | ||
and `gz_sim.launch.py`. You can use them to start Gazebo server or Gazebo (server and GUI) | ||
respectively. | ||
|
||
```bash | ||
ros2 launch ros_gz_sim gz_sim.launch.py gz_args:=empty.sdf | ||
``` | ||
|
||
Or you can just start the server: | ||
|
||
```bash | ||
ros2 launch ros_gz_sim gz_server.launch.py world_sdf_file:=empty.sdf | ||
``` | ||
|
||
Consult the argument block of each launch file | ||
[here](https://github.com/gazebosim/ros_gz/blob/ros2/ros_gz_sim/launch/gz_sim.launch.py.in#L75-L96) | ||
and [here](https://github.com/gazebosim/ros_gz/blob/ros2/ros_gz_sim/launch/gz_server.launch.py#L27-L38) | ||
to learn about the different parameters that are accepted by each launch file. | ||
|
||
## Using a custom launch file. | ||
|
||
It's also possible to start Gazebo from your custom launch file. For that | ||
purpose we have created the custom `<gz_server/>` tag that can be used from you | ||
XML or YAML launch file. In this case, the arguments are passed as attributes | ||
within this tag. Here's an example for launching Gazebo server: | ||
|
||
```xml | ||
<launch> | ||
<arg name="world_sdf_file" default="empty.sdf" /> | ||
<arg name="world_sdf_string" default="" /> | ||
<arg name="container_name" default="ros_gz_container" /> | ||
<arg name="use_composition" default="True" /> | ||
<gz_server | ||
world_sdf_file="$(var world_sdf_file)" | ||
world_sdf_string="$(var world_sdf_string)" | ||
container_name="$(var container_name)" | ||
use_composition="$(var use_composition)"> | ||
</gz_server> | ||
</launch> | ||
``` | ||
|
||
In this case the `<gz_server>` parameters are read from the command line. That's | ||
an option but not strictly necessary as you could decide to hardcode some of the | ||
values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# ROS 2 integration overview | ||
|
||
Gazebo can be integrated within a ROS 2 system. Let's start describing the | ||
different types of integrations that you can achieve between Gazebo and ROS. | ||
|
||
* Use ROS to launch Gazebo: ROS prescribes a specific way to launch all | ||
the pieces needed in your system. There's a dedicated | ||
[launch mechanism](https://docs.ros.org/en/rolling/Tutorials/Intermediate/Launch/Creating-Launch-Files.html) | ||
to orchestrate the launch of all your components and many tooling around it. | ||
Gazebo can be launched in this way. | ||
|
||
* Use ROS to interact with Gazebo topics via the [`ros_gz` bridge](https://github.com/gazebosim/ros_gz): | ||
Once Gazebo is up and running, it's very common to communicate with the | ||
simulation. A common way to perform this communication is via topics. Gazebo has | ||
its own middleware, Gazebo Transport, that exposes a set of topics and services quite similar to ROS. The `ros_gz` bridge allows you to create a bridge between | ||
Gazebo and your ROS system, that translates between Gazebo Transport and ROS 2 | ||
as needed. | ||
|
||
* Use ROS to spawn a Gazebo model: Gazebo worlds can include models that are | ||
loaded at startup. However, sometimes you need to spawn models at runtime. This | ||
task can be performed using ROS 2. | ||
|
||
## Requirements | ||
|
||
Please follow the [Install Gazebo and ROS document](/docs/latest/ros_installation) | ||
before starting this tutorial. A working installation of ROS 2 and Gazebo is | ||
required to go further. | ||
|
||
## Composition | ||
|
||
If you inspect the parameters of the launch files mentioned in the next | ||
tutorials, you'll notice that we have included in most cases a parameter named | ||
`use_composition`. When that parameter is set to `True`, the associated ROS | ||
node will be included within a ROS container. When this happens all the nodes | ||
live within the same process and can leverage intraprocess communication. | ||
|
||
Our recommendation is to always set the `use_composition` parameter to `True`. | ||
That way, the communication between Gazebo and the bridge will be intraprocess. | ||
If your ROS nodes are also written as composable nodes, make sure that they are | ||
launched with the `container_node_name` parameter matching the container name | ||
including Gazebo and the bridge. | ||
|
||
You can learn more about ROS composition in [this tutorial](https://docs.ros.org/en/galactic/Tutorials/Intermediate/Composition.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Spawn a Gazebo model from ROS 2 | ||
|
||
Gazebo will spawn all the models included in the provided world file at startup. | ||
Additionally, it's possible to spawn new models at any time. To do so using ROS | ||
we have provided the following mechanisms: | ||
|
||
## Spawn a model using the launch file included in `ros_gz_sim`. | ||
|
||
The package `ros_gz_sim` contains a launch file named | ||
`ros_gz_spawn_model.launch.py`. You can use it to spawn a new model into an | ||
existing simulation. Here's an example: | ||
|
||
```bash | ||
ros2 launch ros_gz_sim gz_spawn_model.launch.py world:=empty file:=$(ros2 pkg prefix --share ros_gz_sim_demos)/models/vehicle/model.sdf name:=my_vehicle x:=5.0 y:=5.0 z:=0.5 | ||
``` | ||
|
||
Check [this block](https://github.com/gazebosim/ros_gz/blob/cadae1c8323a74395c09a37e3de4c669c8c09d4f/ros_gz_sim/launch/ros_gz_spawn_model.launch.py#L33-L44) | ||
from the source code to know all the different parameters accepted by this | ||
launch file. | ||
|
||
## Spawn a model from a custom launch file. | ||
|
||
It's also possible to spawn the model from your custom launch file. For that | ||
purpose we have created the `<gz_spawn_model/>` tag that can be used from you | ||
XML or YAML launch file. In this case, the arguments are passed as attributes | ||
within this tag. Here's an example: | ||
|
||
```xml | ||
<launch> | ||
<arg name="world" default="" /> | ||
<arg name="file" default="" /> | ||
<arg name="xml_string" default="" /> | ||
<arg name="topic" default="" /> | ||
<arg name="name" default="" /> | ||
<arg name="allow_renaming" default="False" /> | ||
<arg name="x" default="" /> | ||
<arg name="y" default="" /> | ||
<arg name="z" default="" /> | ||
<arg name="roll" default="" /> | ||
<arg name="pitch" default="" /> | ||
<arg name="yaw" default="" /> | ||
<gz_spawn_model | ||
world="$(var world)" | ||
file="$(var file)" | ||
xml_string="$(var xml_string)" | ||
topic="$(var topic)" | ||
name="$(var name)" | ||
allow_renaming="$(var allow_renaming)" | ||
x="$(var x)" | ||
y="$(var y)" | ||
z="$(var z)" | ||
roll="$(var roll)" | ||
pitch="$(var pitch)" | ||
yaw="$(var yaw)"> | ||
</gz_spawn_model> | ||
</launch> | ||
``` | ||
|
||
In this case the `<gz_spawn_model>` parameters are read from the command line. | ||
That's an option but not strictly necessary as you could decide to hardcode some | ||
of the values. |