当前位置:网站首页>16、 Launch file label of ROS (II)

16、 Launch file label of ROS (II)

2022-07-28 14:53:00 Rock magnon

1、launch Document labels

1.param

  • It is mainly used to set parameters on the parameter server , It can be loaded through external files
  • attribute :
    • name=“ Namespace / Parameter name ”
      • Parameter name , Can contain namespaces
    • value=“xxx”( Optional )
      • Define parameter values , If omitted here , You must specify an external file as the parameter source
    • type=“str/int/double/bool/yaml”( Optional )
      • If the parameter type is not specified , The system will try to determine the parameter type , The following rules :
        • contain . Numbers : Think of it as floating point
        • It doesn't contain . The number of : Think it's an integer
        • Others are strings
  • Code implementation : There are two formats
    <launch deprecated = " Disclaimer ">
        <!--  Disclaimer , Warnings will be given during operation  -->
        <!--  Format 1:launch Next ,node Outside  -->
        <param name="param_A" type="int" value="100" />
        <node pkg="turtlesim" type="turtlesim_node" name="myturtle" output="screen" >
            <remap from="/turtle1/cmd_vel" to="/cmd_vel" />
        <!--  Format 2:node Inside , The user-defined node name will be added before the parameter  -->
            <param name="param_B" type="double" value="1.2" />
        </node>
        <node pkg="turtlesim" type="turtle_teleop_key" name="mykey" output="screen" />
    </launch>
    
  • Running results :
    /myturtle/param_B
    /param_A
    

2.rosparam

  • effect : from yaml Import... Into the file , export , Delete parameters
  • attribute :
    • command=“load/dump/delete”( The default is load)
    • file=“$(find xxxx)/xxxx/xxxx…”
      • File load export path
    • param=“ Parameter name ”( Optional ), Used to determine the parameters under that node
    • ns=“ Namespace ”( Optional )
  • Implementation steps :
      1. Write parameter file yaml
      R: 200
      G: 300
      B: 400
      
      1. load: Import parameters
      • Code implementation :( Two formats )
        <launch deprecated = " Disclaimer ">
            <!--  Disclaimer , Warnings will be given during operation  -->
            <!--  Load parameters  -->
            <!--  Format 1: stay node External loading  -->
            <rosparam command="load" file="$(find launch_test_01)/launch/params.yaml" />
            <node pkg="turtlesim" type="turtlesim_node" name="myturtle" output="screen" >
                <!--  Format 2: stay node Internal loading , There will be one more node name defined by yourself  -->
                <rosparam command="load" file="$(find launch_test_01)/launch/params.yaml" />
            </node>
            <node pkg="turtlesim" type="turtle_teleop_key" name="mykey" output="screen" />
        </launch>
        
      • Running results :
        PARAMETERS
        * /B: 400
        * /G: 300
        * /R: 200
        * /myturtle/B: 400
        * /myturtle/G: 300
        * /myturtle/R: 200
        
      1. dump: Export parameters
      • Code implementation :
        turtle_start.launch( The node and the export command are in the same file )
        <launch deprecated = " Disclaimer ">
            <!--  Disclaimer , Warnings will be given during operation  -->
            <!--  Load parameters  -->
            <!--  Format 1: stay node External loading  -->
            <rosparam command="load" file="$(find launch_test_01)/launch/params.yaml" />
            <!--  Format 1: stay node Export , All parameters will be exported , But sometimes some parameters will be exported , You'd better write one by yourself launch file , Export parameters  -->
            <!--  Specifies the namespace , Only the parameters in the renamed space will be exported  -->
            <rosparam command="dump" file="$(find launch_test_01)/launch/params_out1.yaml" ns="myturtle" />
            <rosparam command="dump" file="$(find launch_test_01)/launch/params_out2.yaml" />
            <node pkg="turtlesim" type="turtlesim_node" name="myturtle" output="screen" >
                <!--  Format 2: stay node Internal loading , There will be one more node name defined by yourself  -->
                <rosparam command="load" file="$(find launch_test_01)/launch/params.yaml" />
                <!--  Format 2: stay node Internal export , Only the parameters under the current node will be exported  -->
                <rosparam command="dump" file="$(find launch_test_01)/launch/params_out3.yaml" />
            </node>
            <node pkg="turtlesim" type="turtle_teleop_key" name="mykey" output="screen" />
        </launch>      ```xml
        <launch deprecated = " Disclaimer ">
            <!--  Disclaimer , Warnings will be given during operation  -->
            <!--  Load parameters  -->
            <!--  Format 1: stay node External loading  -->
            <rosparam command="load" file="$(find launch_test_01)/launch/params.yaml" />
            <!--  Format 1: stay node Export , All parameters will be exported , But sometimes some parameters will be exported , You'd better write one by yourself launch file , Export parameters  -->
            <!--  Specifies the namespace , Only the parameters in the renamed space will be exported  -->
            <rosparam command="dump" file="$(find launch_test_01)/launch/params_out1.yaml" ns="myturtle" />
            <rosparam command="dump" file="$(find launch_test_01)/launch/params_out2.yaml" />
            <node pkg="turtlesim" type="turtlesim_node" name="myturtle" output="screen" >
                <!--  Format 2: stay node Internal loading , There will be one more node name defined by yourself  -->
                <rosparam command="load" file="$(find launch_test_01)/launch/params.yaml" />
                <!--  Format 2: stay node Internal export , Only the parameters under the current node will be exported  -->
                <rosparam command="dump" file="$(find launch_test_01)/launch/params_out3.yaml" />
            </node>
            <node pkg="turtlesim" type="turtle_teleop_key" name="mykey" output="screen" />
        </launch>
        
        params.launch( The node and the export command are not in the same file )
        <launch>
            <!--  Write a single launch file , Prevent incomplete parameter Export  -->
            <rosparam command="dump" file="$(find launch_test_01)/launch/params_out4.yaml" />
        </launch>
        
      • Running results :
        params_out1.yaml
        B: 400
        G: 300
        R: 200
        background_b: 255
        background_g: 86
        background_r: 69
        param_B: 1.2
        
        params_out2.yaml
        B: 400
        G: 300
        R: 200
        myturtle:
          B: 400
          G: 300
          R: 200
          background_b: 255
          background_g: 86
          background_r: 69
          param_B: 1.2
        param_A: 100
        rosdistro: 'noetic
        
          '
        roslaunch:
          uris:
            host_d102_w65kj1_kk1__33231: http://d102-W65KJ1-KK1:33231/
            host_d102_w65kj1_kk1__33309: http://d102-W65KJ1-KK1:33309/
            host_d102_w65kj1_kk1__33799: http://d102-W65KJ1-KK1:33799/
            host_d102_w65kj1_kk1__43485: http://d102-W65KJ1-KK1:43485/
            host_d102_w65kj1_kk1__44799: http://d102-W65KJ1-KK1:44799/
            host_d102_w65kj1_kk1__45711: http://d102-W65KJ1-KK1:45711/
            host_d102_w65kj1_kk1__46191: http://d102-W65KJ1-KK1:46191/
        rosversion: '1.15.14
        
          '
        run_id: 0f399634-f437-11ec-a9f9-9bef9f37954f
        
        params_out3.yaml
        B: 400
        G: 300
        R: 200
        background_b: 255
        background_g: 86
        background_r: 69
        param_B: 1.2
        
        params_out4.yaml
        B: 400
        G: 300
        R: 200
        myturtle:
          B: 400
          G: 300
          R: 200
          background_b: 255
          background_g: 86
          background_r: 69
          param_B: 1.2
        param_A: 100
        rosdistro: 'noetic
        
          '
        roslaunch:
          uris:
            host_d102_w65kj1_kk1__33231: http://d102-W65KJ1-KK1:33231/
            host_d102_w65kj1_kk1__33309: http://d102-W65KJ1-KK1:33309/
            host_d102_w65kj1_kk1__33799: http://d102-W65KJ1-KK1:33799/
            host_d102_w65kj1_kk1__40997: http://d102-W65KJ1-KK1:40997/
            host_d102_w65kj1_kk1__43485: http://d102-W65KJ1-KK1:43485/
            host_d102_w65kj1_kk1__44799: http://d102-W65KJ1-KK1:44799/
            host_d102_w65kj1_kk1__45711: http://d102-W65KJ1-KK1:45711/
            host_d102_w65kj1_kk1__46191: http://d102-W65KJ1-KK1:46191/
        rosversion: '1.15.14
        
          '
        run_id: 0f399634-f437-11ec-a9f9-9bef9f37954f
        
    • delete: Delete parameters
      • Code implementation :
        <launch>
            <rosparam command="delete" param="/B" />
        </launch>
        

3.group

  • effect : Grouping nodes , Make the node have ns attribute , So you can start the same node , Use namespaces to distinguish
  • attribute :
    • ns=“ The name space ”( Optional )
    • clear_params=“true/false”( Optional : Use with caution )
  • Code implementation :
    <launch>
        <group ns="first" clear_params="true">
            <node pkg="turtlesim" type="turtlesim_node" name="myturtle" output="screen" />
            <node pkg="turtlesim" type="turtle_teleop_key" name="mykey" output="screen" />
        </group>
        <group ns="second" clear_params="true">
            <node pkg="turtlesim" type="turtlesim_node" name="myturtle" output="screen" />
            <node pkg="turtlesim" type="turtle_teleop_key" name="mykey" output="screen" />
        </group>
    </launch>
    
  • Running results :
    rosnode list
    
    /first/mykey
    /first/myturtle
    /myturtle
    /rosout
    /second/mykey
    /second/myturtle
    

4.arg

  • effect : For dynamic parameter transfer , Parameter reuse
  • attribute :
    • name=“ Parameter name ”
    • default=“ The default value is ”( Optional )
    • value=“ The number ”( Optional ,default and value Can't exist at the same time )
    • doc=“ Parameter description ”
  • Code implementation :
    <launch>
        <!--  Be careful ,default and value Can't exist at the same time  -->
        <rosparam command="delete" param="/B" />
        <arg name="car_weight" default="2.3" doc="this is a test" />
        <arg name="car_length" value="2.3" doc="this is a test" />
        <param name="weight" value="$(arg car_weight)" />
        <param name="length" value="$(arg car_length)" />
    </launch>
    
  • Running results :
    rosparam list
    /length
    /weight
    
  • Command assignment :
    roslaunch launch_test_01 arg.launch car_weight:=0.8
    
原网站

版权声明
本文为[Rock magnon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/196/202207130924520444.html