3 Common commands and tools

3.1 Start node mode

3.1.1 launch file

There are at least two ways to start a launch file with the roslaunch command:

  1. start with the ros package path

The format is as follows:

  1. directly give the absolute path of the launch file

The format is as follows:

No matter which of the above methods is used to start the launch file, parameters can be added later. The more common parameters are

or

When the roslaunch command runs, it will first detect the system's rosmasterWhether to run, if already started, use the existing rosmaster; if not started, it will start first rosmaster, and then execute the settings in the launch file to start multiple nodes at one time according to our pre-configured configuration.

It should be noted that the launch file does not need to be compiled, and it can be run directly in the above manner after setting it up.

3.1.2 rosrun

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:

To start a node, rosrun + package name + node name; the rosrun method can only run one node at a time.

rosrun will look for a package's executable program named executable, passing in the optional parameter ARGS.

3.1.3 python

If it is python code, you can directly start it in the directory where the py file is located, pay attention to distinguish between python2 and python3.

3.1.4 start a small turtle

After the startup is completed, you can control the movement of the turtle through keyboard input. When operating the keyboard, the cursor must be under the command line [rosrun turtlesim turtle_teleop_key], and click the keyboard [up], [down], [left], [right] to control the small Turtles move.

01

And in the rosrun turtlesim turtlesim_node terminal will print some log information of the small turtle

3.1.5 Start two little turtles

Install feature pack

start up

keyboard control node

image-20210831100729460

At this time, press the keyboard [Up], [Down], [Left], [Right] to drive the little turtle to move; it can be observed that one little turtle follows the movement of the other.

3.2 launch file

3.2.1 Overview

In ROS, a node program can generally only complete a single task with a single function, but a complete ROS robot generally requires many node programs to run at the same time and cooperate with each other to complete complex tasks. Therefore, it is required to start the robot when starting the robot. For many node programs, it is more troublesome if one node is started one by one. Through the launch file and the roslaunch command, multiple nodes can be started at one time, which is convenient for "one-click start", and can set rich parameters.

3.2.1 the format of the file

The launch file is essentially an xml file. In some editors, keywords can be highlighted for easy reading. It can be added in the header or not.

Similar to other xml format files, launch files are also tags written in the form of tags. The main are as follows:

1. Label [node]

The label [node] is the core part of the launch file.

in

Note: roslaunch does not guarantee the startup order of nodes, so all nodes in the launch file should be robust to startup order.

You can also set more parameters, as follows:

In the above command,

The names of the computational graph sources are divided into:

  1. Base name, for example: topic
  2. Global name, for example: /A/topic
  3. Relative name, for example: A/topic
  4. Private name, for example: ~topic

When publishing or subscribing, there is such a line of code

2. Label [remap]

Often appears as a subtag of the node tag and can be used to modify the topic. In many rosnode source files, the received or sent topics may not be specified, but only the input_topic and output_topicInstead, it is necessary to replace the abstract topic name with the topic name in the specific scene in use.

Simply put, the role of remap is to facilitate the application of the same node file to different environments. You can use remap to modify the topic from the outside without changing the source file.

The common usage format of remap is as follows:

3. Label [include]

The role of this tag is to add another launch file to this launch file, similar to the nesting of launch files. Basic format:

The file path above can give a specific path, but in general, for the portability of the program, it is best to use the findThe command gives the file path:

In the above command, $(find package-name)Equivalent to the path of the corresponding package in this machine. In this way, even if other masters are changed, as long as the same package is installed, the corresponding path can be found.

Sometimes, the node introduced by another launch may need to be named uniformly, or the node name with similar characteristics, such as /my/gps, /my/lidar, /my/imu, that is, the node has a uniform prefix, which is easy to find. This can be done by setting ns(namespace) attribute to achieve, the command is as follows:

4. Label [arg]

Through [arg], the parameters can be reused, and it is also convenient to modify multiple places at the same time. [arg] Three common methods:

Assignment via command line

5. Variable substitution

There are two forms of variable substitution commonly used in launch files

E.g:

another example:

After this setting, when starting roslaunch, you can assign values to the args parameter

6. Label [param]

Unlike [arg], [param] is shared, and its value is not limited to value, but can also be a file or even a line of commands.

[param] can be in the global scope, and its name is the original name, or it can be in a smaller scope, such as node, then its global name is in the form of node/param.

For example, define the following param in the global scope

Then define the following param in the node scope

If you use rosparam listList the [param] in the server, then there are

Note: Although the [param] name is prefixed with namespace, it is still in the global scope

7. Label [rosparam]

[param] can only operate on a single [param], and there are only three forms: 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 parameter settings, such as dump, delete, etc.

[rosparam] can also be placed in [node], in this case, node namespace is added before the name of [param].

8. Label [group]

If you want to make the same settings for multiple nodes, such as all in the same specific namespace, remap the same topic, etc., you can use [group]. All common tags can be used in [group] to set, for example

3.3 TF coordinate transformation

tf is a package of functions that allows users to keep track of multiple coordinate systems at any time. tf maintains the relationship between coordinate frames in a real-time buffered tree structure and allows the user to convert points, vectors, etc. at any point in time between any two coordinate frames.

The Tf package is to convert the coordinates of a point in a certain coordinate system into the coordinates of another coordinate system. The sensor can be regarded as a coordinate system, the machine can be regarded as a coordinate system, and the obstacle can be regarded as a point.

After starting two small turtles in [3.1.5], perform the following operations.

3.3.1 Common tools of tf

1. view_frames tool

It can monitor all the tf coordinate systems broadcasted by ROS at the current moment, and draw a tree diagram to represent the connection relationship between the coordinate systems, generate a file named frame.pdf, and save it to the local current location.

2. rqt_tf_tree tool

Although view_frames can save the current coordinate system relationship in an offline file, it cannot reflect the coordinate relationship in real time, so you can use rqt_tf_tree to refresh the display coordinate system relationship in real time

3. tf_echo tool

Use the tf_echo tool to view the relationship between the two broadcast reference frames.

Print the rotation-translation transformation from source_frame to target_frame; for example:

6ade3e4ff88a210b944bb021d6e27e4

4.static_transform_publisher

Publishes a static coordinate transformation between two coordinate systems that do not change their relative positions. Command format:

Use in launch:

5.roswtf plugin

A plugin that analyzes your current tf configuration and tries to find common problems.

3.3.2 Commonly used coordinate systems

The commonly used coordinate system is frame_id, including map, odom, base_link, base_footprint, base_laser, etc.

image-20210831110309963

The map coordinate system is a world-fixed coordinate system with its Z axis pointing up. The pose of the moving platform relative to the map coordinate system should not move significantly over time. The map coordinates are discontinuous, which means that the attitude of the moving platform in the map coordinate system can change discretely at any time. In a typical setup, the localization module continuously recalculates the robot's pose in world coordinates based on sensor monitoring, thereby eliminating bias, but may jump when new sensor information arrives. The map coordinate system is useful as a long-term global reference, but jumps make it a bad reference for local sensing and actuators.

odom is a global coordinate system, which records the current motion posture of the robot through the odometer. The pose of the mobile platform in the odom coordinate system can be moved arbitrarily without any boundaries, so that the odom coordinate system cannot be used as a long-term global reference. The odom topic should be distinguished here, which are two concepts, one is the coordinate system, and the other is the odometer calculated based on the encoder (or vision, etc.). But the two are also related. The pose matrix converted by odom topic is the tf relationship of odom–>base_link. The odom and map coordinate systems are coincident at the beginning of the robot motion. However, they do not coincide over time, and the deviation that occurs is the cumulative error of the odometer. In some packages that calibrate the sensor cooperatively, such as amcl, a position estimation (localization) will be given, which can get the tf of map->base_link, so the deviation between the estimated position and the odometer position is also the coordinate system deviation between odom and map. If your odom calculation is correct, then the tf of map->odom is 0. The odom coordinate system is useful as a short-term local reference, but the offset makes it unusable as a long-term reference.

The coordinate system of the robot body (base) coincides with the center of the robot, and the origin of the coordinate system is generally the center of rotation of the robot.

base_footprint: The origin is the projection of the origin of the base_link on the ground, with a slight difference (different z values).

In the robot system, we use a tree to associate all coordinate systems, so each coordinate system has a parent coordinate system and any child coordinate system, as follows: map --> odom --> base_link The world coordinate system is odom The parent of the coordinate system, the odom coordinate system is the parent of the base_link. While intuitively map and odom should be connected to base_link, this is not allowed because there can only be one parent per coordinate system.

The conversion of odom to base_link is computed and published by the odometry source. However, the location module does not publish map-to-base_link transforms. Instead, the location module first receives the transform from odom to base_link, and uses this information to publish the transform from map to odom.

3.4 rqt (QT tool)

Open a command line window and enter rosrun rqtthen double click Tabkey, you can view the content contained in the QT tool in ROS, as shown in the following figure:

100

Next, let's take a small turtle as an example to briefly introduce several commonly used QT tools:

1. rqt_graph calculation graph visualization

Open the command line window and enter the following command to pop up a dialog window.

101

From the image we can clearly see that /teleop_turtlenode pass /turtle1/cmd_veltopic to /turtlesimnode for data transfer.

/teleop_turtleIt is a node with Publisher function.

/turtlesimIt is a node with Subscriber (subscription) function.

/turtle1/cmd_velA topic for publishers and subscribers to communicate.

2. rqt_topic View topic

104

Through this tool, we can clearly see some real-time changing information of the baby turtles.

3. rqt_publisher

rqt_publisher provides a GUI plugin for publishing arbitrary messages with fixed or computed field values. Open the command line window and enter the following command, a dialog window will pop up.

click TopicThe selection box on the right finds what we need /turtle1/cmd_velTopic, click the plus sign on the right to add it, the display is as follows:

102

4. rqt_plot data drawing

103

6. rqt_console log output

The function of the ROS log (log) system is to allow the program to generate some log messages, display them on the screen, send them to a specific topic, or store them in a specific log file to facilitate debugging, logging, alarming, etc.

serial numbergradeParse
1DEBUGDebug logs for development and testing
2INFOGeneral log, user-visible level information
3WARNWarning message.
4ERRORerror message. Message printed after program error
5FATALFatal error. downtime logging

The log messages in ROS can be divided into 5 levels according to the severity from low to high: DEBUG, INFO, WARN, ERROR, FATAL. As long as the program can run, you don't need to pay attention, but ERROR and FATAL appear to indicate that there is a serious problem with the program that prevents it from running.

105

The log output tool is a part of the ROS logging framework (logging framework), which is used to display the output information of the node. From the figure, we can see that it reminds that the turtle has hit the wall.

C++ Basic API FormatC++ stream API formatPython logging API
ROS_DEBUG("Printed content");ROS_DEBUG_STREAM("Printed content" <<"hello");rospy.logdebug("printed content")
ROS_INFO("Printed content");ROS_INFO_STREAM("Printed content" <<"hello");rospy.loginfo("printed content")
ROS_WARN("Printed content");ROS_WARN_STREAM("Printed content" <<"hello");rospy.logwarn("printed content")
ROS_ERROR("Printed content");ROS_ERROR_STREAM("Printed content" <<"hello");rospy.logerror("Printed content")
ROS_FATAL("Printed content");ROS_FATAL_STREAM("Printed content" <<"hello");rospy.logfatal("Printed content")
7. rqt_reconfigure dynamic parameter configuration

Image source ROS wiki:

reconfigure_gui2

3.5 Rviz

rviz is a graphical tool that comes with ros, which can easily perform graphical operations on ros programs. Its use is also relatively simple.

image-20210831165335203

[Set initial pose], [Set target pose], [Publish location point]: generally used in map building and navigation.

The rviz interface mainly includes the following parts:

1: The 3D view area is used to visually display data. There is currently no data, so it is displayed in black.

2: Toolbar, which provides tools such as viewing angle control, target setting, and publishing location.

3: Display item list, which is used to display the currently selected display plug-ins, and the properties of each plug-in can be configured.

4: Angle setting area, you can choose a variety of observation angles.

5: Time display area, showing the current system time and ROS time.

image-20210831140448530

Step 1: Click the [Add] button. A checkbox will pop up.

Step 2: You can choose to add it through the display type [By display type], but you need to modify the corresponding topic before the coordinate system can be displayed; you can also directly add it by selecting the topic [By topic] and it can be displayed normally.

Step 3: Click [OK].

3.6 ROS common commands

Ordereffect
catkin_create_pkgInformation for creating feature packs
rospackGet information about feature packs
catkin_makeCompile the function package in the workspace
rosdepAutomatically install other packages that feature packages depend on
roscdFunction package directory jump
roscpCopy the files in the feature pack
rosedEditing files in feature packs
rosrunRun the executable in the feature pack
roslaunchrun startup file