Skip to content

Instantly share code, notes, and snippets.

@hslyu
Last active May 14, 2020 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hslyu/89ea56c2bebf981f6dcf1f8445dc8416 to your computer and use it in GitHub Desktop.
Save hslyu/89ea56c2bebf981f6dcf1f8445dc8416 to your computer and use it in GitHub Desktop.

This document covers building a drone simulation envrionment which utilizes PX4. The simulation testbed consists of gazebo, PX4 firmware, and ROS melodic. It reffered to this installation guide and includes includes and integration of each software, and troubleshooting of errors in the building process. This document is tested on nvidia/cuda:10.0-devel-ubuntu18.04 docker image. You can download my image.

Prerequisite

  1. Your host OS should be Ubuntu 18.04. Otherwise, this intruction will malfunction.
  2. You should run your container with the environment variable LC_ALL. This locale setting is for the px4 firmware compiling.
docker run [your option] -e LC_ALL=en_US.UTF-8 hslyu/drone:cuda10.0-devel-ubuntu18.04

Before following this document, your host system must have docker and nvidia-docker installed. Follow the instructions to install docker and nvidia-docker.

Execute the following script on your terminal.

echo "Downloading dependent script 'ubuntu_sim_common_deps.sh'"
# Source the ubuntu_sim_common_deps.sh script directly from github
common_deps=$(wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_common_deps.sh -O -)
wget_return_code=$?
# If there was an error downloading the dependent script, we must warn the user and exit at this point.
if [[ $wget_return_code -ne 0 ]]; then echo "Error downloading 'ubuntu_sim_common_deps.sh'. Sorry but I cannot proceed further :("; exit 1; fi
# Otherwise source the downloaded script.
. <(echo "${common_deps}")
sudo apt-get install protobuf-compiler libeigen3-dev libopencv-dev -y

Install ROS Melodic

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
sudo apt update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep

Now you have ROS melodic and Gazebo9 in your container.
Let's install MAVROS package in your ROS workspace

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin init
wstool init src 

# We use the Kinetic reference for all ROS distros as it's not distro-specific and up to date
rosinstall_generator --rosdistro kinetic mavlink | tee /tmp/mavros.rosinstall

# Get source (upstream - released)
rosinstall_generator --upstream mavros | tee -a /tmp/mavros.rosinstall

# Setup workspace & install deps
wstool merge -t src /tmp/mavros.rosinstall
wstool update -t src
rosdep install --from-paths src --ignore-src --rosdistro melodic -y --os ubuntu:bionic

Install some geographic packages

#Install geographiclib
sudo apt install geographiclib -y
echo "Downloading dependent script 'install_geographiclib_datasets.sh'"
# Source the install_geographiclib_datasets.sh script directly from github
install_geo=$(wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh -O -)
wget_return_code=$?
# If there was an error downloading the dependent script, we must warn the user and exit at this point.
if [[ $wget_return_code -ne 0 ]]; then echo "Error downloading 'install_geographiclib_datasets.sh'. Sorry but I cannot proceed further :("; exit 1; fi
# Otherwise source the downloaded script.
sudo bash -c "$install_geo"

Finally, build the catkin workspace.

catkin build
souce ~/catkin_ws/devel/setup.bash

Build firmware

Clone the firmware.

git clone https://github.com/px4/Firmware.git
cd Firmware
make px4_sitl gazebo

Now, all installation finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment