Introduction to the compilation of the ROS robot operating system Catkin and the use of common commands

There are many commands in ROS. Let’s sort out some frequently used common commands. These commands are commonly used in the daily operation of robots, and they are also necessary knowledge for how to make robots operate normally in ROS.

Especially when compiling packages, it will be very simple for friends who are familiar with CMake . At present, Catkin is basically used in ROS . It encapsulates CMake and Make, making it more efficient and concise, and more portable. Well, support for cross-compilation and more reasonable distribution of feature packages. Of course, in the ROS system, it is also compatible with the compilation of the old version of rosbuild . However, it is recommended to use Catkin. Basically, the core software packages of ROS have all been converted to Catkin.

1. Common commands

Order effect
roslaunch run startup file
catkin_create_pkg Create feature pack
rospack Get Feature Pack
catkin_make Compile the feature package in the workspace
Rosdep  Automatically install other packages that the feature package depends on
roscd Function pack directory jump
roscp Copy the files in the feature pack
rosed Edit files in feature packs
rosrun Run executables in feature packs

For some of the common commands mentioned above, their detailed explanations are given below, from the official help document, I have made Chinese annotations for them, which is convenient for later search and application.

1.1、roslaunch

roslaunch : Running the startup file is a very important command. For a complex system with many nodes in ROS, you need to use this command to start many nodes at once.

roslaunch -h

Usage: roslaunch [options] [package] <filename> [arg_name:=value...]
       roslaunch [options] <filename> [<filename>...] [arg_name:=value...]

If <filename> is a single dash ('-'), launch XML is read from standard input.

Options:
  -h, --help         show this help message and exit
  --files               Print list files loaded by launch file, including launch file itself Print list files loaded by launch file, including launch file itself  
  -- args=NODE_NAME      Print command-line arguments for node Print command-line arguments for node
  --nodes               Print list of node names in launch file Print list of node names in launch file
  --find-node=NODE_NAME  Find launch file that node is defined in Find the startup file where the node is defined
  -c NAME, --child=NAME     Run as child service 'NAME'. Required with -u Run as child service 'NAME'. Need to bring -u
  --local               Do not launch remote nodes Do not start remote nodes
  --screen              Force output of all local nodes to screen Force all local nodes to output to the screen
  --required            Force all nodes to be required Force all nodes to be required
  --log                 Force output of all local nodes to log Force all local nodes to output logs
  -u URI , --server_uri=URI     URI of server. Required with -c URI of server. Use with -c
  --run_id=RUN_ID       run_id of session. Required with -c Run_id of session. Use with -c
  --wait                wait for master to start before launching wait for the main program to start before launching
  -p PORT, --port=PORT  master port. Only valid if master is launched master port. Only valid when the main server starts
  --core                Launch core services only only launches core services
  --pid=PID_FN         write the roslaunch pid to filename Write the roslaunch pid to the file
  -v                    verbose printing Detailed printing
  --no-summary          hide summary printing Do not print summary-
  -dump -params         Dump parameters of all roslaunch files to stdout Dump to standard output
  --skip-log-check      skip check size of log folder
  --ros-args            Display command-line arguments for this launch file Display command-line arguments for this launch file
  -- disable-title       Disable setting of terminal title Disable terminal title setting
  -w NUM_WORKERS, --numworkers=NUM_WORKERS
                        override number of worker threads. Only valid for core services. Override number of worker threads. Valid for core services only.
  -t TIMEOUT, --timeout=TIMEOUT
                        override the socket connection timeout (in seconds). Only valid for core services.
                        Override the socket connection timeout (in seconds). Valid only for core services.
  --master-logger-level=MASTER_LOGGER_LEVEL
                        set rosmaster.master logger level ('debug', 'info', 'warn', 'error', 'fatal') set log level

There are many parameters, and the parameter that is often followed is screen

--screen : Force all local nodes to output to the screen, which is convenient for observation and debugging. Of course, if you want to save it to a log file for easy viewing later, just specify it as --log . Generally, after the debugging is completed, the screen parameter should be removed to keep the terminal output clean. When the
roslaunch command is running, it will first check whether the rosmaster of the system is running. If it has been started, the existing rosmaster will be used; if it is not started, the rosmaster will be started first, and thenthe settings in the launch file will be executed. The preconfiguration starts up. It should be noted that the launch file does not need to be compiled, and can be run directly in the above way after setting.
arg:=value : Ifthere are variables to be assigned in the launch file, they can be assigned in this way.

1.2、catkin_create_pkg

Information for creating feature packs

catkin_create_pkg -h

usage: catkin_create_pkg [-h] [--meta] [-s [SYS_DEPS [SYS_DEPS ...]]]
                         [-b [BOOST_COMPS [BOOST_COMPS ...]]] [-V PKG_VERSION]
                         [-D DESCRIPTION] [-l LICENSE] [-a AUTHOR]
                         [-m MAINTAINER] [--rosdistro ROSDISTRO]
                         name [dependencies [dependencies ...]]

Creates a new catkin package

positional arguments:
  name                  The name for the package
  dependencies          Catkin package Dependencies

Optional arguments:
  -h, --help show this help message and exit
  --meta                Creates meta-package files
  -s [SYS_DEPS [SYS_DEPS ...]], --sys-deps [SYS_DEPS [SYS_DEPS .. .]]
                        System Dependencies System Dependencies
  -b [BOOST_COMPS [BOOST_COMPS ...]], --boost-comps [BOOST_COMPS [BOOST_COMPS ...]]
                        Boost Components Boost Components
  -V PKG_VERSION, --pkg_version PKG_VERSION  Initial Package version Initial Package Version
  -D DESCRIPTION, --description DESCRIPTION  Description Description
  -l LICENSE, --license LICENSE  Name for License, (eg BSD, MIT, GPLv3...) License Agreement
  -a AUTHOR, --author AUTHOR  A single author, may be used multiple times   作者
  -m MAINTAINER, --maintainer MAINTAINER  A single maintainer, may be used multiple times  维护者
  --rosdistro ROSDISTRO  The ROS distro (default: environment variable ROS_DISTRO if defined)  ROS发行版

1.3、rospack

Get information about feature packs

rospack -h

USAGE: rospack <command> [options] [package]
  Allowed commands:
    help
    cflags-only-I     [--deps-only] [package]
    cflags-only-other [--deps-only] [package]
    depends           [package] (alias: deps)
    depends-indent    [package] (alias: deps-indent)
    depends-manifests [package] (alias: deps-manifests)
    depends-msgsrv    [package] (alias: deps-msgsrv)
    depends-on        [package]
    depends-on1       [package]
    depends-why --target=<target> [package] (alias: deps-why)
    depends1          [package] (alias: deps1)
    export [--deps-only] --lang=<lang> --attrib=<attrib> [package]
    find [package]
    langs
    libs-only-L     [--deps-only] [package]
    libs-only-l     [--deps-only] [package]
    libs-only-other [--deps-only] [package]
    list
    list-duplicates
    list-names
    plugins --attrib=<attrib> [--top=<toppkg>] [package]
    profile [--length=<length>] [--zombie-only]
    rosdep  [package] (alias: rosdeps)
    rosdep0 [package] (alias: rosdeps0)
    vcs  [package]
    vcs0 [package]
  Extra options:
    -q     Quiets error reports.

 If [package] is omitted, the current working directory
 is used (if it contains a package.xml or manifest.xml).

If no package name is specified, it means the current working directory.

1.4、catkin_make

Compile the function package in the workspace, which has been introduced at the beginning of this article. It is specifically for the compilation of packages in ROS, and it is a package for CMake and Make.

catkin_make -h

usage: catkin_make [-h] [-C DIRECTORY] [--source SOURCE] [--build BUILD]
                   [--use-ninja] [--use-nmake] [--use-gmake] [--force-cmake]
                   [--no-color] [--pkg PKG [PKG ...]]
                   [--only-pkg-with-deps ONLY_PKG_WITH_DEPS [ONLY_PKG_WITH_DEPS ...]]
                   [--cmake-args [CMAKE_ARGS [CMAKE_ARGS ...]]]
                   [--make-args [MAKE_ARGS [MAKE_ARGS ...]]]
                   [--override-build-tool-check]

Optional arguments:
  -h, --help show this help message and exit
  -C DIRECTORY, --directory DIRECTORY   The base path of the workspace (default '.') The base path of the workspace (default '.')')
  --source SOURCE       The path to the source space (default 'workspace_base/src')
  --build BUILD         The path to the build space (default 'workspace_base/build' ) Path to the build space (default 'workspace_base/build')
  --use-ninja           Use 'ninja' instead of 'make' Use ninja instead of make
  --use-nmake           Use 'nmake' instead of 'make' Use nmake instead of make
  --use-gmake           Use 'gmake' instead of 'make' Use gmake instead of make
  --force-cmake         Invoke 'cmake' even if it has been executed before   强制使用cmake
  --no-color            Disables colored output (only for catkin_make and CMake)  禁用彩色输出(仅适用于catkin_make和CMake)
  --pkg PKG [PKG ...]   Invoke 'make' on specific packages only  只对特定的包调用make
  --only-pkg-with-deps ONLY_PKG_WITH_DEPS [ONLY_PKG_WITH_DEPS ...]
                        Whitelist only the specified packages and their
                        dependencies by setting the CATKIN_WHITELIST_PACKAGES
                        variable. This variable is stored in CMakeCache.txt
                        and will persist between CMake calls unless explicitly
                        cleared; e.g. catkin_make
                        -DCATKIN_WHITELIST_PACKAGES="".
    Whitelist the specified package and its dependent packages by setting the CATKIN_WHITELIST_PACKAGES variable, which is stored in CMakeCache.txt and will persist between CMake invocations unless explicitly cleared.
  --cmake-args [CMAKE_ARGS [CMAKE_ARGS ...]]
                        Arbitrary arguments which are passed to CMake. It must be passed after other arguments since it collects all following options.
Arbitrary arguments passed to CMake.
  --make-args [MAKE_ARGS [MAKE_ARGS ...]]
                        Arbitrary arguments which are passes to make. It must be passed after other arguments since it collects all following options . This is only necessary in combination with --cmake-args since else all unknown arguments are passed to make anyway. 
This is only required when used in conjunction with --cmake-args, otherwise all unknown arguments are passed to make
  --override-build-tool-check
                        use to override failure due to using different build tools on the same workspace. For Covers failures caused by using different build tools on the same workspace.

1.5、Rosdep

Automatically install dependent packages of feature packages

rosdep -h

 

Usage: rosdep [options] <command> <args>

Commands:

rosdep check <stacks-and-packages>...
  check if the dependencies of package(s) have been met.

rosdep install <stacks-and-packages>...
  download and install the dependencies of a given package or packages.

rosdep db
  generate the dependency database and print it to the console.

rosdep init
  initialize rosdep sources in /etc/ros/rosdep. May require sudo. Initialize dependency sources in /etc/ross/rosdep. May require sudo privileges

rosdep keys <stacks-and-packages>...
  list the rosdep keys that the packages depend on. List the rosdep keys that the packages depend on.

rosdep resolve <rosdeps>
  resolve <rosdeps> to system dependencies resolve <rosdeps> to system dependencies

rosdep update
  update the local rosdep database based on the rosdep sources. Update the local rosdep database according to the rosdep source

rosdep what-needs <rosdeps>...
  print a list of packages that declare a rosdep on (at least one of) <rosdeps> Print a list of packages that declare a rosdep on (at least one of) <rosdeps>

rosdep where-defined <rosdeps>...
  print a list of yaml files that declare a rosdep on (at least one of) <rosdeps> print a list of yaml files that declare a rosdep on (at least one of) <rosdeps>

 1.5.1. Permission commands

rosdep fix-permissions
  Recursively change the permissions of the user's ros home directory. Recursively change the permissions of the user's ros home directory.
  May require sudo. Can be useful to fix permissions after calling "rosdep update" with sudo accidentally.

When permissions are denied, you can use the following commands:
sudo rosdep fix-permissions
rosdep update (sometimes sudo may be required )

1.5.2、Options

Options:
  -h, --help show this help message and exit
  --os=OS_NAME:OS_VERSION
                        Override OS name and version (colon-separated), eg ubuntu:lucid override OS name and version (colon-separated)
  -c SOURCES_CACHE_DIR, --sources-cache-dir=SOURCES_CACHE_DIR
                        Override /home/jetson/.ros/rosdep/sources.cache
  -v, --verbose         verbose display Detailed display
  --version             print just the rosdep version, then exit Only print the rosdep version, then exit
  --all-versions        print rosdep version and version of installers, then exit
  --reinstall           (re)install all dependencies, even if already installed
  -y , --default-yes     Tell the package manager to default to y or fail when installing
  -s, --simulate        Simulate install Simulate install
  -r                    Continue installing despite errors. Continue installing despite errors.
  -q                    Quiet. Suppress output except for errors. Silent installation. Suppress output except errors.
  -a, --all             select all packages
  -n                    Do not consider implicit/recursive dependencies. Only valid with 'keys', 'check', and 'install' commands.
    Do not consider implicit/recursive dependencies. Only valid for 'keys', 'check' and 'install' commands.
  -i, --ignore-packages-from-source, --ignore-src
                        Affects the 'check', 'install', and 'keys' verbs. If specified then rosdep will ignore keys that are found to be catkin or ament packages anywhere in the ROS_PACKAGE_PATH, AMENT_PREFIX_PATH or in any of the directories given by the --from-paths option.   如果指定这个参数rosdeep将忽略在catkin或其他路径找到的包
  --skip-keys=SKIP_KEYS
                        Affects the 'check' and 'install' verbs. The specified rosdep keys will be ignored, i.e. not resolved and not installed. The option can be supplied multiple times.
                        A space separated list of rosdep keys can also be passed as a string. A more permanent solution to locally ignore a rosdep key is creating a local rosdep rule with an empty list of packages (include it in /etc/ros/rosdep/sources. list.d/ before the defaults). A more permanent solution to locally ignore rosdep keys is to create a local rosdep rule (contained in /etc/ross/rosdep/sources.list.d) with an empty package list, in the default Before the value
  --filter-for-installers=FILTER_FOR_INSTALLERS
                        Affects the 'db' verb. If supplied, the output of the 'db' command is filtered to only list packages whose installer is in the provided list. The option can be supplied multiple times . A space separated list of installers can also be passed as a string. Example:
                        `--filter-for-installers "apt pip"` Only install filtered packages
  --from-paths          Affects the 'check', 'keys', and 'install' verbs. If specified the arguments to those verbs will be considered paths to be searched, acting on all catkin packages found there in.
  --rosdistro=ROS_DISTRO
                        Explicitly sets the ROS distro to use, overriding the normal method of detecting the ROS distro using the ROS_DISTRO environment variable. When used with the 'update' verb, only the specified distro will be updated.  显示指定ros的发行版本
  --as-root=INSTALLER_KEY:<bool>
                        Override whether sudo is used for a specific installer, e.g. '--as-root pip:false' or '--as-root "pip:no homebrew:yes"'. Can be specified multiple times.
  --include-eol-distros
                        Affects the 'update' verb. If specified end-of-life distros are being fetched too.
  -t DEPENDENCY_TYPES, --dependency-types=DEPENDENCY_TYPES
                        Dependency types to install, can be given multiple times . Choose from set(['exec', 'doc', 'build_export','buildtool', 'test', 'build', 'buildtool_export']).Default: all except doc. 

1.6、rosrun

Run the executable file rosrun -h in the feature package

Usage: rosrun [--prefix cmd] [--debug] PACKAGE EXECUTABLE [ARGS]
  rosrun will locate PACKAGE and try to find an executable named EXECUTABLE in the PACKAGE tree. If it finds it, it will run it with ARGS.

rosrun will locate the package and then try to find the executable in the package tree, and if found it will run it according to the arguments.

The node manager ( master ) must be started first. The master is used to manage many processes in the system. When each node starts, it must register with the master to manage the communication between nodes . After the master starts, register each node through the master . Enter the command in the Ubuntu terminal: roscore , this roscore is necessary for each ROS, and is used to provide connection information between nodes, that is to say, when a node starts, it will connect to roscore and register the node to publish and subscribe When a new node appears, roscore will provide it with the necessary information for other nodes that publish and subscribe to the same message topic to establish a point-to-point connection. If there is no roscore , the nodes cannot find each other and cannot communicate with each other. The rosrun method can only run one node at a time. The next step is some actual combat of the order.

2. Example demonstration

2.1. Single turtle simulator

First start the node manager, enter the command: roscore
The following is the relevant information for starting, check the log file size, display the service address and port, version number, summary, etc. Press Ctrl+C to end all ROS nodes:

... logging to /home/jetson/.ros/log/fd65134c-d010-11ec-95c6-0013eff86fe1/roslaunch-jetson-desktop-10638.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://jetson-desktop:33239/
ros_comm version 1.14.11


SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.11

NODES

auto-starting new master
process[master]: started with pid [10695]
ROS_MASTER_URI=http://jetson-desktop:11311/

setting /run_id to fd65134c-d010-11ec-95c6-0013eff86fe1
process[rosout-1]: started with pid [10727]
started core service [/rosout]

Open another terminal and start the turtle simulator node

rosrun turtlesim turtlesim_node

[ INFO] [1652153768.669399182]: Starting turtlesim with node name /turtlesim
[ INFO] [1652153768.694629755]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]
QXcbConnection: XCB error: 148 (Unknown), sequence: 173, resource id: 0, major code: 140 (Unknown), minor code: 20

Finally, open a terminal again and start the turtle keyboard controller node
rosrun turtlesim turtle_teleop_key
Under the command of this keyboard controller node, you can control the movement of the turtle by using the up, down, left, and right arrow keys. As shown below: 

That is to say, in this operation of turtle movement, we opened three terminals, first started the node management, and then started the required nodes respectively. We can check which topics are started, enter the command: rostopic list

/rosout
/rosout_agg
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose

You can also enter the rqt_graph command to view the ROS graph: 

2.2. Two turtles 

Let's see an example of a turtle moving with a keyboard-operated turtle
Install the feature package: sudo apt install ros-melodic-turtle-tf

The following errors may occur:

Could not resolve 'packages.ros.org'
E: Failed to fetch http://packages.ros.org/ros/ubuntu/pool/main/r/ros-melodic-turtle-tf/ros-melodic-turtle-tf_0.2.2-0bionic.20210922.040438_arm64.deb  Could not resolve 'packages.ros.org'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

We directly check the following list page: http://packages.ros.org/ros/ubuntu/pool/main/r/ros-melodic-turtle-tf/ can find that there is no deb
file mentioned above , we can choose other manual downloads It will be all right. Of course, if there is a situation in this version, it is because of network timeout and other problems, which can be handled scientifically by surfing the Internet or manually downloading. It can also be replaced with a domestic mirror source:

cd /etc/apt
vim sources.list

For example, Alibaba Cloud's open source mirror site:

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

I am using the Tsinghua image here:

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe

Finally execute the following:

Refresh the local software list: sudo apt-get update
Software update: sudo apt-get upgrade

Run the .launch file through the roslaunch command to start the turtle, and the same will display some relevant information

roslaunch turtle_tf turtle_tf_demo.launch

For example, the abstract:

SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.11
 * /scale_angular: 2.0
 * /scale_linear: 2.0
 * /turtle1_tf_broadcaster/turtle: turtle1
 * /turtle2_tf_broadcaster/turtle: turtle2

NODES
  /
    sim (turtlesim/turtlesim_node)
    teleop (turtlesim/turtle_teleop_key)
    turtle1_tf_broadcaster (turtle_tf/turtle_tf_broadcaster.py)
    turtle2_tf_broadcaster (turtle_tf/turtle_tf_broadcaster.py)
    turtle_pointer (turtle_tf/turtle_tf_listener.py)

ROS_MASTER_URI=http://localhost:11311

process[sim-1]: started with pid [30907]
process[teleop-2]: started with pid [30908]
process[turtle1_tf_broadcaster-3]: started with pid [30909]
process[turtle2_tf_broadcaster-4]: started with pid [30917]
process[turtle_pointer-5]: started with pid [30920]

You can see that the multiple nodes started and the thread ID started by each program are displayed.

Use rosrun to start the node, and operate the keyboard to control the turtle
rosrun turtlesim turtle_teleop_key

As shown in the figure below, there is a turtle controlled by the keyboard, and another turtle follows the controlled turtle:

Three, launch file 

Let's learn more about the launch file. Let's use the launch file above to start the turtle. Let's find it first:
sudo find / -name turtle_tf_demo.launch
After finding it, let's check what is in it
cat /opt/ros/melodic/ share/turtle_tf/launch/turtle_tf_demo.launch

<launch>

  <!-- Turtlesim Node-->
  <node pkg="turtlesim" type="turtlesim_node" name="sim"/>

  <node pkg="turtlesim" type="turtle_teleop_key" name="teleop" output="screen"/>
  <!-- Axes -->
  <param name="scale_linear" value="2" type="double"/>
  <param name="scale_angular" value="2" type="double"/>

  <node name="turtle1_tf_broadcaster" pkg="turtle_tf" type="turtle_tf_broadcaster.py" respawn="false" output="screen" >
    <param name="turtle" type="string" value="turtle1" />
  </node>
  <node name="turtle2_tf_broadcaster" pkg="turtle_tf" type="turtle_tf_broadcaster.py" respawn="false" output="screen" >
    <param name="turtle" type="string" value="turtle2" />
  </node>
  <node name="turtle_pointer" pkg="turtle_tf" type="turtle_tf_listener.py" respawn="false" output="screen" >
  </node>

</launch>

You can see that the launch file is in XML format. According to the examples of Turtle 1 and Turtle 2, we can know that the name of the launched package and the name of the executable program correspond to the node node .
The first turtle example: pkg="turtlesim" type="turtlesim_node" , so the startup code is: rosrun turtlesim turtlesim_node
The second turtle example: pkg="turtle_tf" type="turtle_tf_broadcaster.py" , so the startup code is: roslaunch
The keyboard operation of turtle_tf turtle_tf_demo.launch is the same: rosrun turtlesim turtle_teleop_key
Then why do we need to create a launch file? Because a complete robot generally contains a lot of node programs and needs to run and cooperate at the same time, it would be more troublesome to start the nodes one by one, so through this configuration file, we can get them all started at once, yes Not much easier.
Next, let's take a look at some parameter descriptions of this file:

<launch>                  <!--根标签开始-->
<node>                    <!--需要启动的node及其参数-->
<remap>                  <!--设定topic映射-->
<include>                <!--包含其他launch-->

<arg>                       <!--定义变量-->
<param>                 <!--定义全局变量-->
<rosparam>            <!--加载yaml文件中的参数到参数服务器-->

<group>                 <!--设定分组-->
<machine>              <!--指定运行的机器-->
<env-loader>          <!--设置环境变量-->
</launch>               <!--根标签结束-->

3.1、<node>

 The node tag is the core part of the launch file, defined as follows:

<launch>
    <node pkg="包名1" type="可执行文件1" name="节点名1"/>
    <node pkg="包名2" type="可执行文件2" name="节点名2"></node>
    ...
</launch>

Among them, if the type is written in Python , it is the .py file, and if it is written in C++ , it is the name of the compiled executable file. It should be noted that this launch file does not start in order for the nodes in it to start. In addition to these three required parameters, there are some optional parameters:

<launch>
    <node pkg="" type="" name="" respawn="true" required="true" launch-prefix="xterm -e" output="screen" ns="namespace" />
</launch>

respawn: if the node is shut down, whether to automatically restart
required: if the node is shut down, whether to shut down all other nodes
launch-prefix: whether to open a new window to execute
output: the default is stored in the log file, you can set it to display on the screen
ns: Classify nodes into different namespaces , that is,addthe prefix specified by ns in front of the node name . In order to realize this kind of operation,defining node name and topic name in the node source file , that is, without the symbol /.

3.1.1. Calculation graph source

In ROS, the calculation graph source refers to the collective name of topics, nodes, services, and parameters. Each computation graph source is identified by a short string called the computation graph source name. The name of the calculation graph source is as follows:
Basic name: For example, topic
global name: the name of the calculation graph source starting with "/". For example, /A/topic
relative name: Computation graph source name without "/" at the beginning of the name. For example, A/topic
private name: the source name of the calculation graph starting with the tilde symbol "~". For example, ~topic
anonymous name: Computational graph source without name.
Code like this when publishing and subscribing:

ros::init(argc, argv, "publish_node");
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<std_msgs::string>("topic",1000);

3.2、<remap>

Pass the name remapping parameter to the ROS node without setting the parameter property of the node.
Topics are divided into publishing and subscribing
. Publishing topics:

<node pkg="pub_node" type="pub_node" name="pub_node">
    <remap from="/pub_topic" to="/new_topic" />
</node>

Here is the topic /pub_topic published by the pub_node node is mapped to /new_topic

Subscribe to topics:

<node pkg="sub_node" type="sub_node" name="sub_node">
    <remap from="/sub_topic" to="/turtle" />
</node>

Here is the sub_topic name that subscribes to other people's topics /turtle is mapped to the sub_node node , that is, the topics published by others are mapped to the topics you subscribe to.

3.3、<include>

Include another launch file, which is equivalent to the nesting of launch files, and the file parameter can be specified as the full path

<include file="path-to-launch-file" />

Of course, for better portability, you can use the find command instead:

<include file="$(find package-name)/launch-file-name" />

The advantage of this is that even if the main controller is replaced, as long as the same package is installed, the corresponding path can be found. Sometimes, the nodes introduced by another launch may need to be named uniformly, or node names with similar characteristics, such as /my/gps, /my/lidar, /my/imu  have a unified prefix, which is easy to find. You can set the namespace ns attribute to achieve, the command is as follows:

<include file="$(find package-name)/launch-file-name " ns="my" /> 

3.4、<arg>

Parameters can be reused, three common ways of writing

<arg name="foo">                          <!--只定义,不赋值-->
<arg name="foo" default="1">              <!--默认值-->
<arg name="foo" value="1">                <!--固定值-->

Other common methods of assignment:
command line assignment
roslaunch package_name xxx.launch arg1:=v1 arg2:=v2

variable substitution

1. $(find pkg): For example, $(find rospy)/manifest.xml If possible, this package-based path setting is strongly recommended
2. $(arg arg_name): Set the default value first, and if there is no additional assignment, just Use this default value,
such as

<arg name="gui" default="true" />
<!-- 如果没有额外的赋值,就用这个默认值 -->
<param name="use_gui" value="$(arg gui)"/>

You can also use the command line assignment

<node pkg="包名" type="可执行文件" name="节点名" args="$(arg a) $(arg b)" />

In this way, args can be assigned when starting the launch file : roslaunch package name file_name.launch a:=1 b:=2

3.5、<param>

Unlike arg , the param here is shared, and its definition is similar

<param name="publish_frequency" type="double" value="10.0" />

The values ​​here, in addition to the above, can also come from files.

<param name="参数名" textfile="$(find pkg)/path/file"/>
<param name="参数名" command="$(find pkg)/exe '$(find pkg)/arg.txt'"/>
<param name="参数名" type="yaml" command="cat '$(find pkg)/*.yaml'"/>

In addition to defining in the global scope, it can also be defined in the node node:

<node name="node1" pkg="pkg1" type="exe1">
    <param name="param1" value="False"/>
 </node>

You can view all params by command: rosparam list
Then the above will appear as follows:

/publish_frequency
/node1/param1 # The namespace prefix will be automatically added here. It should be noted that although the namespace is added before the name, it is still in the global scope.

3.6、<rosparam>

The previous param is obtained through value, textfile, and command , and the content of a single param is returned. Rosparam can be operated in batches, and also includes some commands for setting parameters, such as dump, delete , etc.
Let’s look at its usage
load: From YAML Load a batch of param in the file:

<rosparam command="load" file="$(find rosparam)/example.yaml" />

delete: delete a param

<rosparam command="delete" param="my_param" />

assignment operation

<rosparam param="my_param">[1,2,3,4]</rosparam>

it's ok

<rosparam>
a: 1
b: 2
</rosparam>

Similarly, this rosparam can also be placed in the node.

3.7、<group>

If you want to perform the same settings on multiple nodes, such as all in the same specific namespace, remap the same topic, etc., you can use this group grouping.

<group ns="rosbot">
    <remap from="chatter" to="talker"/>       # 对该组中后面的节点都有效
    <node ... />
    <node ... >
        <remap from="chatter" to="talker1"/>  # 还可以对单个节点重新设置
    </node>
</group>

From the perspective of these startup nodes, the design of ROS is very loosely coupled, which is a very good design for joint collaboration, and the crash of a single node will not affect other nodes, which is very important for debugging and maintenance. Advantage.

Guess you like

Origin blog.csdn.net/weixin_41896770/article/details/132207097