Skip to content

Commit

Permalink
Merge branch 'gazebosim:ros2' into pr-ros2-material_color
Browse files Browse the repository at this point in the history
  • Loading branch information
bperseghetti authored May 6, 2024
2 parents d122cd2 + 98b9d13 commit 53f0f88
Show file tree
Hide file tree
Showing 29 changed files with 480 additions and 193 deletions.
25 changes: 4 additions & 21 deletions .github/workflows/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,15 @@ export ROS_PYTHON_VERSION=3
apt update -qq
apt install -qq -y lsb-release wget curl build-essential

if [ "$GZ_VERSION" == "garden" ]; then
echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list
wget https://packages.osrfoundation.org/gazebo.key -O - | apt-key add -

GZ_DEPS="libgz-sim7-dev"

ROSDEP_ARGS="--skip-keys='sdformat-urdf'"
elif [ "$GZ_VERSION" == "harmonic" ]; then
echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list
echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-prerelease `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-prerelease.list
wget https://packages.osrfoundation.org/gazebo.key -O - | apt-key add -

GZ_DEPS="libgz-sim8-dev"

ROSDEP_ARGS="--skip-keys='sdformat-urdf'"
fi

# Fortress comes through rosdep for Focal and Jammy
echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list
wget https://packages.osrfoundation.org/gazebo.key -O - | apt-key add -

# Dependencies.
echo "deb http://packages.ros.org/ros2-testing/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-testing.list
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
apt-get update -qq
apt-get install -y $GZ_DEPS \
python3-colcon-common-extensions \
python3-rosdep
apt-get install -y python3-colcon-common-extensions \
python3-rosdep

rosdep init
rosdep update
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/ros2-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,17 @@ jobs:
fail-fast: false
matrix:
include:
- docker-image: "ubuntu:22.04"
gz-version: "garden"
ros-distro: "iron"
- docker-image: "ubuntu:22.04"
gz-version: "garden"
ros-distro: "rolling"
- docker-image: "ubuntu:22.04"
- docker-image: "ubuntu:24.04"
gz-version: "harmonic"
ros-distro: "rolling"
container:
image: ${{ matrix.docker-image }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Build and Test
run: .github/workflows/build-and-test.sh
env:
DOCKER_IMAGE: ${{ matrix.docker-image }}
GZ_VERSION: ${{ matrix.gz-version }}
ROS_DISTRO: ${{ matrix.ros-distro }}
- name: Build sdformat_urdf from source
uses: actions/checkout@v2
if: ${{ matrix.gz-version }} == "garden"
with:
repository: ros/sdformat_urdf
ref: ros2
3 changes: 3 additions & 0 deletions ros_gz/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Changelog for package ros_gz
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1.0.0 (2024-04-24)
------------------

0.246.0 (2023-08-31)
--------------------
* Port: humble to ros2 (`#386 <https://github.com/gazebosim/ros_gz/issues/386>`_)
Expand Down
2 changes: 1 addition & 1 deletion ros_gz/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- TODO: Make this a metapackage, see
https://github.com/ros2/ros2/issues/408 -->
<name>ros_gz</name>
<version>0.246.0</version>
<version>1.0.0</version>
<description>Meta-package containing interfaces for using ROS 2 with <a href="https://gazebosim.org">Gazebo</a> simulation.</description>
<maintainer email="[email protected]">Aditya Pande</maintainer>
<maintainer email="[email protected]">Alejandro Hernandez</maintainer>
Expand Down
16 changes: 16 additions & 0 deletions ros_gz_bridge/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
Changelog for package ros_gz_bridge
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1.0.0 (2024-04-24)
------------------
* Use gz_vendor packages (`#531 <https://github.com/gazebosim/ros_gz/issues/531>`_)
* Added conversion for Detection3D and Detection3DArray (`#523 <https://github.com/gazebosim/ros_gz/issues/523>`_) (`#525 <https://github.com/gazebosim/ros_gz/issues/525>`_)
Co-authored-by: wittenator <[email protected]>
* [Backport rolling] Add ROS namespaces to GZ topics (`#517 <https://github.com/gazebosim/ros_gz/issues/517>`_)
Co-authored-by: Krzysztof Wojciechowski <[email protected]>
* ign to gz (`#519 <https://github.com/gazebosim/ros_gz/issues/519>`_)
* Correctly export ros_gz_bridge for downstream targets (`#503 <https://github.com/gazebosim/ros_gz/issues/503>`_)
* Add a virtual destructor to suppress compiler warning (`#502 <https://github.com/gazebosim/ros_gz/issues/502>`_)
* Add conversion for geometry_msgs/msg/TwistStamped <-> gz.msgs.Twist (`#468 <https://github.com/gazebosim/ros_gz/issues/468>`_)
* Added messages for 2D Bounding Boxes to ros_gz_bridge (`#458 <https://github.com/gazebosim/ros_gz/issues/458>`_) (`#466 <https://github.com/gazebosim/ros_gz/issues/466>`_)
Co-authored-by: Alejandro Hernandez Cordero <[email protected]>
* populate imu covariances when converting (`#375 <https://github.com/gazebosim/ros_gz/issues/375>`_)
* Contributors: Addisu Z. Taddese, Alejandro Hernández Cordero, El Jawad Alaa, Michael Carroll

0.246.0 (2023-08-31)
--------------------
* Add harmonic CI (`#447 <https://github.com/gazebosim/ros_gz/issues/447>`_)
Expand Down
68 changes: 22 additions & 46 deletions ros_gz_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,15 @@ find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(yaml_cpp_vendor REQUIRED)
find_package(yaml-cpp REQUIRED)

if(NOT DEFINED ENV{GZ_VERSION})
set(ENV{GZ_VERSION} "garden")
endif()

# Garden
if("$ENV{GZ_VERSION}" STREQUAL "garden")
find_package(gz-transport12 REQUIRED)
find_package(gz-msgs9 REQUIRED)
find_package(gz_transport_vendor REQUIRED)
find_package(gz-transport REQUIRED)

set(GZ_TARGET_PREFIX gz)
set(GZ_MSGS_VER ${gz-msgs9_VERSION_MAJOR})
set(GZ_TRANSPORT_VER ${gz-transport12_VERSION_MAJOR})
find_package(gz_msgs_vendor REQUIRED)
find_package(gz-msgs REQUIRED)

message(STATUS "Compiling against Gazebo Garden")
elseif("$ENV{GZ_VERSION}" STREQUAL "harmonic")
find_package(gz-transport13 REQUIRED)
find_package(gz-msgs10 REQUIRED)

set(GZ_TARGET_PREFIX gz)
set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})
set(GZ_TRANSPORT_VER ${gz-transport13_VERSION_MAJOR})

message(STATUS "Compiling against Gazebo Harmonic")
else()
message(FATAL_ERROR "This branch is only compatible with Gazebo Garden forward.")
endif()

set(GZ_MSGS_VERSION_MAJOR ${${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}_VERSION_MAJOR})
set(GZ_MSGS_VERSION_MINOR ${${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}_VERSION_MINOR})
set(GZ_MSGS_VERSION_PATCH ${${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}_VERSION_PATCH})
set(GZ_MSGS_VERSION_FULL ${GZ_MSGS_VERSION_MAJOR}.${GZ_MSGS_VERSION_MINOR}.${GZ_MSGS_VERSION_PATCH})
set(GZ_MSGS_VERSION_FULL ${gz-msgs_VERSION})

set(BRIDGE_MESSAGE_TYPES
builtin_interfaces
Expand Down Expand Up @@ -118,15 +95,18 @@ add_library(${bridge_lib}
)

target_link_libraries(${bridge_lib}
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER}::core
PUBLIC
gz-msgs::core
gz-transport::core
PRIVATE
yaml-cpp::yaml-cpp
)

ament_target_dependencies(${bridge_lib}
rclcpp
rclcpp_components
yaml_cpp_vendor
${BRIDGE_MESSAGE_TYPES}
PUBLIC
rclcpp
rclcpp_components
${BRIDGE_MESSAGE_TYPES}
)

target_include_directories(${bridge_lib}
Expand All @@ -138,11 +118,6 @@ target_include_directories(${bridge_lib}
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>"
)

target_link_libraries(${bridge_lib}
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER}::core
)

rclcpp_components_register_node(
${bridge_lib}
PLUGIN ros_gz_bridge::RosGzBridge
Expand Down Expand Up @@ -193,7 +168,7 @@ if(BUILD_TESTING)
${PROJECT_SOURCE_DIR}/src/convert/rcl_interfaces_TEST.cpp
)
target_link_libraries(test_rcl_interfaces
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
gz-msgs::core
${rcl_interfaces_TARGETS}
gtest
gtest_main
Expand Down Expand Up @@ -228,8 +203,8 @@ if(BUILD_TESTING)
)
target_link_libraries(test_utils
${GTEST_LIBRARIES}
${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER}::core
${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER}::core
gz-msgs::core
gz-transport::core
)
ament_target_dependencies(test_utils
rclcpp
Expand Down Expand Up @@ -341,9 +316,10 @@ ament_export_targets(export_${PROJECT_NAME})
# specific order: dependents before dependencies
ament_export_dependencies(rclcpp)
ament_export_dependencies(rclcpp_components)
ament_export_dependencies(${GZ_TARGET_PREFIX}-msgs${GZ_MSGS_VER})
ament_export_dependencies(${GZ_TARGET_PREFIX}-transport${GZ_TRANSPORT_VER})
ament_export_dependencies(yaml_cpp_vendor)
ament_export_dependencies(gz_msgs_vendor)
ament_export_dependencies(gz-msgs)
ament_export_dependencies(gz_transport_vendor)
ament_export_dependencies(gz-transport)
ament_export_dependencies(${BRIDGE_MESSAGE_TYPES})

ament_package()
43 changes: 39 additions & 4 deletions ros_gz_bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ The following message types can be bridged for topics:
| trajectory_msgs/msg/JointTrajectory | gz.msgs.JointTrajectory |
| vision_msgs/msg/Detection2D | gz.msgs.AnnotatedAxisAligned2DBox |
| vision_msgs/msg/Detection2DArray | gz.msgs.AnnotatedAxisAligned2DBox_V |

| vision_msgs/msg/Detection3D | gz::msgs::AnnotatedOriented3DBox |
| vision_msgs/msg/Detection3DArray | gz::msgs::AnnotatedOriented3DBox_V |

And the following for services:

Expand Down Expand Up @@ -102,7 +103,7 @@ Now we start the ROS listener.
```
# Shell B:
. /opt/ros/galactic/setup.bash
. /opt/ros/rolling/setup.bash
ros2 topic echo /chatter
```
Expand Down Expand Up @@ -134,7 +135,7 @@ Now we start the ROS talker.
```
# Shell C:
. /opt/ros/galactic/setup.bash
. /opt/ros/rolling/setup.bash
ros2 topic pub /chatter std_msgs/msg/String "data: 'Hi'" --once
```
Expand Down Expand Up @@ -172,7 +173,7 @@ Now we start the ROS GUI:
```
# Shell C:
. /opt/ros/galactic/setup.bash
. /opt/ros/rolling/setup.bash
ros2 run rqt_image_view rqt_image_view /rgbd_camera/image
```
Expand Down Expand Up @@ -290,9 +291,43 @@ To run the bridge node with the above configuration:
ros2 run ros_gz_bridge parameter_bridge --ros-args -p config_file:=$WORKSPACE/ros_gz/ros_gz_bridge/test/config/full.yaml
```
## Example 6: Using ROS namespace with the Bridge
When spawning multiple robots inside the same ROS environment, it is convenient to use namespaces to avoid overlapping topic names.
There are three main types of namespaces: relative, global (`/`) and private (`~/`). For more information, refer to ROS documentation.
Namespaces are applied to Gazebo topic both when specified as `topic_name` as well as `gz_topic_name`.
By default, the Bridge will not apply ROS namespace on the Gazebo topics. To enable this feature, use parameter `expand_gz_topic_names`.
Let's test our topic with namespace:
```bash
# Shell A:
. ~/bridge_ws/install/setup.bash
ros2 run ros_gz_bridge parameter_bridge chatter@std_msgs/msg/[email protected] \
--ros-args -p expand_gz_topic_names:=true -r __ns:=/demo
```
Now we start the Gazebo Transport listener.
```bash
# Shell B:
gz topic -e -t /demo/chatter
```
Now we start the ROS talker.
```bash
# Shell C:
. /opt/ros/rolling/setup.bash
ros2 topic pub /demo/chatter std_msgs/msg/String "data: 'Hi from inside of a namespace'" --once
```
By changing `chatter` to `/chatter` or `~/chatter` you can obtain different results.
## API
ROS 2 Parameters:
* `subscription_heartbeat` - Period at which the node checks for new subscribers for lazy bridges.
* `config_file` - YAML file to be loaded as the bridge configuration
* `expand_gz_topic_names` - Enable or disable ROS namespace applied on GZ topics.
26 changes: 26 additions & 0 deletions ros_gz_bridge/include/ros_gz_bridge/convert/vision_msgs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

// Gazebo Msgs
#include <gz/msgs/annotated_axis_aligned_2d_box_v.pb.h>
#include <gz/msgs/annotated_oriented_3d_box_v.pb.h>

// ROS 2 messages
#include "vision_msgs/msg/detection2_d_array.hpp"
#include "vision_msgs/msg/detection3_d_array.hpp"
#include <ros_gz_bridge/convert_decl.hpp>

namespace ros_gz_bridge
Expand Down Expand Up @@ -47,6 +49,30 @@ void
convert_gz_to_ros(
const gz::msgs::AnnotatedAxisAligned2DBox_V & gz_msg,
vision_msgs::msg::Detection2DArray & ros_msg);

template<>
void
convert_ros_to_gz(
const vision_msgs::msg::Detection3D & ros_msg,
gz::msgs::AnnotatedOriented3DBox & gz_msg);

template<>
void
convert_gz_to_ros(
const gz::msgs::AnnotatedOriented3DBox & gz_msg,
vision_msgs::msg::Detection3D & ros_msg);

template<>
void
convert_ros_to_gz(
const vision_msgs::msg::Detection3DArray & ros_msg,
gz::msgs::AnnotatedOriented3DBox_V & gz_msg);

template<>
void
convert_gz_to_ros(
const gz::msgs::AnnotatedOriented3DBox_V & gz_msg,
vision_msgs::msg::Detection3DArray & ros_msg);
} // namespace ros_gz_bridge

#endif // ROS_GZ_BRIDGE__CONVERT__VISION_MSGS_HPP_
10 changes: 3 additions & 7 deletions ros_gz_bridge/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>ros_gz_bridge</name>
<version>0.246.0</version>
<version>1.0.0</version>
<description>Bridge communication between ROS and Gazebo Transport</description>
<maintainer email="[email protected]">Aditya Pande</maintainer>
<maintainer email="[email protected]">Alejandro Hernandez</maintainer>
Expand Down Expand Up @@ -31,12 +31,8 @@
<depend>yaml_cpp_vendor</depend>
<depend>vision_msgs</depend>

<!-- Garden (default) -->
<depend condition="$GZ_VERSION == '' or $GZ_VERSION == garden">gz-msgs9</depend>
<depend condition="$GZ_VERSION == '' or $GZ_VERSION == garden">gz-transport12</depend>
<!-- Harmonic -->
<depend condition="$GZ_VERSION == harmonic">gz-msgs10</depend>
<depend condition="$GZ_VERSION == harmonic">gz-transport13</depend>
<depend>gz_msgs_vendor</depend>
<depend>gz_transport_vendor</depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>
Expand Down
2 changes: 2 additions & 0 deletions ros_gz_bridge/ros_gz_bridge/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@
'vision_msgs': [
Mapping('Detection2DArray', 'AnnotatedAxisAligned2DBox_V'),
Mapping('Detection2D', 'AnnotatedAxisAligned2DBox'),
Mapping('Detection3DArray', 'AnnotatedOriented3DBox_V'),
Mapping('Detection3D', 'AnnotatedOriented3DBox'),
],
}
Loading

0 comments on commit 53f0f88

Please sign in to comment.