ROS2 launch时根据xacro生成urdf
文章目录
- 前言
- 正文
前言
本文简单记录如何在ros2 launch时生成urdf并保存到目标目录。
正文
python">from launch.substitutions import Command, FindExecutable, PathJoinSubstitution
from launch_ros.substitutions import FindPackageSharedef 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机械臂模型-CSDN博客》有写命令中-o
参数的原因
对于xacro
的使用说明可以参考官方文档《xacro — xacro 2.0.11 documentation (ros.org)》及《Using Xacro to clean up your code — ROS 2 Documentation: Humble documentation》