Skip to content

Commit

Permalink
Merge remote-tracking branch 'clyde_remote/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezenders committed Dec 28, 2022
2 parents f08af38 + 8fa5368 commit 19b1be3
Show file tree
Hide file tree
Showing 21 changed files with 310 additions and 141 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
cmake-build-*
.cmake-build-*
38 changes: 0 additions & 38 deletions Dockerfile_galactic_garden

This file was deleted.

60 changes: 31 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
# BlueROV2 in Ignition Gazebo
# BlueROV2 in Gazebo Garden

> Status: proof-of-concept
> Status: proof-of-concept, updated for Gazebo Garden binaries
This is a model of the BlueROV2 that runs in Ignition Gazebo.
This is a model of the BlueROV2 that runs in Gazebo Garden.
It uses the BuoyancyPlugin, HydrodynamicsPlugin and ThrusterPlugin.

Requirements:
* Ignition Gazebo, built from source with [this patch](https://github.com/ignitionrobotics/ign-gazebo/pull/1402)
* See [garden.repos](garden.repos) for commit hashes
* See [Dockerfile_galactic_garden](Dockerfile_galactic_garden) for build instructions
* ardupilot_gazebo, built from source on [this branch](https://github.com/ArduPilot/ardupilot_gazebo/tree/ignition-garden)
* ArduSub
* MAVProxy
![RVIZ2_GUI](images/gazebo.png)

Running Ignition Gazebo:

## Requirements

* [Gazebo Garden 7.1.0](https://gazebosim.org/docs/garden/install)
* [ardupilot_gazebo](https://github.com/ArduPilot/ardupilot_gazebo)
* [ArduSub and MAVProxy](https://ardupilot.org/dev/docs/building-setup-linux.html)

See the [Dockerfile](docker/Dockerfile) for installation details.

## Running Gazebo

Launch Gazebo:
~~~
$ . ~/ignition_ws/install/setup.bash
$ ign gazebo --version
Ignition Gazebo, version 7.0.0~pre1
$ export IGN_GAZEBO_RESOURCE_PATH=~/colcon_ws/src/bluerov2_ignition/models:~/colcon_ws/src/bluerov2_ignition/worlds
$ export IGN_GAZEBO_SYSTEM_PLUGIN_PATH=~/ardupilot_gazebo/build
$ ign gazebo -v 3 -r underwater.world
export GZ_SIM_RESOURCE_PATH=~/colcon_ws/src/bluerov2_ignition/models:~/colcon_ws/src/bluerov2_ignition/worlds
export GZ_SIM_SYSTEM_PLUGIN_PATH=~/ardupilot_gazebo/build
gz sim -v 3 -r underwater.world
~~~

Directly send thrust commands:
You can directly send thrust commands to the BlueROV2 model in Gazebo:
~~~
$ . ~/ignition_ws/install/setup.bash
$ cd ~/colcon_ws/src/bluerov2_ignition
$ . scripts/cw.sh
$ . scripts/stop.sh
cd ~/colcon_ws/src/bluerov2_ignition
. scripts/cw.sh
. scripts/stop.sh
~~~

Running ArduSub:
Now Launch ArduSub and ardupilot_gazebo:
~~~
$ cd ~/ardupilot
$ Tools/autotest/sim_vehicle.py -L RATBeach -v ArduSub --model=JSON --out=udp:0.0.0.0:14550 --console
cd ~/ardupilot
Tools/autotest/sim_vehicle.py -L RATBeach -v ArduSub --model=JSON --out=udp:0.0.0.0:14550 --console
~~~

Sending commands to ArduSub:
Use MAVProxy to send commands to ArduSub:
~~~
arm throttle
rc 3 1450
Expand All @@ -47,14 +48,15 @@ rc 5 1550
disarm
~~~

Caveats:
## Caveats:
* The model needs tuning
* The visuals are quite basic

References:
## References:
* https://github.com/ardupilot/ardupilot_gazebo/wiki
* https://ignitionrobotics.org/docs/garden
* https://gazebosim.org/docs/garden/install
* https://ardupilot.org/dev/docs/building-setup-linux.html
* https://ardupilot.org/dev/docs/setting-up-sitl-on-linux.html
* https://ardupilot.org/mavproxy/docs/getting_started/download_and_installation.html
* https://www.ardusub.com/developers/rc-input-and-output.html
* https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html
128 changes: 128 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
FROM ubuntu:22.04 AS base

ARG USERNAME=bluerov2
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get upgrade -y

# Install language
RUN apt-get update \
&& apt-get -y --quiet --no-install-recommends install \
locales \
&& locale-gen en_US.UTF-8 \
&& update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 \
&& rm -rf /var/lib/apt/lists/*
ENV LANG=en_US.UTF-8

# Install timezone
RUN ln -fs /usr/share/zoneinfo/UTC /etc/localtime \
&& apt-get update \
&& apt-get -y --quiet --no-install-recommends install \
tzdata \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& rm -rf /var/lib/apt/lists/*

# Install a few handy tools
RUN apt-get update \
&& apt-get -y --quiet --no-install-recommends install \
bash-completion \
build-essential \
git \
glmark2 \
gnupg \
iputils-ping \
lsb-release \
mlocate \
software-properties-common \
sudo \
wget \
vim \
&& rm -rf /var/lib/apt/lists/*

# Install Gazebo Garden
RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
RUN apt-get update \
&& apt-get -y --quiet --no-install-recommends install \
gz-garden \
&& rm -rf /var/lib/apt/lists/*

# Install NVIDIA software
RUN apt-get update \
&& apt-get -y --quiet --no-install-recommends install \
libglvnd0 \
libgl1 \
libglx0 \
libegl1 \
libxext6 \
libx11-6 \
&& rm -rf /var/lib/apt/lists/* \
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=graphics,utility,compute
ENV QT_X11_NO_MITSHM=1

# Install some ardupilot and ardupilot_gazebo prereqs
RUN apt-get update \
&& apt-get -y --quiet --no-install-recommends install \
python3-wxgtk4.0 \
rapidjson-dev \
xterm \
&& rm -rf /var/lib/apt/lists/*

# Create a non-root user
# Required for ArduSub install, but generally a good idea
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& echo "\n# Added by bluerov2_ignition Dockerfile:" >> /home/$USERNAME/.bashrc \
&& echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc

# Switch to our new user
USER $USERNAME
ENV USER=$USERNAME

# Clone ArduSub code
WORKDIR /home/$USERNAME
RUN git clone https://github.com/ArduPilot/ardupilot.git --recurse-submodules

# Install ArduSub prereqs (this also appends to .bashrc)
WORKDIR /home/$USERNAME/ardupilot
ENV SKIP_AP_EXT_ENV=1 SKIP_AP_GRAPHIC_ENV=1 SKIP_AP_COV_ENV=1 SKIP_AP_GIT_CHECK=1
RUN Tools/environment_install/install-prereqs-ubuntu.sh -y

# Build ArduSub
# Note: waf will capture all of the environment variables in ardupilot/.lock-waf_linux_build.
# Any change to enviroment variables will cause a re-build.
# To avoid this call sim_vehicle.py with the "--no-rebuild" option.
WORKDIR /home/$USERNAME/ardupilot
RUN modules/waf/waf-light configure --board sitl \
&& modules/waf/waf-light build --target bin/ardusub

# Clone ardupilot_gazebo code
WORKDIR /home/$USERNAME
RUN git clone https://github.com/ArduPilot/ardupilot_gazebo.git

# Build ardupilot_gazebo
RUN [ "/bin/bash" , "-c" , " \
cd ardupilot_gazebo \
&& mkdir build \
&& cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo \
&& make -j4" ]

# Copy bluerov2_ignition code
WORKDIR /home/$USERNAME/bluerov2_ignition
COPY --chown=$USER_UID:$USER_GID . .

# Set up the environment
WORKDIR /home/$USERNAME
RUN echo "export PATH=/home/$USERNAME/.local/bin:\$PATH" >> /home/$USERNAME/.bashrc \
&& echo "export PATH=/home/$USERNAME/.local/lib/python3.10/site-packages:\$PATH" >> /home/$USERNAME/.bashrc \
&& echo "export GZ_SIM_SYSTEM_PLUGIN_PATH=/home/$USERNAME/ardupilot_gazebo/build" >> /home/$USERNAME/.bashrc \
&& echo "export GZ_SIM_RESOURCE_PATH=/home/$USERNAME/bluerov2_ignition/models:/home/$USERNAME/bluerov2_ignition/worlds" >> /home/$USERNAME/.bashrc

# Required to use the --console option on sim_vehicle.py
# RUN pip3 install matplotlib
16 changes: 16 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
To build the docker image:
~~~
./build.sh
~~~

To run the demo, start the container in the 1st terminal, and start ArduSub:
~~~
./run.sh
sim_vehicle.py -L RATBeach -v ArduSub --model=JSON --out=udp:0.0.0.0:14550 --no-rebuild
~~~

In the 2nd terminal start Gazebo:
~~~
docker exec -it bluerov2_ignition /bin/bash
gz sim -v 3 -r underwater.world
~~~
7 changes: 7 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

cd $DIR

docker build -f $DIR/Dockerfile -t bluerov2_ignition:latest ..
33 changes: 33 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

XAUTH=/tmp/.docker.xauth
if [ ! -f $XAUTH ]
then
xauth_list=$(xauth nlist $DISPLAY)
xauth_list=$(sed -e 's/^..../ffff/' <<< "$xauth_list")
if [ ! -z "$xauth_list" ]
then
echo "$xauth_list" | xauth -f $XAUTH nmerge -
else
touch $XAUTH
fi
chmod a+r $XAUTH
fi

# Specific for NVIDIA drivers, required for OpenGL >= 3.3
docker run -it \
--rm \
--name bluerov2_ignition \
-e DISPLAY \
-e QT_X11_NO_MITSHM=1 \
-e XAUTHORITY=$XAUTH \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=all \
-v "$XAUTH:$XAUTH" \
-v "/tmp/.X11-unix:/tmp/.X11-unix" \
-v "/etc/localtime:/etc/localtime:ro" \
-v "/dev/input:/dev/input" \
--privileged \
--security-opt seccomp=unconfined \
--gpus all \
bluerov2_ignition:latest
Binary file added images/gazebo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 19b1be3

Please sign in to comment.