Skip to content

Commit

Permalink
ros2-crazyswarm initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-bender committed Nov 23, 2024
1 parent 796f21c commit d0ea3e9
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 0 deletions.
130 changes: 130 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
ARG ROS_DISTRO=humble
FROM osrf/ros:${ROS_DISTRO}-desktop

# Avoid prompts from apt
ENV DEBIAN_FRONTEND=noninteractive

# Declare an ARG for setting RUN_MODE at build time (optional)
ARG RUN_MODE=cli

# Set an ENV variable based on the ARG (to make it available at runtime)
ENV RUN_MODE=${RUN_MODE}

# Ignore setup.py warnings in building phase
ENV PYTHONWARNINGS="ignore:setup.py install is deprecated::setuptools.command.install"

# Install required apps
RUN apt-get update \
&& apt-get install -y \
nano \
git \
python3-pip \
&& rm -rf /var/lib/apt/list/*

# Install gazebo dependencies
RUN apt-get update \
&& apt-get install -y \
curl \
lsb-release \
gnupg \
python3-colcon-common-extensions \
&& rm -rf /var/lib/apt/list/*

# Set up colcon_cd for future bash sessions
RUN echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
RUN echo "export _colcon_cd_root=/opt/ros/humble/" >> ~/.bashrc
RUN echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc

# Add Gazebo repository
RUN curl https://packages.osrfoundation.org/gazebo.gpg --output /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg \
&& 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" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null

# Set up the gazebo version
ARG GZ_VERSION=fortress

# Install Gazebo
RUN apt-get update \
&& apt-get install -y \
gz-${GZ_VERSION} \
ros-${ROS_DISTRO}-ros-gz-sim \
ros-${ROS_DISTRO}-ros-gz-bridge \
&& rm -rf /var/lib/apt/lists/*

# Set up the environment
ENV GZ_RESOURCE_PATH=/usr/share/gazebo-${GZ_VERSION}

# Install crazyswarm2 dependencies
RUN apt-get update \
&& apt-get install -y \
libboost-program-options-dev \
libusb-1.0-0-dev \
ros-${ROS_DISTRO}-motion-capture-tracking \
ros-${ROS_DISTRO}-tf-transformations \
ros-${ROS_DISTRO}-teleop-twist-keyboard \
&& rm -rf /var/lib/apt/lists/*

# Install Python packages dependencies
RUN pip3 install rowan nicegui
RUN pip3 install cflib transform3D

# Set the working directory inside the container
WORKDIR /home

# Create the necessary workspace
RUN mkdir -p ros2_ws/src

# Set the workingspace inside the container
WORKDIR /home/ros2_ws

# Clone the repositorys into ros2 workspace
RUN git clone https://github.com/IMRCLab/crazyswarm2 --recursive

# Set the working directory inside the container
# WORKDIR /home/ros2_ws/src

# Change permissions
RUN sudo chmod 777 -R /home/ros2_ws

# Set working directory to ros2_ws and build using colcon
WORKDIR /home/ros2_ws

# Build
RUN . /opt/ros/${ROS_DISTRO}/setup.sh \
&& colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release

# Source ROS 2 workspace setup
RUN echo "source /home/ros2_ws/install/setup.bash" >> ~/.bashrc

# Set the working directory inside the container
WORKDIR /home

# Clone the repositorys for the SITL simulation
RUN git clone --recursive https://github.com/bitcraze/crazyflie-firmware.git

# Build python bindings & dependencies
WORKDIR /home/crazyflie-firmware

RUN apt-get update \
&& apt-get install -y \
swig \
&& rm -rf /var/lib/apt/lists/*

RUN make cf2_defconfig \
&& make bindings_python \
&& cd build \
&& python3 setup.py install --user

# Set PYTHONPATH environment variable
ENV PYTHONPATH=${PYTHONPATH:-}/home/crazyflie-firmware/build:$PYTHONPATH

# Set working directory to ros2_ws
WORKDIR /home/ros2_ws

# Entrypoint
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

# Interactive bash shell
CMD ["/bin/bash"]
# CMD ["sleep", "infinity"]
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
ros2-crazyswarm:
build: .
container_name: ros2-crazyswarm-container
network_mode: "host"
ipc: host
volumes:
- "/tmp/.X11-unix:/tmp/.X11-unix:rw"
environment:
- DISPLAY=$DISPLAY
- RUN_MODE=compose
tty: true
stdin_open: true
17 changes: 17 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

# Setup the Demo environment
cd /home/ros2_ws/
source /opt/ros/humble/setup.bash

# Check if the environment variable RUN_MODE is set to "compose"
if [ "$RUN_MODE" = "compose" ]; then
# Run sleep infinity if it's Docker Compose
exec sleep infinity
else
# Otherwise, run /bin/bash for CLI usage
exec /bin/bash
fi

exec "$@"
38 changes: 38 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ROS 2 Crazyswarm docker

This is an image that I generated using installation guide in [Crazyswarm official page](https://crazyswarm.readthedocs.io/en/latest/).


## Using CLI
To build the image, you need to type:
```$
docker build --no-cache -t ros2-crazyswarm .
```

To run the container, you need to type:
```$
docker run -it --rm --network=host --ipc=host -v /tmp/.X11-unix:/tmp/.X11-unix:rw --env=DISPLAY --name ros2-crazyswarm swarm -container ros2-crazyswarm
```

## Using docker compose
To start the docker compose, you need to type:
```$
docker compose up -d
```
To get access in the container, you need to type:
```$
docker exec -it ros2-crazyswarm -container /bin/bash
```
To stop the docker compose, you need to type:
```$
docker compose down
```

## Levevl of readiness
Not tested exhaustively. Use it on your own risk. If you discover issues, please report them.

## Environment (or it works in my machine)
It was testes in an Ubuntu 24.04.1 LTS machine

### Author (to blame)
Angelos Plastropoulos

0 comments on commit d0ea3e9

Please sign in to comment.