ROS2 launch时根据xacro生成urdf

ROS2 launch时根据xacro生成urdf

文章目录

前言

本文简单记录如何在ros2 launch时生成urdf并保存到目标目录。

正文

from launch.substitutions import Command, FindExecutable, PathJoinSubstitution
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
    # 使用'xacro'生成urdf文件,并的保存至"r6bot.urdf"
    robot_description_content = Command(
        [
            PathJoinSubstitution([FindExecutable(name="xacro")]),
            " ",
            PathJoinSubstitution(
                [
                    FindPackageShare("ros2_control_demo_description"),
                    "r6bot",
                    "urdf",
                    "r6bot_description.urdf.xacro",
                ]
            ),
            " -o ",
            PathJoinSubstitution(
                [
                    FindPackageShare("ros2_control_demo_example_7"),
                    "urdf",
                    "r6bot.urdf",
                ]
            ),
        ]
    )
    robot_description = {"robot_description": robot_description_content}

解析:

Command()内部填写具体待执行程序;

PathJoinSubstitution([])拼接不同的路径到一起;

FindPackageShare("ros2_control_demo_description")寻找对应的ROS包的share路径(通常在CMakeLists.txt中定义install share);

在之前的博文中《一文学会MoveIt Setup Assistant搭建moveit2机械臂模型-优快云博客》有写命令中-o参数的原因

对于xacro的使用说明可以参考官方文档《xacro — xacro 2.0.11 documentation (ros.org)》及《Using Xacro to clean up your code — ROS 2 Documentation: Humble documentation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机器人梦想家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值