Author of this series of tutorials: Xiaoyu
Public account: Yuxiang ROS
QQ exchange group: 139707339
Teaching video address: Xiaoyu's B station
Full document address: Yuxiang ROS official website
Copyright statement: Reprinting and commercial use are prohibited unless permitted.
8.2 RVIZ2 Visualized Mobile Robot Model
Hello everyone, I'm Xiaoyu. After the joint and link in the previous section, let's display the simple URDF (including body and radar) we defined above with RVIZ2, and intuitively feel our robot model.
The steps of URDF visualization are as follows:
-
Create a robot description function package
-
Create
urdf
a folder to write a urdf file -
Create
launch
a folder and write a launch file -
Modify the
setup.py
configuration, compile and test
1. Create a function package
Familiar with the road, first create a fishbot_ws
workspace, then create a function package, choose the type of packageament_python
ros2 pkg create fishbot_description --build-type ament_python
2. Create a URDF file
Create a folder, create a urdf file
cd fishbot_description && mkdir urdf
touch fishbot_base.urdf
editfishbot_base.urdf
<?xml version="1.0"?>
<robot name="fishbot">
<!-- base link -->
<link name="base_link">
<visual>
<origin xyz="0 0 0.0" rpy="0 0 0"/>
<geometry>
<cylinder length="0.12" radius="0.10"/>
</geometry>
</visual>
</link>
<!-- laser link -->
<link name="laser_link">
<visual>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<cylinder length="0.02" radius="0.02"/>
</geometry>
<material name="black">
<color rgba="0.0 0.0 0.0 0.8" />
</material>
</visual>
</link>
<!-- laser joint -->
<joint name="laser_joint" type="fixed">
<parent link="base_link" />
<child link="laser_link" />
<origin xyz="0 0 0.075" />
</joint>
</robot>
3. Create a launch file
mkdir launch
touch display_rviz2.launch.py
import os
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
def generate_launch_description():
package_name = 'fishbot_description'
urdf_name = "fishbot_base.urdf"
ld = LaunchDescription()
pkg_share = FindPackageShare(package=package_name).find(package_name)
urdf_model_path = os.path.join(pkg_share, f'urdf/{
urdf_name}')
robot_state_publisher_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
arguments=[urdf_model_path]
)
joint_state_publisher_node = Node(
package='joint_state_publisher_gui',
executable='joint_state_publisher_gui',
name='joint_state_publisher_gui',
arguments=[urdf_model_path]
)
rviz2_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='screen',
)
ld.add_action(robot_state_publisher_node)
ld.add_action(joint_state_publisher_node)
ld.add_action(rviz2_node)
return ld
To visualize the model requires three nodes to participate
joint_state_publisher_gui
Responsible for publishing robot joint data information throughjoint_states
topicsrobot_state_publisher_node
Responsible for publishing robot model informationrobot_description
andjoint_states
publishing data conversion tf informationrviz2_node
Responsible for displaying information about the robot
graph
A[joint_state_publisher]--joint_states-->B
B[robot_state_publisher]--robot_de-->C
C[rviz2]
Here we use joint_state_publisher_gui
and robot_state_publisher
two packages, if your system does not have these two packages installed, you can install them manually:
sudo apt install ros-$ROS_DISTRO-joint-state-publisher-gui ros-$ROS_DISTRO-robot-state-publisher
joint_state_publisher_gui
, and there is a brother calledjoint_state_publisher
the difference between the two . Whenjoint_state_publisher_gui
running, an interface will pop up. Through the interface, you can operate the active joints in the URDF.
4. Modify setup.py
import header
from glob import glob
import os
add directory installation
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
whole
from setuptools import setup
from glob import glob
import os
package_name = 'fishbot_description'
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']),
(os.path.join('share', package_name, 'launch'), glob('launch/*.launch.py')),
(os.path.join('share', package_name, 'urdf'), glob('urdf/**')),
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='root',
maintainer_email='[email protected]',
description='TODO: Package description',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
],
},
)
5. Compile and test
compile
colcon build
run the test
source install/setup.bash
ros2 launch fishbot_description display_rviz2.launch.py
Add the robotmodel module, select the link name as follows, and you can see the model display of the robot
Now look at the node relationship diagram
Here you can refer to the relationship between the three nodes started in the Graph-Management launch file.
Then open the TF module and look at the coordinate system relationship of the robot
6. Exercise in this section
Exercise 1: Try changing the color of the modified robot body to blue and the opacity to 50%(0.1 0.1 1.0 0.5)
Exercise 2: Try to add imu_link in URDF and use imu_joint to fix it 2cm above the center of the car body. The geometry used by imu is box. Length, width and height are each 2cm
Results show:
Technical exchange && problem assistance:
-
WeChat public account and communication group: Yuxiang ROS
-
Xiaoyu WeChat: AiIotRobot
-
QQ exchange group: 139707339
-
Copyright Protection: Joined the Copyright Protection Program of Rights Knights (rightknights.com)
about the author:
I am Xiaoyu, a senior player in the field of robotics. I am currently a unipod robot algorithm engineer in Shenzhen,
learning programming in junior high school. I began to get in touch with robots in high school. During college, I played robot-related competitions and achieved a monthly income of 2W+ (competition bonus).
Currently, I am outputting robot learning guides , paper notes, work experience, welcome everyone to pay attention to Xiaoyu, exchange technology together, and learn robots