Skip to content

Commit

Permalink
Create setup script for single command full dev setup (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
texhnolyze authored May 16, 2024
2 parents 6c6a27a + 078b557 commit 094dac3
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 121 deletions.
70 changes: 35 additions & 35 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"name": "Bit-Bots Iron Dev",
"name": "Bit-Bots Iron Dev",

"build": { "dockerfile": "Dockerfile" },
"build": { "dockerfile": "Dockerfile" },

"containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}",
"LIBGL_ALWAYS_SOFTWARE": "1",
"QT_X11_NO_MITSHM": "1",
"DOCKER": "1"
},
"containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}",
"LIBGL_ALWAYS_SOFTWARE": "1",
"QT_X11_NO_MITSHM": "1",
"DOCKER": "1"
},

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": { "zsh": { "path": "/bin/zsh" } }
},
"extensions": [
"ms-iot.vscode-ros"
]
}
},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": { "zsh": { "path": "/bin/zsh" } }
},
"extensions": ["ms-iot.vscode-ros"]
}
},

"workspaceMount": "type=bind,source=${localWorkspaceFolder},target=/root/colcon_ws/src/bitbots_main",
"workspaceFolder": "/root/colcon_ws/src/bitbots_main",
"workspaceMount": "type=bind,source=${localWorkspaceFolder},target=/root/colcon_ws/src/bitbots_main",
"workspaceFolder": "/root/colcon_ws/src/bitbots_main",

"mounts": [
"type=bind,source=${localEnv:HOME},target=/srv/host_home,consistency=cached",
],
"mounts": [
"type=bind,source=${localEnv:HOME},target=/srv/host_home,consistency=cached"
],

"runArgs": [
"--tmpfs", "/tmp:exec,mode=01777",
"--privileged",
"--net=host",
"--device=/dev/dri:/dev/dri",
"--volume=/tmp/.X11-unix:/tmp/.X11-unix",
"--cap-add=SYS_PTRACE",
"--security-opt", "seccomp=unconfined"
],
"runArgs": [
"--tmpfs",
"/tmp:exec,mode=01777",
"--privileged",
"--net=host",
"--device=/dev/dri:/dev/dri",
"--volume=/tmp/.X11-unix:/tmp/.X11-unix",
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],

"postCreateCommand": "git config --global --add safe.directory '*'"
}
"postCreateCommand": "git config --global --add safe.directory '*'"
}
42 changes: 9 additions & 33 deletions .devcontainer/zshrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$HOME/.local/bin:$PATH

# Set the default shell to zsh when running zsh
export SHELL="$(which zsh)"

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh

Expand Down Expand Up @@ -49,8 +52,7 @@ bindkey "^[[1;5D" backward-word
# Settings for the prompt to show that we are in a docker container
export PROMPT="%K{black} 🐋 %K{blue}%F{black}%/ %f%k%F{blue}%f " # Prefix the prompt with DOCKER

# Do ros2 specific things
source /opt/ros/iron/setup.zsh &> /dev/null
# >>> bit-bots initialize >>>

# Ignore some deprecation warnings
export PYTHONWARNINGS=ignore:::setuptools.command.install,ignore:::setuptools.command.easy_install,ignore:::pkg_resources
Expand All @@ -72,38 +74,12 @@ export RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity}] [{name}]: {message}"
# Set the default Middleware
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp

# Create a function to update the argcomplete so tab completion works
# This needs to be called every time we source something ROS 2 related
function update_ros2_argcomplete() {
eval "$(register-python-argcomplete3 colcon)"
eval "$(register-python-argcomplete3 ros2)"
}

# Update the tab completion
update_ros2_argcomplete

alias rr='ros2 run'
alias rl='ros2 launch'

alias rte='ros2 topic echo'
alias rtl='ros2 topic list'
alias rth='ros2 topic hz'
alias rtp='ros2 topic pub'

alias rpl='ros2 param list'
alias rpg='ros2 param get'

alias cdc='cd $COLCON_WS'

alias cba='cdc && colcon build --symlink-install --continue-on-error'
alias cb='cdc && colcon build --symlink-install --continue-on-error --packages-up-to'
alias cbs='cdc && colcon build --symlink-install --packages-select'
alias cc='cdc && colcon clean packages --packages-select'
alias cca='cdc && colcon clean packages'
# Load our ros plugin script containing useful functions and aliases for ROS 2 development
if [[ -f $COLCON_WS/src/bitbots_main/scripts/ros.plugin.sh ]]; then
source $COLCON_WS/src/bitbots_main/scripts/ros.plugin.sh
fi

alias sr='source /opt/ros/iron/setup.zsh && update_ros2_argcomplete'
alias sc='source $COLCON_WS/install/setup.zsh && update_ros2_argcomplete'
alias sa='sr && sc'
# <<< bit-bots initialize <<<

# Set default editor
export VISUAL="vim"
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY : basler install install-no-root pip pre-commit install-git-filters format pull-all pull-init pull-repos pull-files fresh-libs remove-libs setup-libs rosdep status update update-no-root
.PHONY : basler webots install install-no-root pip pre-commit install-git-filters format pull-all pull-init pull-repos pull-files fresh-libs remove-libs setup-libs rosdep status update update-no-root

HTTPS := ""
REPO:=$(dir $(abspath $(firstword $(MAKEFILE_LIST))))
Expand All @@ -7,6 +7,10 @@ basler:
# Install Basler Pylon SDK
scripts/make_basler.sh $(ARGS)

webots:
# Install Webots Simulation environment
scripts/make_webots.sh $(ARGS)

install: pull-init basler update

install-no-root: pull-init update-no-root
Expand Down Expand Up @@ -77,6 +81,8 @@ else
endif

rosdep:
# Initialize rosdep if not already done
[ -f /etc/ros/rosdep/sources.list.d/20-default.list ] || sudo rosdep init
# Update rosdep and install dependencies from meta directory
rosdep update
rosdep install --from-paths . --ignore-src --rosdistro iron -y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,33 @@ Software installation with ROS2

In this tutorial, we will learn how to install ROS2 Iron Irwini on Ubuntu 22.04 and build our software stack.

**TLDR**: single command setup
------------------------------

**Prerequirements**
- You have a running Ubuntu 22.04 environment
- You have an existing Github account and added a SSH key to your account
- You have root access to your system (sudo)

If you have not previously set up any of our software stack, you can use the following command to install and setup everything in one go:

.. code-block:: bash
mkdir -p ~/git/bitbots \
&& cd ~/git/bitbots \
&& curl -fsSL https://raw.githubusercontent.com/bit-bots/bitbots_main/main/scripts/setup.sh > /tmp/setup.sh \
&& bash /tmp/setup.sh
Manual steps with in depth explanation
--------------------------------------

**0. Use Ubuntu 22.04**

As ROS works best on Ubuntu, we are using this distribution.
Currently, ROS2 Iron runs on Ubuntu 22.04.
If you are not already using Ubuntu 22.04, consider installing it on your system (perhaps as a dual boot), alternately you can run it in a virtual machine (not recommended, as recently we had some issues with it; https://www.virtualbox.org/) or use the ROS2 docker (https://github.com/timonegk/rosdocked)

If you are not already using Ubuntu 22.04, consider installing it on your system (perhaps as a dual boot?).
Alternatively you can use a devcontainer :doc:`vscode-dev-container`, with a preconfigured environment and follow those instructions, as these docs do not apply to the devcontainer.

**1. Setup and Install ROS 2**

Expand All @@ -17,29 +39,38 @@ If you are not already using Ubuntu 22.04, consider installing it on your system
.. code-block:: bash
sudo apt install \
clang-format \
cppcheck \
python3-colcon-clean \
python3-colcon-common-extensions \
python3-pip \
python3-rosdep \
python3-vcstool \
ros-iron-plotjuggler-ros \
ros-iron-rmw-cyclonedds-cpp \
ros-iron-rqt-robot-monitor \
ros-iron-rqt-runtime-monitor
clang-format \
cppcheck \
python3-colcon-clean \
python3-colcon-common-extensions \
python3-pip \
python3-rosdep \
python3-vcstool \
ros-iron-plotjuggler-ros \
ros-iron-rmw-cyclonedds-cpp \
ros-iron-rqt-robot-monitor \
ros-iron-rqt-runtime-monitor
- Run ``sudo rosdep init`` to initialize ``rosdep``, a tool that helps you install system dependencies for ROS packages.
- Optionally, to get nice colored output from colcon, you can install the following pip packages:

.. code-block:: bash
python3 -m pip install \
git+https://github.com/ruffsl/colcon-clean \
git+https://github.com/timonegk/colcon-core.git@colors \
git+https://github.com/timonegk/colcon-notification.git@colors \
git+https://github.com/timonegk/colcon-output.git@colors
**2. Install Webots**

- Navigate to https://github.com/cyberbotics/webots/releases and download the ``.deb`` file of **Webots2022b**.
- Install it using the command ``sudo apt install ~/Downloads/webots_2022b_amd64.deb`` or similar, depending on your system setup.
Webots is a robot simulator, which we use to simulate our robots and test our software.
It is not strictly necessary to install it, but it is very useful for development and testing.
If you want to install it, you can do so by running ``make webots`` in the bitbots_main repository.

**3. Download our software**

- Create a GitHub account, if not already done (see here for further information on this: http://doku.bit-bots.de/private/manual/dienste_accounts.html)
Those services host our Git software repositories.
- Create a GitHub account, if not already done (see `here <http://doku.bit-bots.de/private/manual/dienste_accounts.html>` for further information)
- Add your SSH key to GitHub to access and sync our repositories
- If you don't know what I am talking about or you don't yet have a SSH key, follow this guide: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys
- Go to your account settings and add your SSH key (the ``.pub`` file) to `GitHub <https://github.com/settings/keys>`_
Expand Down Expand Up @@ -74,48 +105,46 @@ In case you are not using the bash shell, replace ``~/.bashrc`` and ``bash`` wit
.. code-block:: bash
cat >> ~/.bashrc << EOF
export PATH=\$PATH:\$HOME/.local/bin
export COLCON_WS="\$HOME/colcon_ws"
export COLCON_LOG_LEVEL=30
export RCUTILS_COLORIZED_OUTPUT=1
export RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})"
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
source /opt/ros/iron/setup.bash
eval "\$(register-python-argcomplete3 ros2)"
eval "\$(register-python-argcomplete3 colcon)"
EOF
- Optionally, run the following command to set some useful shortcuts for various ROS2 commands:
# >>> bit-bots initialize >>>
.. code-block:: bash
# Ignore some deprecation warnings
export PYTHONWARNINGS=ignore:::setuptools.command.install,ignore:::setuptools.command.easy_install,ignore:::pkg_resources
cat >> ~/.bashrc << EOF
alias rr='ros2 run'
alias rl='ros2 launch'
# Limit ROS 2 communication to localhost (can be overridden when needed)
export ROS_DOMAIN_ID=24
export ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
# Set the default colcon workspace
export COLCON_WS="\$HOME/colcon_ws"
# Set the default log level for colcon
export COLCON_LOG_LEVEL=30
alias rte='ros2 topic echo'
alias rtl='ros2 topic list'
alias rth='ros2 topic hz'
alias rtp='ros2 topic pub'
# Define a log layout
export RCUTILS_COLORIZED_OUTPUT=1
export RCUTILS_CONSOLE_OUTPUT_FORMAT="[{severity}] [{name}]: {message}"
alias rpl='ros2 param list'
alias rpg='ros2 param get'
# Set the default Middleware
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
alias cdc='cd \$COLCON_WS'
# Load our ros plugin script containing useful functions and aliases for ROS 2 development
if [[ -f \$COLCON_WS/src/bitbots_main/scripts/ros.plugin.sh ]]; then
source \$COLCON_WS/src/bitbots_main/scripts/ros.plugin.sh
fi
alias cba='cdc && colcon build --symlink-install --continue-on-error'
alias cb='cdc && colcon build --symlink-install --continue-on-error --packages-up-to'
alias cbs='cdc && colcon build --symlink-install --packages-select'
alias cc='cdc && colcon clean packages --packages-select'
alias cca='cdc && colcon clean packages'
# <<< bit-bots initialize <<<
alias sr='source /opt/ros/iron/setup.bash'
alias sc='source \$COLCON_WS/install/setup.bash'
alias sa='sr && sc'
EOF
- Configure the robot hostnames, see :doc:`configure_hostnames`.
**6. Troubleshooting**
Notes
-----
Custom docker setup
Before utilizing a devcontainer, we used a custom docker setup for ROS 2 development.
If you want (or need) to utilize a custom setup like this, have a look at https://github.com/timonegk/rosdocked.
If you have some problems with your installation, like not finding any nodes or topics, referr here for some troubleshooting steps: https://docs.ros.org/en/rolling/How-To-Guides/Installation-Troubleshooting.html
Virtual Machine setup
We recommend against using a virtual machine for ROS 2 development, both for compile speed and setup complexity reasons.
8 changes: 4 additions & 4 deletions scripts/make_basler.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -eEo pipefail

# You need to fill out a form to download the pylon driver.
# The pylon driver can be found in the download section of the following link:
Expand All @@ -25,10 +26,9 @@ else
SHOW_PROGRESS="--show-progress"
fi

# Create function to check if we have an internet connection
function check_internet_connection () {
check_internet_connection () {
# Check if we have an internet connection, except in the ci as azure does not support ping by design
if [[ $1 != "--ci" ]] && ! ping -q -c 1 -W 1 google.com >/dev/null; then
if [[ $1 != "--ci" ]] && ! ping -q -c 1 -W 1 google.com > /dev/null; then
echo "No internet connection. Please check your internet connection to install the basler drivers."
exit 1
fi
Expand All @@ -40,7 +40,7 @@ if apt list pylon --installed | grep -q $PYLON_VERSION; then
else
echo "Pylon driver $PYLON_VERSION is not installed. Installing..."
# Check if we have an internet connection
check_internet_connection $1
check_internet_connection "$1"
# Check if the url exist
if ! curl --output /dev/null --silent --head --fail "$PYLON_DOWNLOAD_URL"; then
echo "Pylon download url does not exist. Please check the url and update the 'PYLON_DOWNLOAD_URL' variable in the 'make_basler.sh' script. The website might have changed."
Expand Down
30 changes: 30 additions & 0 deletions scripts/make_webots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -eEo pipefail

WEBOTS_VERSION="2022b"
WEBOTS_DOWNLOAD_URL="https://github.com/cyberbotics/webots/releases/download/R${WEBOTS_VERSION}/webots_${WEBOTS_VERSION}_amd64.deb"

check_internet_connection () {
if ! ping -q -c 1 -W 1 google.com > /dev/null; then
echo "No internet connection. Please check your internet connection to install the webots simulator."
exit 1
fi
}

# Check if the correct webots simulator WEBOTS_VERSION is installed (apt)
if apt list webots --installed | grep -q "$WEBOTS_VERSION"; then
echo "Webots simulator release $WEBOTS_VERSION is already installed."
else
echo "Webots simulator release $WEBOTS_VERSION is not installed. Installing..."
# Check if we have an internet connection
check_internet_connection
# Check if the url exist
if ! curl --output /dev/null --silent --head --fail "$WEBOTS_DOWNLOAD_URL"; then
echo "Webots download url does not exist. Please check the url and update the 'WEBOTS_DOWNLOAD_URL' variable in the 'make_webots.sh' script."
exit 1
fi
# Download the webots simulator dep package to temp folder
wget --no-verbose --show-progress "$WEBOTS_DOWNLOAD_URL" -O "/tmp/webots_${WEBOTS_VERSION}.deb"
# Install the webots simulator
sudo apt-get install "/tmp/webots_${WEBOTS_VERSION}.deb" -y
fi
Loading

0 comments on commit 094dac3

Please sign in to comment.