ros2+xml格式launch文件示例代码(重要内容)

2023-12-16 05:22:49

?源自githubeasy_ros2_launch_talk/easy_launch_demo/launch/demo_launch.xml at main · tylerjw/easy_ros2_launch_talk · GitHub

<launch>
  <arg name="robot_ip" default="xxx.yyy.zzz.www" />
  <arg name="use_fake_hardware" default="true" />
  <arg name="gripper" default="robotiq_2f_85" />
  <arg name="dof" default="7" />

  <let name="robot_description" value="$(command 'xacro $(find-pkg-share kortex_description)/robots/gen3.xacro robot_ip:=$(var robot_ip) use_fake_hardware:=$(var use_fake_hardware) gripper:=$(var gripper) dof:=$(var dof)')" />
  <let name="robot_description_semantic" value="$(command 'xacro $(find-pkg-share kinova_gen3_7dof_robotiq_2f_85_moveit_config)/config/gen3.srdf')" />

  <!-- MoveGroup -->
  <node pkg="moveit_ros_move_group" exec="move_group" output="screen">
    <param name="robot_description" value="$(var robot_description)" type="str" />
    <param name="robot_description_semantic" value="$(var robot_description_semantic)" type="str" />
    <param from="$(find-pkg-share easy_launch_demo)/config/moveit.yaml" />
  </node>

  <!-- RViz -->
  <node pkg="rviz2" exec="rviz2" name="rviz2" output="log" args="-d $(find-pkg-share moveit2_tutorials)/launch/kinova_moveit_config_demo.rviz">
    <param name="robot_description" value="$(var robot_description)" type="str" />
    <param name="robot_description_semantic" value="$(var robot_description_semantic)" type="str" />
    <param from="$(find-pkg-share easy_launch_demo)/config/moveit.yaml" />
  </node>

  <!-- Static TF -->
  <node pkg="tf2_ros" exec="static_transform_publisher" name="static_transform_publisher" output="log"
    args="--frame-id world --child-frame-id base_link" />

  <!-- Publish TF -->
  <node pkg="robot_state_publisher" exec="robot_state_publisher" name="robot_state_publisher" output="both" >
    <param name="robot_description" value="$(var robot_description)" type="str" />
  </node>

  <!-- ros2_control -->
  <node pkg="controller_manager" exec="ros2_control_node" output="both" >
    <param name="robot_description" value="$(var robot_description)" type="str" />
    <param from="$(find-pkg-share kinova_gen3_7dof_robotiq_2f_85_moveit_config)/config/ros2_controllers.yaml" />
  </node>

  <!-- ros2_control spawners -->
  <node pkg="controller_manager" exec="spawner" args="joint_state_broadcaster -c /controller_manager" />
  <node pkg="controller_manager" exec="spawner" args="joint_trajectory_controller -c /controller_manager" />
  <node pkg="controller_manager" exec="spawner" args="robotiq_gripper_controller -c /controller_manager" />
</launch>

??

? <let name="robot_description" value="$(command 'xacro $(find-pkg-share kortex_description)/robots/gen3.xacro robot_ip:=$(var robot_ip) use_fake_hardware:=$(var use_fake_hardware) gripper:=$(var gripper) dof:=$(var dof)')" />
?

<let name="robot_description_semantic" value="$(command 'xacro $(find-pkg-share kinova_gen3_7dof_robotiq_2f_85_moveit_config)/config/gen3.srdf')" />

? <!-- MoveGroup -->
? <node pkg="moveit_ros_move_group" exec="move_group" output="screen">
? ? <param name="robot_description" value="$(var robot_description)" type="str" />
? ? <param name="robot_description_semantic" value="$(var robot_description_semantic)" type="str" />
? ? <param from="$(find-pkg-share easy_launch_demo)/config/moveit.yaml" />
? </node>

? <!-- RViz -->
? <node pkg="rviz2" exec="rviz2" name="rviz2" output="log" args="-d $(find-pkg-share moveit2_tutorials)/launch/kinova_moveit_config_demo.rviz">
? ? <param name="robot_description" value="$(var robot_description)" type="str" />
? ? <param name="robot_description_semantic" value="$(var robot_description_semantic)" type="str" />
? ? <param from="$(find-pkg-share easy_launch_demo)/config/moveit.yaml" />
? </node>
上述代码就是textfile的替代方法:即:

? 第一步:<let name="robot_description" value="$(command 'xacro $(find-pkg-share kortex_description)/robots/gen3.xacro robot_ip:=$(var robot_ip) use_fake_hardware:=$(var use_fake_hardware) gripper:=$(var gripper) dof:=$(var dof)')" />

? ? 第二部:<param name="robot_description" value="$(var robot_description)" type="str" />

例如:

这样可以正常显示机器人模型,后面这样就无法显示正常

但是后面这样的写法又可以正常显示

结论就是在ros2中,param中的textfile属性可以用value代替就可以了。

如果这里无法正常显示模型可能是urdf文件地址错误。很常见的就是CMakelists.txt文件中没有

install(
? DIRECTORY launch urdf
? DESTINATION share/${PROJECT_NAME}
)没有上述代码,这个代码用于安装代码到指定文件夹,如果不包含urdf文件夹,那么自然无法找到就会出错

文章来源:https://blog.csdn.net/geniusChinaHN/article/details/135027479
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。