zoukankan      html  css  js  c++  java
  • ROS启动多launch文件

    在ROS工程中经常需要启动好几个launch文件,比较不方便,有下面两种方法可以更高效些:

    1. 重写一个大型的launch文件,将所有的节点的启动配置信息都包含进去。
    2. 通过bash写一个xxx.sh文件,将命令行一起写入一个脚本。
    launch文件中则如下进行设置:

    pkg对应文件的包名。

    type是CMakeList.txt中对应该文件add_executable(pcan_test src/pcan_test)中可执行文件的名称,在python中则是文件名,因为Python的可执行文件就是文件本身(解释性语言,同Matlab),所以若用C++编程不要误写为文件名全称。

    name表示节点启动后的名称,该名称会覆盖ros::init中初始化的名称。

    output后参数表示从屏幕输出打印信息,否则打印信息会存储到某个临时文件里。

    <launch>
    <node pkg="uav_dl" name="position_control" type="position_control.py" output="screen" />
    <node pkg="uav_dl" name="action_control" type="action_control.py" output="screen" />
    <node pkg="uav_dl" name="goto_position_server" type="goto_position_server.py" output="screen" />
    <node pkg="uav_dl" name="detect_object_server" type="detect_object_server.py" output="screen" />
    <node pkg="uav_dl" name="tensorflow_detection" type="tensorflow_detection.py" output="screen" />
    </launch>

    注:只需要在src下建立launch文件夹,然后在其中创建launch文件即可,不需要做其他工作。

    参数里nameros::param::get()中第一个字符串去掉“~”后的名称,launch会在运行时进行查找匹配,type是变量类型,value是具体值。以下launch文件(包含私有变量和公有变量)。

    <launch>

    <arg name="fcu_url" default="serial:///dev/ttyACM0:921600" />
    <arg name="gcs_url" default="udp://:14556@192.168.150.2:14550" />
    <arg name="tgt_system" default="1" />
    <arg name="tgt_component" default="50" />

    <node name="mavros" pkg="mavros" type="mavros_node" output="screen">
    <param name="fcu_url" value="$(arg fcu_url)" />
    <param name="gcs_url" value="$(arg gcs_url)" />
    <param name="target_system_id" value="$(arg tgt_system)" />
    <param name="target_component_id" value="$(arg tgt_component)" />

    <rosparam command="load" file="$(find mavros)/launch/px4_blacklist.yaml" />

    <!-- enable heartbeat send and reduce timeout -->
    <param name="conn_heartbeat" value="5.0" />
    <param name="conn_timeout" value="5.0" />
    <!-- automatically start mavlink on USB -->
    <param name="startup_px4_usb_quirk" value="true" />

    </node>

    <node name="camera" pkg="usb_cam" type="usb_cam_node">
    <param name="video_device" value="/dev/video0" />
    <param name="image_width" value="800" />
    <param name="image_height" value="600" />
    <param name="pixel_format" value="mjpeg" />
    <param name="framerate" value="30" />
    <param name="camera_frame_id" value="webcam" />
    </node>

    <node name="viewer" pkg="image_view" type="image_view">
    <remap from="image" to="/camera/image_raw" />
    </node>

    </launch>
    在ubuntu下进行节点启动顺序控制的简单策略就是通过shell实现

    新建文件后命名为xxx.sh

    #!/bin/bash
    roslaunch bhand_controller bhand_controller.launch &
    sleep 5
    echo "bhand controller starting success!"

    roslaunch beginner_tutorials bhand_force_control.launch &
    sleep 0.1
    wait
    exit 0

    代码解释:第一行表示用bash执行,sleep表示演示,echo用来输出一定内容,注意不要忘记句子后的”&“符号。注:若ROS的关键词不能在终端识别,需先source下ROS环境。

    节点启动顺序控制策略就是如果某个节点必须先执行,可以单独为其写一个launch文件,然后通过shell控制先行启动。

    参考链接:https://wangcong.info/article/ROSLaunchTips.html

  • 相关阅读:
    em,pt和px之间的换算
    css中 中文字体(fontfamily)的标准英文名称
    HTML css面试题
    css实现的透明三角形
    JavaScript经典面试题系列
    C++ template 学习笔记(第二章)
    C++ template 学习笔记 (第五章)
    20120906
    C++ template 学习笔记(第十六章) 16.1 命名模版参数
    C++ template 学习笔记(第三,四章)
  • 原文地址:https://www.cnblogs.com/klcf0220/p/10395844.html
Copyright © 2011-2022 走看看