【ROS2】演示:用假机器人(dummy robot)进行实验

在这个演示中,我们展示了一个简单的演示机器人,包含从发布关节状态到发布虚假激光数据再到在 RViz 中可视化机器人模型的所有组件

启动演示

我们假设您的 ROS 2 安装目录为 ~/ros2_ws 。请根据您的平台更改目录。

要启动演示,我们执行演示启动文件,我们将在下一节中详细解释。

源码构建:

mkdir -p ~/ros2_ws/src 
cd ~/ros2_ws/src 
git clone -b ${ROS_DISTRO} https://github.com/ros2/demos 
cd .. && colcon build –packages-up-to dummy_robot_bringup 
source ~/ros2_ws/install/setup.bash 
ros2 launch dummy_robot_bringup dummy_robot_bringup_launch.py
cxy@cxy-Ubuntu2404:~/second_ros2_ws$  ros2 launch dummy_robot_bringup dummy_robot_bringup_launch.py
[INFO] [launch]: All log files can be found below /home/cxy/.ros/log/2024-07-25-14-00-29-377480-cxy-Ubuntu2404-194696
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [dummy_map_server-1]: process started with pid [194699]
[INFO] [robot_state_publisher-2]: process started with pid [194700]
[INFO] [dummy_joint_states-3]: process started with pid [194701]
[INFO] [dummy_laser-4]: process started with pid [194702]
[dummy_laser-4] [INFO] [1721887229.677420145] [dummy_laser]: angle inc:  0.004363
[dummy_laser-4] [INFO] [1721887229.677495680] [dummy_laser]: scan size:  1081
[dummy_laser-4] [INFO] [1721887229.677505147] [dummy_laser]: scan time increment:   0.000000
[robot_state_publisher-2] [INFO] [1721887230.335038334] [robot_state_publisher]: Robot initialized

dummy_robot_bringup_launch.py

import os  # 导入操作系统模块


from launch import LaunchDescription  # 从launch模块导入LaunchDescription类
from launch.substitutions import FileContent  # 从launch.substitutions模块导入FileContent类
from launch_ros.actions import Node  # 从launch_ros.actions模块导入Node类
from launch_ros.substitutions import FindPackageShare  # 从launch_ros.substitutions模块导入FindPackageShare类


def generate_launch_description():  # 定义生成启动描述的函数
    pkg_share = FindPackageShare('dummy_robot_bringup').find('dummy_robot_bringup')  
    # 查找'dummy_robot_bringup'包的共享路径
    urdf_file = os.path.join(pkg_share, 'launch', 'single_rrbot.urdf')  
    # 构建URDF文件的路径
    robot_desc = FileContent(urdf_file)  
    # 读取URDF文件的内容
    rsp_params = {'robot_description': robot_desc}  
    # 创建包含机器人描述的参数字典


    return LaunchDescription([  # 返回一个LaunchDescription对象,包含以下节点
        Node(package='dummy_map_server', executable='dummy_map_server', output='screen'),  
        # 创建一个dummy_map_server节点,输出到屏幕
        Node(package='robot_state_publisher', executable='robot_state_publisher',
             output='screen', parameters=[rsp_params]),  
        # 创建一个robot_state_publisher节点,输出到屏幕,并传递机器人描述参数
        Node(package='dummy_sensors', executable='dummy_joi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值