Skip to content

Commit

Permalink
Merge pull request #117 from StarlingUAS/ap-sim-address
Browse files Browse the repository at this point in the history
Add host-based lookups for ArduPilot/Gazebo
  • Loading branch information
rob-clarke authored Oct 30, 2021
2 parents ab197ac + b877ab2 commit faca4d6
Show file tree
Hide file tree
Showing 9 changed files with 670 additions and 4 deletions.
4 changes: 4 additions & 0 deletions buildtools/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ target "starling-sim-ardupilot-plane" {

target "starling-sim-ardupilot-gazebo" {
context = "simulator/base/ardupilot"
args = {
"VERSION": "${BAKE_VERSION}",
"REGISTRY": "${BAKE_REGISTRY}"
}
tags = [
"${BAKE_REGISTRY}uobflightlabstarling/starling-sim-ardupilot-gazebo:${BAKE_VERSION}",
notequal("",BAKE_RELEASENAME) ? "${BAKE_REGISTRY}uobflightlabstarling/starling-sim-ardupilot-gazebo:${BAKE_RELEASENAME}": "",
Expand Down
9 changes: 9 additions & 0 deletions docs/details/build_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,12 @@ The set of images are automatically updated on DockerHub. Each image will have a
- `:nightly` tracking the most recent push to the `dev` branch
- `:vX.Y.Z` fixed release tags
- `:${BRANCH}` tracking most recent push to PR branches while active

#### Updating the cache

The builds can be run locally to update the cache if GitHub is timing out. `starling-mavros` is usually the culprit.
The command below will update the nightly tag on Docker Hub, both caching from and to the dev caches.

```bash
BAKE_VERSION=nightly BAKE_CACHEFROM_NAME=cache-dev BAKE_CACHETO_NAME=cache-dev docker buildx bake -f buildtools/docker-bake.hcl --push starling-mavros
```
13 changes: 13 additions & 0 deletions docs/docker-images/sim-ardupilot-vehicle.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Name | Default Value | Description
`AP_OFFSET_Y` | 0 | Start location y offset for SITL
`AP_DISTRIBUTE` | {null} | If set, automatically generate `AP_OFFSET_X` and `AP_OFFSET_Y`
`AP_USE_GAZEBO` | {null} | If set, use a Gazebo model as physics backend
`AP_SIM_ADDRESS` | 127.0.0.1 | IP address to use for talking to Gazebo instance
`AP_SIM_HOST` | {null} | Hostname to use for talking to Gazebo instance. Will __override__ `AP_SIM_ADDRESS`

### `AP_SYSID`

Expand Down Expand Up @@ -86,6 +88,17 @@ grid lines are laid out at 1m separations. As a SYSID of 0 is invalid, no vehicl
When set, `AP_USE_GAZEBO` will cause the SITL to connect to an instance of the ArduPilot plugin running as part of a
Gazebo model. At present, this will use the default IP and port pair: 127.0.0.1:9002/9003

### `AP_SIM_ADDRESS`

Use this to adjust the IP address that the SITL uses to connect to the simulator backend. At present, this is only
relevant when `AP_USE_GAZEBO` is set.

### `AP_SIM_HOST`

When set, the container will resolve the hostname stored in this variable using `getent hosts`. The value from the
lookup will be used in preference to any address set in `AP_SIM_ADDRESS`. If the hostname lookup fails, the container
will exit early.

## Dockerfile Build Arguments

### `VEHICLE`
Expand Down
9 changes: 8 additions & 1 deletion docs/docker-images/sim-iris-ap.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ Based on [`staring-sim-ardupilot-gazebo`](../sim-ardupilot-gazebo)

## Overview

This image adds the launch files required to launch an Iris model with the ArduPilot plugin using Gazebo.
This image adds the launch files required to launch an Iris model with the ArduPilot plugin using Gazebo.

## Environment Variables

Name | Default Value | Description
----------------------|------------------------------|------------
`AP_SITL_ADDRESS` | 127.0.0.1 | IP address for Gazebo plugin to use to talk to ArduPilot instance
`AP_SITL_HOST` | {null} | Hostname for Gazebo plugin to use to talk to ArduPilot instance. Set to __override__ IP address.
15 changes: 14 additions & 1 deletion simulator/base/ardupilot/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ if [ ! -z "$AP_DISTRIBUTE" ]; then
AP_OFFSET_Y=$(( AP_SYSID % 16 ))
fi

if [ ! -z "${AP_SIM_HOST}" ]; then
# AP_SIM_HOST has been set, use it to set AP_SIM_ADDRESS
AP_SIM_ADDRESS="$(getent hosts ${AP_SIM_HOST} | cut -d ' ' -f1)"
if [ -z "${AP_SIM_ADDRESS}" ]; then
# Address lookup failed
echo "Error: Failed to lookup IP address for host '${AP_SIM_HOST}'"
exit 1
fi
fi

AP_SIM_ADDRESS=${AP_SIM_ADDRESS:-127.0.0.1}

exec /src/ardupilot/build/sitl/bin/ardu${AP_VEHICLE} \
--model=${AP_MODEL} \
--home=$(/home/root/offset_location.py ${AP_HOME} ${AP_OFFSET_X} ${AP_OFFSET_Y}) \
--defaults=${AP_PARAM_FILES},$(pwd)/set_sysid.parm
--defaults=${AP_PARAM_FILES},$(pwd)/set_sysid.parm \
--sim-address=${AP_SIM_ADDRESS}
3 changes: 3 additions & 0 deletions simulator/base/ardupilot/sitl.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ ENV AP_PARAM_FILES ""
ENV AP_HOME 51.4235413,-2.6708488,50,250
ENV AP_OFFSET_X 0
ENV AP_OFFSET_Y 0
# AP_DISTRIBUTE
# AP_USE_GAZEBO
ENV AP_SIM_ADDRESS 127.0.0.1
# AP_SIM_HOST

ENTRYPOINT [ "/home/root/entrypoint.sh" ]
9 changes: 7 additions & 2 deletions simulator/vehicles/iris-ap/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ FROM ${REGISTRY}uobflightlabstarling/starling-sim-ardupilot-gazebo:${VERSION}
# Copy in the vehicle launch file
COPY iris.launch.xml /ros_ws/launch/
COPY spawn_iris.sh /ros_ws/
#COPY xacro_launch.sh /ros.env.d/xacro/setup.bash

RUN echo 'export PX4_SITL_PORT=$((PX4_SITL_PORT + PX4_INSTANCE))' >> /ros.env
ENV AP_SITL_ADDRESS 127.0.0.1
# AP_SITL_HOST

# Copy in the xacro & bash file to setup the model with a specific address
RUN mkdir /ros.env.d/iris_ap
COPY model.sdf.xacro /ros.env.d/iris_ap/model.sdf.xacro
COPY iris_setup.sh /ros.env.d/iris_ap/setup.bash

WORKDIR /ros_ws

Expand Down
16 changes: 16 additions & 0 deletions simulator/vehicles/iris-ap/iris_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

if [ ! -z "${AP_SITL_HOST}" ]; then
# AP_SITL_HOST has been set, use it to set AP_SITL_ADDRESS
AP_SITL_ADDRESS="$(getent hosts ${AP_SITL_HOST} | cut -d ' ' -f1)"
if [ -z "${AP_SITL_ADDRESS}" ]; then
# Address lookup failed
echo "Error: Failed to lookup IP address for host '${AP_SITL_HOST}'"
exit 1
fi
fi

XACRO_PATH=/ros.env.d/iris_ap/model.sdf.xacro
MODEL_PATH=/ardupilot_gazebo/models/iris_with_ardupilot/model.sdf

xacro ${XACRO_PATH} fdm_addr:=${AP_SITL_ADDRESS} listen_addr:=0.0.0.0 > ${MODEL_PATH}
Loading

0 comments on commit faca4d6

Please sign in to comment.