日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ROS系统 launch启动文件的使用方法

發布時間:2025/5/22 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ROS系统 launch启动文件的使用方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

launch文件:通過XML文件實現多節點的配置和啟動(可以自動啟動ROS Master)

使用步驟

  • 選定功能包右擊 —> 添加 launch 文件夾
  • 選定 launch 文件夾右擊 —> 添加 launch 文件
  • 編輯 launch 文件內容
  • 運行 launch 文件
  • 運行結果: 一次性啟動了多個節點

launch文件語法:

<launch> launch文件中的根元素采用<llaunch>標簽定義

啟動節點
<node pkg=“package-name” type=“executable-name” name=“node-name”>

  • pkg :節點所在的功能包名稱
  • type:節點的可執行文件名稱
  • name:節點運行時的名稱
  • output:設置日志的輸出目標
  • respawn、required、ns、args
參數設置
<lparam> 和 <rosparam>

設置ROS系統運行中的參數,存儲在參數服務器中。
<lparam name=“output_frame” value=“odom” />

  • name:參數名
  • value:參數值

加載參數文件中的多個參數:
<rosparam file=“params.yaml” command=“load” ns=“params” />

<arg>

launch文件內部的局部變量,僅限于launch文件使用
<arg name=“arg-name” default=“arg-value” />

  • name:參數名
  • value:參數值

調用:
<param name=“foo” value="$(arg arg-name)" />
<node name=“node” pkg=“package” type=“type” args="$(arg arg-name)" />

重映射
<remap>

重映射ROS計算圖資源的命名
<remap from=“/turtlebotcmd_vel” to="/cmd_vel" />

  • from:原命名
  • to:映射之后的命名
嵌套
<include>

包含其他launch文件,類似C語言中的頭文件包含。
<include file="$(dirname)/other.launch" />

  • file:包含的其他launch文件路徑

更多標簽參考:http://wiki.ros.org/roslaunch/XML

使用 launch 標簽啟動兩個節點。

代碼實現話題消息的定義:
https://blog.csdn.net/qq_44989881/article/details/118574750

創建 learning_launch 工程包

cd ~/catkin_ws/src catkin_create_pkg learning_launch

cd ~/catkin_ws/src/learning_launch

創建 launch 文件夾

mkdir launch

cd launch

創建 simple.launch 文件

touch simple.launch

在simple.launch文件中添加以下代碼:

<launch><node pkg="learning_topic" type="person_subscriber" name="talker" output="screen" /><node pkg="learning_topic" type="person_publisher" name="listener" output="screen" /> </launch>

配置完成后,對工程目錄進行編譯

cd ~/catkin_ws catkin_make

啟動 launch 文件
指令格式:

roslaunch [工程包名] [launch文件名]

例如:

roslaunch learning_launch simple.launch


使用 launch 標簽讀取 yaml 文件的配置

cd ~/catkin_ws/src/learning_launch/launch touch turtlesim_parameter_config.launch

在 turtlesim_parameter_config.launch 文件中添加以下代碼:

<launch><param name="/turtle_number" value="2"/><node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node"><param name="turtle_name1" value="Tom"/><param name="turtle_name2" value="Jerry"/><rosparam file="$(find learning_launch)/config/param.yaml" command="load"/></node><node pkg="turtlesim" type="turtle_teleop_key" name="turtle_teleop_key" output="screen"/></launch> cd ~/catkin_ws/src/learning_launch mkdir config cd config touch param.yaml

在 param.yaml 文件中添加以下代碼:

A: 123 B: "hello"group:C: 456D: "hello" roslaunch learning_launch turtlesim_parameter_config.launch rosparam list


tf坐標系廣播與監聽,用launch文件配置啟動

用代碼創建tf坐標系廣播與監聽的方法: https://blog.csdn.net/qq_44989881/article/details/118603453

cd ~/catkin_ws/src/learning_launch/launch touch start_tf_demo_c++.launch

在 start_tf_demo_c++.launch 文件中添加以下代碼:

<launch><!-- 海龜仿真器--><node pkg="turtlesim" type="turtlesim_node" name="sim"/><!-- 鍵盤控制--><node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/><!-- 兩只海龜的tf廣播--><node pkg="learning_tf" type="turtle_tf_broadcaster" args="/turtle1" name="turtle1_tf_broadcaster" /><node pkg="learning_tf" type="turtle_tf_broadcaster" args="/turtle2" name="turtle2_tf_broadcaster" /><!-- 監聽tf廣播,并且控制turtle2移動--><node pkg="learning_tf" type="turtle_tf_listener" name="listener" /></launch>

啟動節點

roslaunch learning_launch start_tf_demo_c++.launch

touch start_tf_demo_py.launch

在 start_tf_demo_py.launch 文件中添加以下代碼:

<launch><!-- 海龜仿真器--><node pkg="turtlesim" type="turtlesim_node" name="sim"/><!-- 鍵盤控制--><node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/><!-- 兩只海龜的tf廣播--><node name="turtle1_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py"><param name="turtle" type="string" value="turtle1" /></node><node name="turtle2_tf_broadcaster" pkg="learning_tf" type="turtle_tf_broadcaster.py"><param name="turtle" type="string" value="turtle2" /> </node><!-- 監聽tf廣播,并且控制turtle2移動--><node pkg="learning_tf" type="turtle_tf_listener.py" name="listener" /></launch>

啟動節點

roslaunch learning_launch start_tf_demo_py.launch

可直接在該窗口控制海龜的移動。


使用 launch 標簽給話題名稱 起個別名

cd ~/catkin_ws/src/learning_launch/launch touch turtlesim_remap.launch

在 turtlesim_remap.launch 文件中添加以下代碼:

<launch><include file="$(find learning_launch)/launch/simple.launch" /><node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node"><remap from="/turtle1/cmd_vel" to="/cmd_vel"/></node></launch>

啟動節點

roslaunch learning_launch turtlesim_remap.launch

<remap from="/turtle1/cmd_vel" to="/cmd_vel"/>
注:用 /cmd_vel 替換了 /turtle1/cmd_vel,相當于起了個別名。

踩坑

RLException: [start_turtle.launch] is neither a launch file in package [hello_world_c] nor is [hello_world_c] a launch file name
The traceback for the exception was written to the log file

解決方法:
錯誤原因:環境變量設置有問題,重新添加環境變量后再執行roslaunch

source ~/工作空間名/devel/setup.bash

總結

以上是生活随笔為你收集整理的ROS系统 launch启动文件的使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。