跳到主要内容

5.1.5 使用 ROS2 package

前提:已成功安装 TogetheROS.Bot

tros.b 和 ROS2 Foxy/Humble/Jazzy 版本接口完全兼容,能够复用 ROS2 丰富工具包,这里以安装和使用 ROS2 image-transport 为例介绍如何在 tros.b 中使用 ROS package。

安装 ROS2 package

1 添加 ROS apt 源

安装 tros.b 时,已自动添加 ROS apt 源,无需手动添加。

更新 apt 仓库

sudo apt update
注意

如果 sudo apt update 命令执行失败或报错,请查看常见问题章节的 Q10: apt update 命令执行失败或报错如何处理? 解决。

如果 sudo apt update 命令执行失败或报错,请查看常见问题章节的 Q10: apt update 命令执行失败或报错如何处理? 解决。

注意

如果 sudo apt update 命令执行失败或报错,请查看常见问题章节的 Q6: apt update 命令执行失败或报错如何处理? 解决。

如果 sudo apt update 命令执行失败或报错,请查看常见问题章节的 Q6: apt update 命令执行失败或报错如何处理? 解决。

2 安装 packages

sudo apt install ros-foxy-image-transport
sudo apt install ros-foxy-image-transport-plugins
sudo apt install ros-humble-image-transport
sudo apt install ros-humble-image-transport-plugins
sudo apt install ros-jazzy-image-transport
sudo apt install ros-jazzy-image-transport-plugins

使用 ROS2 package

与 ROS 使用一样

source /opt/tros/setup.bash
ros2 run image_transport list_transports
source /opt/tros/humble/setup.bash
ros2 run image_transport list_transports
source /opt/tros/jazzy/setup.bash
ros2 run image_transport list_transports

运行结果如下,展示了 image_transport package 支持的图像格式

root@ubuntu:/opt/tros# ros2 run image_transport list_transports
Declared transports:
image_transport/compressed
image_transport/compressedDepth
image_transport/raw
image_transport/theora

Details:
----------
"image_transport/compressed"
- Provided by package: compressed_image_transport
- Publisher:
This plugin publishes a CompressedImage using either JPEG or PNG compression.

- Subscriber:
This plugin decompresses a CompressedImage topic.

----------
"image_transport/compressedDepth"
- Provided by package: compressed_depth_image_transport
- Publisher:
This plugin publishes a compressed depth images using PNG compression.

- Subscriber:
This plugin decodes a compressed depth images.

----------
"image_transport/raw"
- Provided by package: image_transport
- Publisher:
This is the default publisher. It publishes the Image as-is on the base topic.

- Subscriber:
This is the default pass-through subscriber for topics of type sensor_msgs/Image.

----------
"image_transport/theora"
- Provided by package: theora_image_transport
- Publisher:
This plugin publishes a video packet stream encoded using Theora.

- Subscriber:
This plugin decodes a video packet stream encoded using Theora.