Welcome to Jetson Orin NX Developer Kit repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
17.ROS2 rviz2 use
17. ROS2 Rviz2 Use
1. Introduction to Rviz2
During robot development there are all kinds of functions. If we only analyze the data from the data level, it is hard to quickly understand the effect of the data. For example, for a robot model, we need to know what the model we designed looks like, and where the many coordinate frames inside the model are during the motion.
Another example is robotic arm motion planning and autonomous navigation of a mobile robot: we hope to see the environment around the robot and the planned path, and of course the sensor information, such as cameras, 3D cameras, LiDAR, and so on. The data is used for computation, while the visualized result is what people look at.
Therefore, data visualization can greatly improve development efficiency. Rviz2 is exactly such a data visualization software for robot development. The robot model, sensor information, environment information, and so on can all be handled here.
2. Preparation
First, load the ROS2 Jazzy environment in the terminal that starts the simulation:
source /opt/ros/jazzy/setup.bashIf you have a physical robot, you can start rviz on the robot's main control board to practise the content of this section. If you do not have a physical robot, you can start the turtlebot3 simulated robot through the gazebo simulation to simulate topics such as the LiDAR and the camera, which makes the following data visualization convenient.
Note: The installation steps below are not mandatory. If you have a physical robot at hand, you can use the LiDAR information of the real machine directly after setting up the multi-machine communication, and you can freely choose to use the real LiDAR or the virtual simulated robot. The following content is suitable for users without a real robot.
This section uses the simulated robot as an example to teach the visualization functions of rviz2. Whether it is a real robot or a simulated robot, the rviz2 operation flow is the same.
Install the TurtleBot3 simulator function package
xxxxxxxxxxsudo apt install ros-${ROS_DISTRO}-turtlebot3*Install the ros and gazebo bridging tool
xxxxxxxxxxsudo apt install ros-${ROS_DISTRO}-ros-gzSet the environment variable of the turtlebot3 robot type
xxxxxxxxxxexport TURTLEBOT3_MODEL=waffleTURTLEBOT3_MODEL must be effective in the same terminal in which the simulation is started. You can first run echo $TURTLEBOT3_MODEL to confirm that it returns waffle, otherwise the launch file will report 'TURTLEBOT3_MODEL'.
Start the gazebo simulation environment
xxxxxxxxxxros2 launch turtlebot3_gazebo turtlebot3_world.launch.pyIt is recommended to run it in the VNC graphical desktop. An SSH or RDP terminal without a correct DISPLAY may fail to show the Gazebo GUI; on devices with little memory you should also close the other Gazebo processes first to avoid EGL errors or insufficient memory. Do not start TurtleBot3 and the other Gazebo worlds of this tutorial at the same time.

3. Starting Rviz2
Open a terminal, and you can start it with the following command:
xxxxxxxxxxrviz2
If you start it inside docker, please make sure that the GUI display has been enabled.

4. Image Data Visualization
Click "Add" in the Displays window on the left, find the Image display item, and after confirming with OK it is added to the display list. Then configure the image topic that this display item subscribes to, and you can smoothly see the camera image of the robot.
Set
Fixed Frameto thebase_footprintcoordinate frame to prevent coordinate transformation errorsSelect the camera colour image topic
/camera/image_rawAt this point you can see the view of the current simulated robot in the Camera window

5. LiDAR Data Visualization
Click "Add" in the Displays window on the left, select Laserscan, and then configure the name of the subscribed topic. At this point you can see the laser points.

Set the
TopicofLaserScanto/scanAt this point you can see the point cloud outline of the LiDAR

6. Robot Model Visualization
Click "Add" in the Displays window on the left and select RobotModel

In the
DescriptionTopicoption of the robot, select the topic/robot_descriptionAt this point you can see the visualization model of the robot in Rviz2

7. Other Data Visualization
rviz_default_plugins lists many commonly used data visualization plugins. You can try them one by one.