日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

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

發(fā)布時(shí)間:2025/5/22 windows 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ROS系统 launch启动文件的使用方法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

launch文件:通過XML文件實(shí)現(xiàn)多節(jié)點(diǎn)的配置和啟動(dòng)(可以自動(dòng)啟動(dòng)ROS Master)

使用步驟

  • 選定功能包右擊 —> 添加 launch 文件夾
  • 選定 launch 文件夾右擊 —> 添加 launch 文件
  • 編輯 launch 文件內(nèi)容
  • 運(yùn)行 launch 文件
  • 運(yùn)行結(jié)果: 一次性啟動(dòng)了多個(gè)節(jié)點(diǎn)

launch文件語法:

<launch> launch文件中的根元素采用<llaunch>標(biāo)簽定義

啟動(dòng)節(jié)點(diǎn)
<node pkg=“package-name” type=“executable-name” name=“node-name”>

  • pkg :節(jié)點(diǎn)所在的功能包名稱
  • type:節(jié)點(diǎn)的可執(zhí)行文件名稱
  • name:節(jié)點(diǎn)運(yùn)行時(shí)的名稱
  • output:設(shè)置日志的輸出目標(biāo)
  • respawn、required、ns、args
參數(shù)設(shè)置
<lparam> 和 <rosparam>

設(shè)置ROS系統(tǒng)運(yùn)行中的參數(shù),存儲(chǔ)在參數(shù)服務(wù)器中。
<lparam name=“output_frame” value=“odom” />

  • name:參數(shù)名
  • value:參數(shù)值

加載參數(shù)文件中的多個(gè)參數(shù):
<rosparam file=“params.yaml” command=“l(fā)oad” ns=“params” />

<arg>

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

  • name:參數(shù)名
  • value:參數(shù)值

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

重映射
<remap>

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

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

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

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

更多標(biāo)簽參考:http://wiki.ros.org/roslaunch/XML

使用 launch 標(biāo)簽啟動(dòng)兩個(gè)節(jié)點(diǎn)。

代碼實(shí)現(xiàn)話題消息的定義:
https://blog.csdn.net/qq_44989881/article/details/118574750

創(chuàng)建 learning_launch 工程包

cd ~/catkin_ws/src catkin_create_pkg learning_launch

cd ~/catkin_ws/src/learning_launch

創(chuàng)建 launch 文件夾

mkdir launch

cd launch

創(chuàng)建 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>

配置完成后,對(duì)工程目錄進(jìn)行編譯

cd ~/catkin_ws catkin_make

啟動(dòng) launch 文件
指令格式:

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

例如:

roslaunch learning_launch simple.launch


使用 launch 標(biāo)簽讀取 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坐標(biāo)系廣播與監(jiān)聽,用launch文件配置啟動(dòng)

用代碼創(chuàng)建tf坐標(biāo)系廣播與監(jiān)聽的方法: 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"/><!-- 兩只海龜?shù)膖f廣播--><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" /><!-- 監(jiān)聽tf廣播,并且控制turtle2移動(dòng)--><node pkg="learning_tf" type="turtle_tf_listener" name="listener" /></launch>

啟動(dòng)節(jié)點(diǎn)

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"/><!-- 兩只海龜?shù)膖f廣播--><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><!-- 監(jiān)聽tf廣播,并且控制turtle2移動(dòng)--><node pkg="learning_tf" type="turtle_tf_listener.py" name="listener" /></launch>

啟動(dòng)節(jié)點(diǎn)

roslaunch learning_launch start_tf_demo_py.launch

可直接在該窗口控制海龜?shù)囊苿?dòng)。


使用 launch 標(biāo)簽給話題名稱 起個(gè)別名

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>

啟動(dòng)節(jié)點(diǎn)

roslaunch learning_launch turtlesim_remap.launch

<remap from="/turtle1/cmd_vel" to="/cmd_vel"/>
注:用 /cmd_vel 替換了 /turtle1/cmd_vel,相當(dāng)于起了個(gè)別名。

踩坑

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

解決方法:
錯(cuò)誤原因:環(huán)境變量設(shè)置有問題,重新添加環(huán)境變量后再執(zhí)行roslaunch

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

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。