Development Environment Setup & Building the Workspace - Weber-State-UAV-Program/Documentation-2024-2025 GitHub Wiki

This page will go over how to set up the development environment for our ROS2 workspace. Setup includes installation of the PX4 Autopilot firmware, Installation of various packages. Downloading the codebase for the project, building it and running a simulation.

Pre-Requisites

Installing PX4 Autopilot

NOTE The version of PX4 Autopilot used for this project is V1.15.3. It is Very important that all development is done using the same version of PX4 that is intended to run on the flight hardware, otherwise unexpected behavior may occur. For the purposes of this documentation, everything related to PX4 is based on v1.15, documentation for this version of PX4 can be found here

Clone the PX4-Autopilot repository to your development machine, and navigate into the PX4-Autopilot directory.

git clone https://github.com/PX4/PX4-Autopilot.git --recursive
cd PX4-Autopilot

This will clone the latest release branch of PX4, checkout v1.15.3.

git checkout v1.15.3

Update submodules

make submodulesclean

Run the ubuntu.sh bash script to install everything.

bash ./Tools/setup/ubuntu.sh

IMPORTANT At this point you must reboot the computer to finish installation

PX4 should now be installed. Ensure that it can be built and the simulation started by running:

make px4_sitl

The process should complete without errors.

Installing Python Dependencies

The following python dependencies are required before you can run ROS2 with PX4, install them with

pip install --user -U empy==3.3.4 pyros-genmsg setuptools

Install the Micro XRCE-DDS Agent

The Micro XRCE-DDS Agent must also be installed on the development machine to facilitate communcation between PX4 and ROS2. On the drone this is done via UART, however within the development environment, since both the PX4 flight stack and the ROS2 network are running on the same machine, it is done over UDP port 8888.

Install the Agent with

git clone -b v2.4.2 https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
cd Micro-XRCE-DDS-Agent
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig /usr/local/lib/

Building the workspace

Clone the ARG-Drone project repository to the development machine, and navigate to the project directory.

git clone [email protected]:Weber-State-UAV-Program/ARG-Drone-2024-2025.git --recursive
cd ARG-Drone-2024-2025

INFO Ensure you have appropriate access rights to the Weber-State-UAV-Program organization and the ARG-Drone-2024-2025 project repository.

Initialize and update submodules

git submodule update --init --recursive

Before building the ROS2 packages, there is a slight bug that must be taken care of in the px4_ros2_cpp ROS2 package. In the version that is used by this project, there is an extra "+" sign in the home_position.hpp file. Once that is removed the package should build without error. This fix is only necessary any time the package submodules are updated or the workspace is freshly cloned.

The error is at line 30 in the file at px4-ros2-interface-lib/px4_ros2_cpp/include/px4_ros2/vehicle_state/home_position.hpp

build the ROS2 packages

colcon build

Ensure that all packages build without error. It may be necessary to build the px4_msgs px4_ros2_cpp and arg_interfaces packages first with

colcon build --packages-select px4_msgs px4_ros2_cpp arg_interfaces

Source the setup files before attempting to build the rest of the packages

source install/setup.bash

Simulation Setup

When in installing the PX4-Autopilot software, gazebo, and all modules necessary for simulation are installed as well. This can be verified by navigating to the PX4-Autopilot directory and running the following command.

make px4_sitl gz_x500

This should pull up gazebo, with PX4 running and connected to the simulation environment as indicated by the "ready for takeoff" message in the terminal

image image

If gazebo pulls up with the x500 multi-copter model, then the simulation environment is configured properly.

INFO More information on PX4 Software-In-The-Loop simulation can be found here

Models

It is now necessary to clone the models & world used for testing of the precision landing system into the gazebo environment.

Copy all of the model folders from the ARG-Drone project repository located at ARG-Drone-2024-2025/arg_workspace_2024/Simulation/models to the PX4/Gazebo simulation models folder located at PX4-Autopilot/Tools/simulation/gz/models

Copy all of the worlds from the ARG-Drone project repsitory located at ARG-Drone-2024-2025/arg_workspace_2024/Simulation/worlds to the PX4/Gazebo simulation worlds folder located at PX4-Autopilot/Tools/simulation/gz/worlds

List of Models

Model Description
apriltag-0 A model of an April Tag with ID 0. Used in the base station model
apriltag-1 A model of the left side base station door with an April Tag of ID 1. Used in the base station model
apriltag-2 A model of the right side base station door with an April Tag of ID 2. Used in the base station model
basestation A model of the base station with three total AprilTags
rangefinder A model of a single beam lidar rangefinder
vinyl_target A model of our vinyl landing target with four AprilTags of varying sizes
x500_mono_cam_down_lidar A model of the x500 drone with a downward facing camera and downward facing lidar rangefinder

List of Models

World Description
apriltag Simple flat world with the basestation model
apriltag_simple Simple flat world with the vinyl landing target model

Once the models have been added to the simulation environment, we must add the sim target to PX4.

Add a file called 4016_gz_x500_mono_cam_down_lidar to the list of airframes in the folder PX4-Autopilot/build/px4_sitl_default/etc/init.d-posix/airframes

Add the following content

#!/bin/sh
#
# @name Gazebo x500 mono cam
#
# @type Quadrotor
#

PX4_SIM_MODEL=${PX4_SIM_MODEL:=x500_mono_cam_down_lidar}

. ${R}etc/init.d-posix/airframes/4001_gz_x500

Note Ensure the px4_sitl has been built with make px4_sitl prior to performing this step

Run the Launch File

Navigate to the 2024 ARG-Drone ROS2 workspace at ARG-Drone-2024-2025/arg_workspace_2024

build and source

colcon build
source install/setup.bash

Launch the simulation

ros2 launch arg_drone.launch.py

This will launch the Micro XRCE-DDS Agent, the simulation with the vinyl landing target, rqt_image_view for the image viewer, and all ROS2 nodes necessary to control the drone.

You will then need to start QGroundControl and plan a mission from there. If running on the same machine it should connect automatically. The custom mission with precision landing mode should be listed as an available mode within there.

Instructions on using QGroundControl to plan an execute a mission with precision landing can be found here