Robot TF coordinate system transformation and application of some visualization tools

TF coordinates are a very important concept in ROS, because when the robot is doing daily operation tasks, it needs to know its location and orientation at all times, and the robot is a collaborative task composed of many nodes . For each component, We need to know its pose (position and orientation) , which makes the coordinate system a very important issue.
The function of TF is to convert the coordinates of the point in other coordinate systems. For example, taking a robot as an example, two coordinate systems are defined. One coordinate system takes the center of the robot's mobile platform as its origin, which is called the base_link reference system, and the other coordinate system takes the center of the laser radar as its origin, which is called the base_laser reference system. Of course This naming needs to be unique. Use TF coordinate conversion to coincide with the base_laser reference system and the base_link reference system, so that the robot's own position can be accurately known, making it easier to proceed with the next operation.

1. Overview of terminology

So when introducing the coordinate system, you will often see terms such as position, orientation, pose, etc. Let us first introduce a few terms in the three-dimensional world: Position: It is a
three -dimensional vector (x, y, z), used for Indicates how far it has moved along each axis relative to the origin.
Orientation: It is also a three-dimensional vector (roll, pitch, yaw), used to represent how much it has rotated around each axis.
Pose: Put position and orientation together, a pair (position, orientation) represents a pose. This pose with six dimensions (three-dimensional displacement, three-dimensional rotation) becomes a 6D pose .
Given the pose between the two, we can transform the data in the two coordinate systems. This transformation is usually some matrix multiplication. Some poses are dynamic, and some positions are fixed. For example, the laser radar fixed on the robot is relatively fixed; while the pose of the manipulator is constantly changing because it needs to move, rotate, etc. and do some Grab action. In order to manage these coordinate systems and transformations, the tf (abbreviation for Transform) package
was designed to implement it, using a distributed approach and using ROS topics to share transformed data. Any node can publish the current information of certain transformations, and any node can subscribe to the transformed data to obtain all transformation relationships between various parts of the robot from different publishing sources.

2. tf coordinate system

For a powerful system, tf will be more complicated and more likely to make mistakes, so there are many tf- related inspection and debugging tools to help you understand what is happening. Let’s take a look at what visualizations are available. Tools are available.

2.1、view_frames

Let’s start the turtle example first. You can ignore the previous installation. You can also use sudo apt install ros-melodic-turtle-tf to install it. For the installation of ros, it is recommended that you read the article introduced earlier: Ubuntu18.04 Version installation of ROS and error handling methods

start turtle

roslaunch turtle_tf turtle_tf_demo.launch

Start keyboard operation

rosrun turtlesim turtle_teleop_key

Then open a terminal and run the command: rosrun tf view_frames

the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'
Listening to /tf for 5.0 seconds
Done Listening
dot - graphviz version 2.40.1 (20161225.0304)

Detected dot version 2.40
frames.pdf generated

A pdf file frames.pdf of a coordinate system is generated here . The frames seen later are also expressed as coordinate systems.

2.2、rqt_tf_tree

For the above view_frames command, the current coordinate system is saved after running. However, such saving is offline and cannot reflect the changing coordinate relationships in real time.
Let’s change the command: rqt_tf_tree , which can display the tree structure of the tf coordinate system.

rosrun rqt_tf_tree rqt_tf_tree

Running the above command will pop up a visual interface, as shown below:

As you can see, the recording time, the broadcast (release) node corresponding to the two turtles, the average rate, buffer size, the latest and oldest conversion time are displayed. It can also be highlighted. When the mouse is placed on the node, the relevant node will be displayed. Different colors.
We can operate the turtle, and then click refresh in the upper left corner , and we will see that the speed and so on have changed, which looks more intuitive. As shown below:

The tree-structured coordinate system established by TF has no closed loop in the entire coordinate system . That is to say, each coordinate system can only have one parent coordinate system, but can have multiple child coordinate systems.

2.3、tf_echo

Command format: rosrun tf tf_echo <source_frame> <target_frame> 
The information displayed is the rotation and translation transformation from source_frame to target_frame .

See the relationship between two turtle reference frames

rosrun tf tf_echo turtle1 turtle2

At time 1652155224.053
- Translation: [0.000, 0.000, 0.000]
- Rotation: in Quaternion [0.000, 0.000, 0.893, 0.450]
            in RPY (radian) [0.000, -0.000, 2.208]
            in RPY (degree) [0.000, -0.000, 126.509]
At time 1652155225.061
- Translation: [0.000, 0.000, 0.000]
- Rotation: in Quaternion [0.000, 0.000, 0.893, 0.450]
            in RPY (radian) [0.000, -0.000, 2.208]
            in RPY (degree) [0.000, -0.000, 126.509]
At time 1652155226.053
- Translation: [0.000, 0.000, 0.000]
- Rotation: in Quaternion [0.000, 0.000, 0.893, 0.450]
            in RPY (radian) [0.000, -0.000, 2.208]
            in RPY (degree) [0.000, -0.000, 126.509]

2.4、static_transform_publisher

Static coordinate transformation between two coordinate systems. The relative positions of the two coordinate systems do not change. For example, the lidar and IMU inertial measurement modules on unmanned vehicles are basically fixed, so you can use static_transform_publisher to publish their coordinate transformations.
The command format is as follows:
The first command format:

static_transform_publisher x y z yaw pitch roll frame_id child_frame_id period_in_ms

The second command format:

static_transform_publisher x y z qx qy qz qw frame_id child_frame_id period_in_ms

The above two formats require setting the offset and rotation
parameters of the coordinates: both use coordinate displacements relative to the xyz three-axis.
Rotation parameters: The first command format uses three angles of yaw pitch roll in radians (yaw is the yaw angle of rotation around the x-axis, pitch is the pitch angle of rotation around the y-axis, and roll is the rotation around the z-axis Roll angle )
The second command format uses quaternions to express the rotation angle.
The period_in_ms publishing frequency is in milliseconds. Generally, 100ms, which is 0.1 seconds, is more appropriate.

Examples of usage methods in launch are as follows:

<launch>
    <node pkg="tf" type="static_transform_publisher" name="link1_broadcaster" args="1 0 0 0 0 0 1 link1_parent link1 100" />
</launch>

2.5、roswtf

roswtf is a plugin that analyzes your current tf configuration and tries to identify common problems.
For example, when I enter a command, my current status displays the following information, and errors and other conditions will be highlighted:

the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'
No package or stack in the current directory
================================================================================
Static checks summary:

Found 1 error(s).

ERROR ROS Dep database not updated: Please update rosdep database with 'rosdep update'.
================================================================================
Beginning tests of your ROS graph. These may take a while...
analyzing graph...
... done analyzing graph
running graph rules...
connection to [/tf_echo_1652154589994246734] timed out
... done running graph rules

Online checks summary:

Found 1 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING The following node subscriptions are unconnected:
 * /tf_echo_1652154589994246734:
   * /tf_static
 * /turtle_pointer:
   * /tf_static


Found 2 error(s).

ERROR Could not contact the following nodes:
 * /tf_echo_1652154589994246734

ERROR Errors connecting to the following services:
 * service [/tf_echo_1652154589994246734/set_logger_level] appears to be malfunctioning: Unable to communicate with service [/tf_echo_1652154589994246734/set_logger_level], address [rosrpc://jetson-desktop:54551]
 * service [/tf_echo_1652154589994246734/get_loggers] appears to be malfunctioning: Unable to communicate with service [/tf_echo_1652154589994246734/get_loggers], address [rosrpc://jetson-desktop:54551]

3. tab key

The tab key can complete the code or display the unfinished commands related to the entered command. Double-clicking the tab key can improve efficiency and ensure that the entered command is correct.
For example, enter: rosrun rqt_    and then double-click the tab key, various nodes starting with rqt will automatically appear:

rqt_action rqt_logger_level rqt_robot_monitor
rqt_bag rqt_moveit rqt_robot_steering
rqt_bag_plugins rqt_msg rqt_runtime_monitor
rqt_console rqt_nav_view rqt_rviz rqt_dep
rqt_plot rqt_service_caller
rqt_graph rqt_pose_view rqt_shell
rqt_gui publisher rqt_srv
rqt_gui_cpp rqt_py_common rqt_tf_tree
rqt_gui_py rqt_py_console rqt_top
rqt_image_view rqt_reconfigure rqt_topic
rqt_launch rqt_robot_dashboard rqt_web

If there is a lot of content displayed, there will also be a prompt. For example, I just type: rosrun and then double-click the tab key
to display all 229 possibilities? (y or n)
to choose whether to continue displaying.

If the entered command is a deterministic match, double-clicking the tab key at this time will automatically complete the rest.
For example, enter: rosrun rqt_gu.
Double-clicking the tab key will automatically complete it into rosrun rqt_gui . If we double-click the tab key again, all matching nodes starting with rqt_gui will be listed:

rqt_gui rqt_gui_cpp rqt_gui_py

4. Visualization tools

4.1、rqt_graph

rqt_graph can visualize the calculation graph. Enter the command: rosrun rqt_graph rqt_graph.
If you run this command directly without starting the node manager, an error will be reported:
Could not find ROS master, Either start a 'roscore' or abort loading the plugin.

So before we do this, we first start the node manager, using turtles as an example, and then run the above command, as shown below: 

You can intuitively see the two turtle nodes, which contain topics such as pose , keyboard operation, etc., and then the poses release information through their respective broadcasts. The one in the middle is the topic of the tf coordinate system that we focus on in this section :/ tf (with subscription and publishing functions) to transform coordinates, and finally output through the node /turtle_pointer to /rosout .
We can also get the nodes in the graph through the command: rosnode list

/rosout
/sim
/teleop
/teleop_turtle
/turtle1_tf_broadcaster
/turtle2_tf_broadcaster
/turtle_pointer

Nodes can be seen as applications corresponding to respective ports in the website, so we can also view them like pinging the network:
rosnode ping /rosout

rosnode: node is [/rosout]
pinging /rosout with a timeout of 3.0s
xmlrpc reply from http://jetson-desktop:46881/    time=1.574039ms
xmlrpc reply from http://jetson-desktop:46881/    time=1.164913ms
...

rosnode ping /sim

rosnode: node is [/sim]
pinging /sim with a timeout of 3.0s
xmlrpc reply from http://jetson-desktop:36081/    time=1.548052ms
xmlrpc reply from http://jetson-desktop:36081/    time=1.078129ms
...

4.2、rqt_topic 

rqt_topic is a plug-in for viewing topics. It can know the specific real-time changes in the topics of each node. Enter the command:

rosrun rqt_topic rqt_topic

As shown below:

You can see that the detailed information of each topic includes Type message category, Bandwidth bandwidth, Hz frequency, and Value value.
Let’s click on the /tf coordinate system to see what attributes are in it, as shown below:


As you can see, the parent coordinates and child coordinates are specified. Of course, the main thing is the conversion of coordinates. There are two timestamps, one in nanoseconds and one in seconds. 

 4.3、rqt_publisher

rqt_publisher is used to publish arbitrary messages with fixed or calculated field values. Enter the command:
rosrun rqt_publisher rqt_publisher
will pop up the interface as shown below:

You can click the drop-down box to select both topic topic and type message data type, enter the frequency, and then click the + sign to add it. As shown below: 

Then you can modify the value corresponding to the expression field inside and perform input debugging manually.

4.4, see

rviz is a graphical tool that comes with ROS , which can conveniently perform graphical operations on ROS programs. Enter the command: rviz
as shown below:

It is mainly divided into 5 functional areas, as marked in the picture. Among them, Set initial pose , Set target pose , and Publish location point in the toolbar : are generally used during map navigation.

Add display operation as shown in the figure:

Click the Add button in the lower left corner , an interface will pop up, and then you can select " By display type " to add through the display type, but you need to modify the corresponding topic yourself before the coordinate system can be displayed; or select " By topic " to add through the topic method, it can be displayed normally if added directly. Finally click the OK button in the lower right corner

Finally, a warm reminder, when using ROS core tools and other Linux commands, always remember to hit the tab key , which can save a lot of time.

Guess you like

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