Skip to content

Pr space cobot #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions Dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
FROM nvidia/opengl:1.2-glvnd-runtime-ubuntu22.04

## Arguments for selection of the PX4 software repository and their respective branch, this makes it easier to switch without needing to change the Dockerfile
ARG PX4_SOFTWARE_REPO=https://github.com/DISCOWER/PX4-Space-Systems.git
ARG PX4_SOFTWARE_BRANCH=master

ENV user=px4space
ENV home=/home/$user
ENV ROS_DISTRO=humble

WORKDIR $home

RUN apt-get update -y && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y \
bash \
sudo \
wget \
curl \
tzdata \
python3-pip \
lsb-release \
gnupg \
git \
mesa-utils \
libgl1-mesa-dri \
libegl1-mesa \
libgles2-mesa \
libglx-mesa0 \
libglx0 \
nvidia-utils-460 \
libnvidia-gl-470 && \
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
dpkg-reconfigure --frontend noninteractive tzdata

## Create non root user and give it sudo permissions
RUN useradd -m -s /bin/bash px4space \
&& usermod -aG sudo px4space \
&& echo 'px4space ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& chown -R px4space:px4space $home

## Switch to non root user
## Install ROS2
RUN sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \
&& sudo 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" | tee /etc/apt/sources.list.d/ros2.list > /dev/null \
&& sudo apt-get update -y \
&& sudo apt-get upgrade -y \
&& sudo apt-get install -y ros-humble-desktop python3-rosdep


RUN echo "source /opt/ros/humble/setup.bash" >> $home/.bashrc
RUN ["/bin/bash", "-c", "source $home/.bashrc"]

## Install Gazebo
RUN pip3 install vcstool \
&& pip3 install -U colcon-common-extensions \
&& pip3 show vcstool | grep Location \
&& pip3 show colcon-common-extensions | grep Location \
&& sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros2-latest.list' \
&& curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - \
&& sudo apt-get update -y \
&& sudo apt-get install -y python3-vcstool python3-colcon-common-extensions \
&& mkdir -p $home/Gazebo/src \
&& cd $home/Gazebo/src \
&& curl -O https://raw.githubusercontent.com/gazebo-tooling/gazebodistro/master/collection-garden.yaml \
&& sed -i "s|gz-sim7|pr-spacecraft-thrusters|" collection-garden.yaml \
&& sed -i 's|https://github.com/gazebosim/gz-sim|https://github.com/DISCOWER/gz-sim.git|' collection-garden.yaml \
&& vcs import < collection-garden.yaml \
&& 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" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null \
&& sudo apt-get update \
&& sudo apt-get install -y \
$(sort -u $(find . -iname 'packages-'$(lsb_release -cs)'.apt' -o -iname 'packages.apt' | grep -v '/\.git/') | sed '/gz\|sdf/d' | tr '\n' ' ') && \
cd $home/Gazebo && \
colcon build --merge-install && \
echo "source $home/Gazebo/install/setup.bash" >> $home/.bashrc


## Install micro-ROS
RUN rosdep fix-permissions && rosdep init && rosdep update && \
apt-get install -y ros-${ROS_DISTRO}-ament-cmake && \
apt-get install -y python3-colcon-common-extensions && \
mkdir -p $home/microros_ws/ && cd $home/microros_ws/ && \
git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup && \
rosdep update && \
rosdep install --from-paths src --ignore-src -y && \
. /opt/ros/$ROS_DISTRO/setup.sh && \
colcon build && \
. install/setup.sh && \
ros2 run micro_ros_setup create_firmware_ws.sh host && \
ros2 run micro_ros_setup build_firmware.sh && \
. install/setup.sh && \
ros2 run micro_ros_setup create_agent_ws.sh && \
ros2 run micro_ros_setup build_agent.sh && \
. install/local_setup.sh && \
echo "source $home/microros_ws/install/local_setup.bash" >> $home/.bashrc


RUN pip install aqtinstall
ENV PATH="$home/.local/bin:$PATH"
# Install qt version 6.6.3
RUN aqt install-qt --outputdir $home/qt linux desktop 6.6.3 gcc_64 -m qtcharts qtconnectivity qtlocation qtmultimedia qtpositioning qtsensors qtserialport qtspeech qtshadertools qt5compat qtquick3d

ENV PATH=$home/qt/6.6.3/gcc_64/bin:$PATH
ENV LD_LIBRARY_PATH=$home/qt/6.6.3/gcc_64/lib:$LD_LIBRARY_PATH
ENV QT_PLUGIN_PATH=$home/qt/6.6.3/gcc_64/lib/pkgconfig:$PKG_CONFIG_PATH

USER px4space

RUN sudo chown -R px4space:px4space $home
ENV PATH=$home/.local/bin:$PATH
RUN mkdir -p $home/QGroundControl && \
cd $home/QGroundControl && \
git clone --recursive --depth=1 https://github.com/DISCOWER/qgroundcontrol.git && \
sudo bash ./qgroundcontrol/tools/setup/install-dependencies-debian.sh && \
cd qgroundcontrol && \
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug && \
cmake --build build --config Debug && \
pwd && \
cp ./build/QGroundControl $home/QGroundControlApp

### PX4 messages compile
RUN mkdir -p $home/PX4/ros2_ws/src && \
cd $home/PX4/ros2_ws/src && \
git clone --recursive --depth=1 https://github.com/PX4/px4_msgs.git && \
cd $home/PX4/ros2_ws && \
. /opt/ros/humble/setup.sh && colcon build --symlink-install && \
echo "source $home/PX4/ros2_ws/install/setup.bash" >> $home/.bashrc

WORKDIR $home

### PX4 simulation software compile
RUN mkdir -p $home/PX4 && \
cd $home/PX4 && \
git clone --recursive ${PX4_SOFTWARE_REPO} -b ${PX4_SOFTWARE_BRANCH} && \
sudo ./PX4-Space-Systems/Tools/setup/ubuntu.sh -y && \
pip3 install -r PX4-Space-Systems/Tools/setup/requirements.txt && \
pip3 install --user symforce && \
cd PX4-Space-Systems && \
make px4_sitl

## Set runtime directory environment variable
ENV XDG_RUNTIME_DIR=/tmp/runtime-root
42 changes: 42 additions & 0 deletions Dockerfiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# PX4 Space System docker container

## Overview
This docker file is used as a way to containerize the simulation environment of PX4 space systems. The simulation run in Ubuntu 22.04 container and uses the new gazebo garden as a simulation engine.

If it is intended to use with ROS (inside the container) you should use ROS2 humble.

## Software packed inside

Inside the container you have packed Gazebo Garden, ros2 humble, micro ros agent, px4 msgs, qt versioon 6.6.3 and QGroundControl (with custom plugin for gzç-sim7).

## Compiling

Compiling the docker is rather simple you must ensure that you have [docker installed](https://docs.docker.com/engine/install/), after this simply build the container, as you can see in the command bellow you can specify the link and the branch for the PX4 git, this allow for more modularity when using in fork of the main work. **Be aware that when changing the branch or link you will need to compile the full container, and this is a lengthy process**

```
docker build -t px4 --build-arg PX4_SOFTWARE_REPO=https://github.com/SpaceBotsISR/PX4-Space-Systems.git --build-arg PX4_SOFTWARE_BRANCH=pr-space_cobot .
```

In the computer where this was developed the build process toke around 20 minutes, and needed 16GB of RAM and 16GB of swap space and during the gazebo compilation process the full 16 cores were occupied with build the docker.

After compiling you now need to create the container, this can e done with
```
docker run -it --gpus all \\n --network=host --ipc=host \\n -e DISPLAY=$DISPLAY \\n -e NVIDIA_VISIBLE_DEVICES=all \\n -e NVIDIA_DRIVER_CAPABILITIES=all \\n -e QT_X11_NO_MITSHM=1 \\n -v /tmp/.X11-unix:/tmp/.X11-unix:rw \\n -v /dev/dri:/dev/dri \\n -e XDG_RUNTIME_DIR=/tmp/runtime-root \\n --runtime=nvidia \\n -v /home/andret/ISR:/home/px4space/ISR \\n --name px4_cont px4
```

Most of the flags are used are to pass a gpu to docker and e able to use it for running the gazebo simulation, if you dont have a gpu, or is not a nvidia gpu i recomend removing the flags, since the base container is from nvidia in this docker. An extra folder is also passed to the docker, remove this if you dont want to have the need to it.

## Using the container

The current test done to the simulation enviomnent envolve
- Gazebo and QGroundControl running inside the docker container
- Gazebo, QGroundControl and ros2 nodes running inside the docker
- Gazebo, micro-ros and ros2 nodes inside this docker, with QGroundControl in the host machine and more ros2 node in an external container

When you open the docker this is the result of the ls command
```
Documents ISR QGroundControl aqtinstall.log qt
Gazebo PX4 QGroundControlApp microros_ws ros2_ws
```

The QGroundControlApp is the execulable, and the simulation toll are accesible through PX4/PX4-Space-Systems
126 changes: 126 additions & 0 deletions ROMFS/px4fmu_common/init.d-posix/airframes/71003_gz_space_cobot
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/sh
#
# @name 3DoF Spacecraft Model
#
# @type 2D Freeflyer with 8 thrusters - Planar motion
#
# @maintainer André Teixeira <[email protected]>
#

. ${R}etc/init.d/rc.sc_defaults

PX4_SIMULATOR=${PX4_SIMULATOR:=gz}
PX4_GZ_WORLD=${PX4_GZ_WORLD:=default}
PX4_SIM_MODEL=${PX4_SIM_MODEL:=spacecraft_2d}

param set-default SIM_GZ_EN 1

param set-default SENS_EN_GPSSIM 1
param set-default SENS_EN_BAROSIM 1
param set-default SENS_EN_MAGSIM 1

param set-default CA_AIRFRAME 0
param set-default MAV_TYPE 99

param set-default CA_ROTOR_COUNT 6
param set-default CA_R_REV 255

# param set-default FW_ARSP_MODE 1

# Auto to be provided by Custom Airframe
param set-default CA_METHOD 0

param set-default SIM_GZ_EC_FUNC1 101
param set-default SIM_GZ_EC_FUNC2 102
param set-default SIM_GZ_EC_FUNC3 103
param set-default SIM_GZ_EC_FUNC4 104
param set-default SIM_GZ_EC_FUNC5 105
param set-default SIM_GZ_EC_FUNC6 106

param set-default SIM_GZ_EC_MIN1 0
param set-default SIM_GZ_EC_MIN2 0
param set-default SIM_GZ_EC_MIN3 0
param set-default SIM_GZ_EC_MIN4 0
param set-default SIM_GZ_EC_MIN5 0
param set-default SIM_GZ_EC_MIN6 0

param set-default SIM_GZ_EC_MAX1 1100
param set-default SIM_GZ_EC_MAX2 1100
param set-default SIM_GZ_EC_MAX3 1100
param set-default SIM_GZ_EC_MAX4 1100
param set-default SIM_GZ_EC_MAX5 1100
param set-default SIM_GZ_EC_MAX6 1100


# Propellers positions
param set-default CA_ROTOR0_PX 0.0
param set-default CA_ROTOR0_PY -0.1655
param set-default CA_ROTOR0_PZ 0.0
param set-default CA_ROTOR0_KM -0.05
param set-default CA_ROTOR0_AX -0.818042890710956
param set-default CA_ROTOR0_AY 0.0
param set-default CA_ROTOR0_AZ 0.5751572210772138


param set-default CA_ROTOR1_PX 0.0
param set-default CA_ROTOR1_PY 0.1655
param set-default CA_ROTOR1_PZ 0.0
param set-default CA_ROTOR1_KM 0.05
param set-default CA_ROTOR1_AX 0.8191299982695545
param set-default CA_ROTOR1_AY 0.0
param set-default CA_ROTOR1_AZ -0.5736079200420091


param set-default CA_ROTOR2_PX 0.1433
param set-default CA_ROTOR2_PY -0.0827
param set-default CA_ROTOR2_PZ 0.0
param set-default CA_ROTOR2_KM 0.05
param set-default CA_ROTOR2_AX -0.4095653689428518
param set-default CA_ROTOR2_AY 0.709392039827003
param set-default CA_ROTOR2_AZ 0.5736019023615504


param set-default CA_ROTOR3_PX -0.1433
param set-default CA_ROTOR3_PY 0.0827
param set-default CA_ROTOR3_PZ 0.0
param set-default CA_ROTOR3_KM -0.05
param set-default CA_ROTOR3_AX -0.40957058041672156
param set-default CA_ROTOR3_AY 0.7093890309726535
param set-default CA_ROTOR3_AZ 0.5736019023615503


param set-default CA_ROTOR4_PX 0.1433
param set-default CA_ROTOR4_PY 0.0827
param set-default CA_ROTOR4_PZ 0.0
param set-default CA_ROTOR4_KM -0.05
param set-default CA_ROTOR4_AX -0.40957058041672156
param set-default CA_ROTOR4_AY -0.7093890309726535
param set-default CA_ROTOR4_AZ 0.5736019023615503


param set-default CA_ROTOR5_PX -0.1433
param set-default CA_ROTOR5_PY -0.0827
param set-default CA_ROTOR5_PZ 0.0
param set-default CA_ROTOR5_KM 0.05
param set-default CA_ROTOR5_AX -0.409707239158564
param set-default CA_ROTOR5_AY -0.7093101125659198
param set-default CA_ROTOR5_AZ 0.5736019023615504






# Controller Tunings
param set SC_YAWRATE_P 3.335
param set SC_YAWRATE_I 0.87
param set SC_YAWRATE_D 0.15
param set SC_YR_INT_LIM 0.2
param set SC_YAW_P 3.0

param set SPC_POS_P 0.20
param set SPC_VEL_P 6.55
param set SPC_VEL_I 0.0
param set SPC_VEL_D 0.0
param set SPC_VEL_MAX 12.0

1 change: 1 addition & 0 deletions ROMFS/px4fmu_common/init.d-posix/airframes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ px4_add_romfs_files(
71000_gazebo-classic_2d_spacecraft
71001_gazebo-classic_spacecraft_dart
71002_gz_spacecraft_2d
71003_gz_space_cobot

# [22000, 22999] Reserve for custom models
)
Loading