RViz2展示

功能介绍

TogetheROS.Bot兼容ROS2 foxy版本,为了方便预览图像效果,可以通过RViz2获取图像。

支持平台

平台 运行方式 示例功能
旭日X3派 Ubuntu 20.04 启动MIPI摄像头获取图像,在PC上使用RViz2预览

准备工作

旭日X3派

  1. 旭日X3派已烧录好地平线提供的Ubuntu 20.04系统镜像。

  2. 旭日X3派已成功安装tros.b。

  3. PC已安装Ubuntu 20.04系统、ROS2 Foxy桌面版和数据可视化工具RViz2,并且和旭日X3派在同一网段(IP地址前三位相同)。

    ROS2 Foxy安装参考:https://docs.ros.org/en/foxy/Installation/Ubuntu-Install-Debians.html

    PC 端 RViz2安装方法为:sudo apt install ros-foxy-rviz-common ros-foxy-rviz-default-plugins ros-foxy-rviz2

使用方式

旭日X3派

  1. 通过SSH登录开发板,启动板端相关程序

    vim mipi_cam.launch.py

    from launch import LaunchDescription
    from launch_ros.actions import Node
    
    def generate_launch_description():
        return LaunchDescription([
            # 启动图片发布pkg
            Node(
                package='mipi_cam',
                executable='mipi_cam',
                output='screen',
                parameters=[
                    {"out_format": "bgr8"},
                    {"image_width": 480},
                    {"image_height": 272},
                    {"io_method": "ros"},
                    {"video_device": "F37"}
                ],
                arguments=['--ros-args', '--log-level', 'error']
            )
        ])
    

    保存然后:

    # 配置tros.b环境
    source /opt/tros/setup.bash
    # 启动F37 camera发布BGR8格式图像
    ros2 launch mipi_cam mipi_cam.launch.py
    

    注意:out_format请勿随意更改,RViz2只支持RGB8, RGBA8, BGR8, BGRA8等图像格式.

  2. 如程序输出如下信息,说明节点已成功启动

    [INFO] [launch]: All log files can be found below /root/.ros/log/2022-08-19-03-53-54-778203-ubuntu-2881662
    [INFO] [launch]: Default logging verbosity is set to INFO
    [INFO] [mipi_cam-1]: process started with pid [2881781]
    
  3. 旭日X3派新建一个窗口,查询话题命令及返回结果如下:

    # 配置tros.b环境
    source /opt/tros/setup.bash
    # 查询topic
    ros2 topic list
    

    输出:

    /image_raw
    /parameter_events
    /rosout
    
  4. PC机上查询当前话题,查询命令及返回结果如下:

    # 配置ROS2环境
    source /opt/ros/foxy/local_setup.bash
    ros2 topic list
    

    输出:

    /image_raw
    /parameter_events
    /rosout
    
  5. PC机上订阅话题,并预览摄像头数据;

    # 配置ROS2环境
    source /opt/ros/foxy/local_setup.bash
    ros2 run rviz2 rviz2
    

    在 RViz2 界面上首先点击 add 按钮,然后按照topic选择发布的图像,在该示例中topic名为/image_raw,然后点击image:

    ../../_images/rviz2-config.png

    图像效果图如下:

    ../../_images/rviz2-result.png

注意事项

  1. 如遇到PC端ros2 topic list未识别到摄像头topic,排查:

    • 检查X3派是否正常pub图像

      source /opt/tros/setup.bash
      ros2 topic list
      

      输出:

      /image_raw
      /parameter_events
      /rosout
      
    • 检查PC和旭日X3派网络能否ping通;

    • PC和旭日X3派IP地址是否前三位相同;