Skip to content

Commit

Permalink
Add launch option for gzclient
Browse files Browse the repository at this point in the history
  • Loading branch information
Georg Novotny committed Dec 29, 2023
1 parent b7d7fde commit 460acc4
Show file tree
Hide file tree
Showing 23 changed files with 495 additions and 30 deletions.
39 changes: 39 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"image": "georgno/fhtw-ros:iron-desktop-ros_terminal-standard",
"remoteUser": "fhtw_user",
"initializeCommand": "xhost +",
"onCreateCommand": "sudo bash /entrypoint.sh &",
"workspaceMount": "source=${localWorkspaceFolder},target=/home/fhtw_user/sim_ws/src/sjtu_drone,type=bind,consistency=cached",
"workspaceFolder": "/home/fhtw_user/sim_ws",
// mount Jupyter/src/ros2 to ~/ros2_ws/src
"runArgs": [
"--shm-size=512m",
"--privileged",
"--gpus=all",
"--volume=/tmp/.X11-unix:/tmp/.X11-unix"
],
"containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}",
// "LIBGL_ALWAYS_SOFTWARE": "1" // Needed for software rendering of opengl
},
// Set *default* container specific settings.json values on container create.
"customizations": {
"vscode": {
"extensions": [
"althack.ament-task-provider",
"DotJoshJohnson.xml",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-vscode.cpptools",
"redhat.vscode-yaml",
"smilerobotics.urdf",
"twxs.cmake",
"yzhang.markdown-all-in-one",
"zachflower.uncrustify",
"ms-iot.vscode-ros",
"ms-vscode.cpptools-extension-pack"
]
}
}
}
19 changes: 15 additions & 4 deletions .github/workflows/CI_CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
strategy:
matrix:
include:
# - os: ubuntu-20.04
# ros_distribution: "galactic"
- os: ubuntu-22.04
ros_distribution: "humble"
- os: ubuntu-22.04
ros_distribution: "iron"
- os: ubuntu-22.04
ros_distribution: "rolling"
fail-fast: false
Expand Down Expand Up @@ -67,7 +67,17 @@ jobs:
if: always()

deploy:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
ros_distribution: "humble"
- os: ubuntu-22.04
ros_distribution: "iron"
- os: ubuntu-22.04
ros_distribution: "rolling"
fail-fast: false
needs: build
if: needs.build.outputs.build_step_outcome == 'success'
steps:
Expand All @@ -90,4 +100,5 @@ jobs:
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/sjtu_drone:ros2
tags: ${{ secrets.DOCKERHUB_USERNAME }}/sjtu_drone:ros2-${{ matrix.ros_distribution }}
args: --build-arg ROS_DISTRO=${{ matrix.ros_distribution}}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
plugins/
bin/

__pycache__/
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM ros:humble-ros-core-jammy
ARG ROS_DISTRO
FROM ros:${ROS_DISTRO}-ros-core-jammy

RUN apt-get update \
&& apt-get install -y \
Expand All @@ -14,23 +15,24 @@ RUN echo "deb http://packages.osrfoundation.org/gazebo/ubuntu `lsb_release -cs`
&& apt-get update \
&& apt-get install -y \
gazebo \
ros-humble-gazebo-ros-pkgs \
ros-${ROS_DISTRO}-gazebo-ros-pkgs \
python3-colcon-common-extensions python3-rosdep --no-install-recommends \
&& apt-get clean
RUN rosdep init && rosdep update

RUN mkdir -p /ros2_ws/src
COPY ./sjtu_drone_description /ros2_ws/src/sjtu_drone_description
COPY ./sjtu_drone_bringup /ros2_ws/src/sjtu_drone_bringup
COPY ./sjtu_drone_control /ros2_ws/src/sjtu_drone_control

RUN curl -L https://github.com/osrf/gazebo_models/archive/refs/heads/master.zip -o /tmp/gazebo_models.zip \
&& unzip /tmp/gazebo_models.zip -d /tmp && mkdir -p ~/.gazebo/models/ && mv /tmp/gazebo_models-master/* ~/.gazebo/models/ \
&& rm -r /tmp/gazebo_models.zip

WORKDIR /ros2_ws
RUN /bin/bash -c 'cd /ros2_ws/ \
&& source /opt/ros/humble/setup.bash \
&& source /opt/ros/${ROS_DISTRO}/setup.bash \
&& rosdep install --from-paths src --ignore-src -r -y \
&& colcon build'

CMD ["/bin/bash", "-c", "source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && ros2 launch sjtu_drone_bringup sjtu_drone_bringup.launch.py"]
CMD ["/bin/bash", "-c", "source /opt/ros/${ROS_DISTRO}/setup.bash && source /ros2_ws/install/setup.bash && ros2 launch sjtu_drone_bringup sjtu_drone_bringup.launch.py"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# sjtu_drone

[![Humble](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/NovoG93/589e4b4dc8d92861e4b92defff6d56c0/raw/_humble_build.json)](https://github.com/NovoG93/sjtu_drone/actions/workflows/build.yml) [![Rolling](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/NovoG93/589e4b4dc8d92861e4b92defff6d56c0/raw/_rolling_build.json)](https://github.com/NovoG93/sjtu_drone/actions/workflows/build.yml)
[![Iron](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/NovoG93/589e4b4dc8d92861e4b92defff6d56c0/raw/_iron_build.json)](https://github.com/NovoG93/sjtu_drone/actions/workflows/build.yml) [![Humble](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/NovoG93/589e4b4dc8d92861e4b92defff6d56c0/raw/_humble_build.json)](https://github.com/NovoG93/sjtu_drone/actions/workflows/build.yml) [![Rolling](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/NovoG93/589e4b4dc8d92861e4b92defff6d56c0/raw/_rolling_build.json)](https://github.com/NovoG93/sjtu_drone/actions/workflows/build.yml)

sjtu_drone is a quadrotor simulation program forked from [tum_simulator](http://wiki.ros.org/tum_simulator), developed using ROS + Gazebo.

The acronym 'sjtu' stands for Shanghai Jiao Tong University. This package has been used in the past for testing algorithms for the [UAV contest at SJTU](http://mediasoc.sjtu.edu.cn/wordpress)

# Requirements

This package is tested with ROS 2 Humble version (Ubuntu 22.04) and Gazebo 11.
This package is tested with ROS 2 (Ubuntu 22.04) and Gazebo 11.

# Downloading and building

Expand Down
29 changes: 26 additions & 3 deletions run_docker.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
#!/bin/bash

usage(){
echo "Usage: $0 [-r <humble|iron|rolling>]"
exit 1
}

ROS_DISTRO=${ROS_DISTRO:-"iron"} # [humble, iron, rolling]
while getopts "r:" opt; do
case $opt in
r)
if [ $OPTARG != "humble" ] && [ $OPTARG != "iron" ] && [ $OPTARG != "rolling" ]; then
echo "Invalid ROS distro: $OPTARG" >&2
usage
fi
ROS_DISTRO=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done

XSOCK=/tmp/.X11-unix
XAUTH=$HOME/.Xauthority

# docker build -t georgno/sjtu_drone:$(git rev-parse --abbrev-ref HEAD) .
docker pull georgno/sjtu_drone:$(git rev-parse --abbrev-ref HEAD)
# docker build -t georgno/sjtu_drone:${ROS_DISTRO} .
docker pull georgno/sjtu_drone:${ROS_DISTRO}

if [ $? -ne 0 ]; then
exit 1
Expand All @@ -22,5 +45,5 @@ docker run \
--privileged \
--net=host \
--name="sjtu_drone" \
georgno/sjtu_drone:$(git rev-parse --abbrev-ref HEAD)
georgno/sjtu_drone:${ROS_DISTRO}
xhost -local:docker
19 changes: 15 additions & 4 deletions sjtu_drone_bringup/launch/sjtu_drone_bringup.launch.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
#!/usr/bin/env python3
# Copyright 2023 Georg Novotny
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.launch_description_sources import PythonLaunchDescriptionSource


def generate_launch_description():

use_sim_time = LaunchConfiguration("use_sim_time", default="false")
sjtu_drone_bringup_path = get_package_share_directory('sjtu_drone_bringup')

rviz_path = os.path.join(
Expand All @@ -37,8 +48,8 @@ def generate_launch_description():
),

Node(
package="teleop_twist_keyboard",
executable="teleop_twist_keyboard",
package="sjtu_drone_control",
executable="teleop",
namespace="drone",
output="screen",
prefix="xterm -e"
Expand Down
38 changes: 29 additions & 9 deletions sjtu_drone_bringup/launch/sjtu_drone_gazebo.launch.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
#!/usr/bin/env python3
# Copyright 2023 Georg Novotny
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, OpaqueFunction
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.launch_description_sources import PythonLaunchDescriptionSource

import xacro

def generate_launch_description():

use_sim_time = LaunchConfiguration("use_sim_time", default="false")
def generate_launch_description():
use_sim_time = LaunchConfiguration("use_sim_time", default="true")
use_gui = DeclareLaunchArgument("use_gui", default_value="true", choices=["true", "false"], description="Whether to execute gzclient")
xacro_file_name = "sjtu_drone.urdf.xacro"
pkg_gazebo_ros = get_package_share_directory('gazebo_ros')
xacro_file = os.path.join(
Expand All @@ -29,7 +43,18 @@ def generate_launch_description():
"worlds", "playground.world"
)

def launch_gzclient(context, *args, **kwargs):
if context.launch_configurations.get('use_gui') == 'true':
return [IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_gazebo_ros, 'launch', 'gzclient.launch.py')
),
launch_arguments={'verbose': 'true'}.items()
)]
return []

return LaunchDescription([
use_gui,
Node(
package="robot_state_publisher",
executable="robot_state_publisher",
Expand Down Expand Up @@ -57,12 +82,7 @@ def generate_launch_description():
'extra_gazebo_args': 'verbose'}.items()
),

IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_gazebo_ros, 'launch', 'gzclient.launch.py')
),
launch_arguments={'verbose': "true"}.items()
),
OpaqueFunction(function=launch_gzclient),

Node(
package="sjtu_drone_bringup",
Expand Down
2 changes: 1 addition & 1 deletion sjtu_drone_bringup/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>sjtu_drone_bringup</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">ubuntu</maintainer>
<maintainer email="[email protected]">Georg Novotny</maintainer>
<license>TODO: License declaration</license>

<depend>rclpy</depend>
Expand Down
17 changes: 15 additions & 2 deletions sjtu_drone_bringup/sjtu_drone_bringup/spawn_drone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#!/usr/bin/python3
#!/usr/bin/env python3
# Copyright 2023 Georg Novotny
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -*- coding: utf-8 -*-
import os
import sys
import rclpy
from gazebo_msgs.srv import SpawnEntity
Expand Down
24 changes: 24 additions & 0 deletions sjtu_drone_control/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>sjtu_drone_control</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">Georg Novotny</maintainer>
<license>TODO: License declaration</license>

<depend>sensor_msgs</depend>
<depend>geometry_msgs</depend>
<depend>rclpy</depend>
<depend>std_msgs</depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend> <maintainer email="[email protected]">ubuntu</maintainer>

<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
4 changes: 4 additions & 0 deletions sjtu_drone_control/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/sjtu_drone_control
[install]
install_scripts=$base/lib/sjtu_drone_control
26 changes: 26 additions & 0 deletions sjtu_drone_control/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from setuptools import setup

package_name = 'sjtu_drone_control'

setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='ubuntu',
maintainer_email='[email protected]',
description='TODO: Package description',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'teleop = sjtu_drone_control.teleop:main'
],
},
)
Empty file.
Loading

0 comments on commit 460acc4

Please sign in to comment.