Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Tidy up multi-simulation doc #835

Merged
merged 1 commit into from
Jul 10, 2019
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
51 changes: 31 additions & 20 deletions en/simulation/multi-vehicle-simulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ To build an example setup, follow the step below:
DONT_RUN=1 make px4_sitl_default gazebo
```
1. Source your environment:

```
source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd):$(pwd)/Tools/sitl_gazebo
```

1. Run launch file:

```
roslaunch px4 multi_uav_mavros_sitl.launch
```
Expand Down Expand Up @@ -62,7 +60,7 @@ For each simulated vehicle, the following is required:
The launch file `multi_uav_mavros_sitl.launch`does the following,

* loads a world in gazebo,
```
```
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lamping7
Note

  1. Typically use three backticks on a new line for a block of code and single backticks for an inline code. With a block you can specify the programming language for syntax highlighting (I have not done this here).
  2. The backticks and blocks have to be indented next to the text in the bullet - in this case 2 spaces.

<!-- Gazebo sim -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="gui" value="$(arg gui)"/>
Expand All @@ -71,11 +69,11 @@ The launch file `multi_uav_mavros_sitl.launch`does the following,
<arg name="verbose" value="$(arg verbose)"/>
<arg name="paused" value="$(arg paused)"/>
</include>
```
```
* for each vehicle,

* creates urdf model from xacro, loads gazebo model and runs PX4 SITL app instance
```
```
<!-- PX4 SITL and vehicle spawn -->
<include file="$(find px4)/launch/single_vehicle_spawn.launch">
<arg name="x" value="0"/>
Expand All @@ -89,18 +87,18 @@ The launch file `multi_uav_mavros_sitl.launch`does the following,
<arg name="mavlink_tcp_port" value="4560"/>
<arg name="ID" value="$(arg ID)"/>
</include>
```
```

* runs a mavros node
```
```
<!-- MAVROS -->
<include file="$(find mavros)/launch/px4.launch">
<arg name="fcu_url" value="$(arg fcu_url)"/>
<arg name="gcs_url" value=""/>
<arg name="tgt_system" value="$(arg ID)"/>
<arg name="tgt_component" value="1"/>
</include>
```
```

> **Note** The complete block for each vehicle is enclosed in a set of `<group>` tags to separate the ROS namespaces of the vehicles.

Expand All @@ -121,25 +119,38 @@ To add a third iris to this simulation there are two main components to consider


## Multiple Vehicles using SDF Models
Developers can alternatively simulate multiple vehicles using vehicle models defined in Gazebp SDF files (instead of using models defined in the ROS Xacro file, as discussed in the rest of this topic).

This section shows how developers can simulate multiple vehicles using vehicle models defined in Gazebo SDF files (instead of using models defined in the ROS Xacro file, as discussed in the rest of this topic).

The steps are:

1. Install xmlstarlet from your Linux terminal
`sudo apt install xmlstarlet`
1. Use roslaunch with the multi_uav_mavros_sitl_sdf.launch launch file:
`roslaunch multi_uav_mavros_sitl_sdf.launch vehicle:=<model_file_name>`
1. Install *xmlstarlet* from your Linux terminal:
```
sudo apt install xmlstarlet
```
1. Use *roslaunch* with the **multi_uav_mavros_sitl_sdf.launch** launch file:
````
roslaunch multi_uav_mavros_sitl_sdf.launch vehicle:=<model_file_name>
```

> **Note** that the vehicle model file name argument is optional; the [plane model](https://github.com/PX4/sitl_gazebo/tree/master/models/plane) will be used by default.
> **Note** that the vehicle model file name argument is optional (`vehicle:=<model_file_name>`); if omitted the [plane model](https://github.com/PX4/sitl_gazebo/tree/master/models/plane) will be used by default.

This method is similar to using the xacro except that the SITL/Gazebo port number is automatically inserted by _xmstarlet_ for each spawned vehicle, and does not need to be specified in the SDF file.

To add a new vehicle, you need to make sure the model can be found in order to spawn it in Gazebo and PX4 needs to have an approperate startup script corresponding to it.

1. You can choose to either modify the `single_vehicle_spawn_sdf.launch` file to point to the location of your model by changing the line containing:
`$(find px4)/Tools/sitl_gazebo/models/$(arg vehicle)/$(arg vehicle).sdf`
to point to your model or copy your model in to the folder above (following the same path convention). Be sure to set the `vehicle` argument even if you hardcode the path to your model.
1. The `vehicle` argument is used to set the `PX4_SIM_MODEL` environment variable, which is used by the default rCS (startup script) to find the corresponding startup settings file for the model. Within PX4 these startup files can be found in the `Firmware/ROMFS/px4fmu_common/init.d-posix/` directory. For example, here is the plane model's [startup script](https://github.com/PX4/Firmware/blob/master/ROMFS/px4fmu_common/init.d-posix/1030_plane). For this to work, the PX4 node in the launch file is passed arguemnts that specify the rCS file (`etc/init.d/rcS`) and the location of the rootfs directory (`$(find px4)/ROMFS/px4fmu_common`). For simplicity, it is suggested that the startup file for the model be placed alongside PX4's in `Firmware/ROMFS/px4fmu_common/init.d-posix/`.
To add a new vehicle, you need to make sure the model can be found (in order to spawn it in Gazebo), and PX4 needs to have an appropriate corresponding startup script.

1. You can choose to do either of:
* modify the **single_vehicle_spawn_sdf.launch** file to point to the location of your model by changing the line below to point to your model:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to use bold for filenames, italic for tool names, and code for code or command line invocations.

```
$(find px4)/Tools/sitl_gazebo/models/$(arg vehicle)/$(arg vehicle).sdf
```
> **Note** Ensure you set the `vehicle` argument even if you hardcode the path to your model.
* copy your model into the folder indicated above (following the same path convention).
1. The `vehicle` argument is used to set the `PX4_SIM_MODEL` environment variable, which is used by the default rCS (startup script) to find the corresponding startup settings file for the model.
Within PX4 these startup files can be found in the **Firmware/ROMFS/px4fmu_common/init.d-posix/** directory.
For example, here is the plane model's [startup script](https://github.com/PX4/Firmware/blob/master/ROMFS/px4fmu_common/init.d-posix/1030_plane).
For this to work, the PX4 node in the launch file is passed arguments that specify the *rCS* file (**etc/init.d/rcS**) and the location of the rootfs directory (`$(find px4)/ROMFS/px4fmu_common`).
For simplicity, it is suggested that the startup file for the model be placed alongside PX4's in **Firmware/ROMFS/px4fmu_common/init.d-posix/**.


## Additional Resources
Expand Down