ROS1 Learning 11 Coordinate System tf Management System Introduction and Demo Example

The coordinate system is a concept that we are very familiar with and is also an important foundation in robotics. In a complete robot system, there will be many coordinate systems. How to manage the positional relationships between these coordinate systems?
ROS provides us with a coordinate system management artifact-TF.
Insert image description here
For example, in a robot in the form of a robotic arm, the location where the robot is installed is called the base coordinate system Base Frame, the reference system of the robot's installation location in the external environment is called the world coordinate system World Frame, and the robot's end gripper The position is called the tool coordinate system, and the position of the external manipulated object is called the workpiece coordinate system. During the process of the robot arm grabbing external objects, the relationship between these coordinate systems also changes.

1. Coordinate transformation in robots

The core of robot kinematics describes the transformation between any two vectors in any two coordinate systems. A 4×4 transformation matrix (Transformation Matrices) can be used to describe its translation and rotation changes.
The transformation matrix includes information about the rotation matrix (Rotation Matrix) and positional movement (Translation) information

Insert image description here

2. TF function package

A robot system usually involves many coordinate system operations, which inevitably involves a large number of matrix operations. We can use TF(Transform)功能包 in ROS to solve the problem.

Insert image description here

Features of the TF function package: By default, it can record the position relationship of all coordinate systems of the robot within 10 seconds.

Insert image description here

How to implement TF coordinate changes?

  • Broadcast TF transformation
  • Monitor TF transformation

After ROS Master is started and TF is started, a data structure called "TF Tree" will be maintained in the background. All coordinate systems are stored in this tree structure through a tree structure. When there is a node that wants to query the relationship between two coordinate systems, it can be obtained directly by querying this TF Tree.

For example, this TF example:

This car with lidar,车体是以base_link is the coordinate system, 激光雷达是以base_laser is the coordinate system, you can see that base_laser is base_link to the x-axis It has been translated by 0.1m, and it has been translated by 0.2m towards the z-axis, but there is no translation on the y-axis.

When base_laser measures that the distance from the wall is 0.3m, that is, the vector (0.3,0,0), the data transformation operation between coordinate systems can be performed based on the TF tree at the bottom of the figure, thereby calculating the relative and measured values ​​of base_link. Relative vector from the point (0.4,0,0.2).

Insert image description here

That is to say, you don’t need to calculate the position detection of two things, calculate one of them, and then calculate the coordinate position of the other part based on their relative difference.

3. Little turtle following experiment

We use a small program to implement the experiment of a small turtle following another small turtle, and use a visual method to understand the transformation of the coordinate system

Insert image description here
In this experiment, we first generate a little turtle, and then generate a new little turtle. The new little turtle will automatically follow the old little turtle until they overlap.

3.1 Start the experiment
Before conducting the experiment, since the noetic version has pre-made this program, but running it directly will report an error. The reason is the pointing problem of the python interpreter. Let's first Open a terminal and enter the following command:

cd /usr/bin/
sudo rm -r python #出现rm -r 找不到文件的忽略即可
sudo cp python3 python

After execution, we can run this program:

roslaunch turtle_tf turtle_tf_demo.launch

Start keyboard control

 rosrun turtlesim turtle_teleop_key

After opening it, we will generate two little turtles. We control one of the little turtles through the keyboard, and the other will automatically follow.

Insert image description here

Insert image description here
3.2 View the current TF tree

We can view the current TF number and see the relationship between coordinate systems:

rosrun tf view_frames

However, if you run it directly, an error will be reported and the pdf file cannot be generated.

Insert image description here

We open the error folder as shown in the picture and add this sentence as shown:

Insert image description here

Run again:

rosrun tf view_frames

The pdf file was successfully generated:

Insert image description here

We can see that this tree shows the positional relationship between the current coordinate systems. turtle1 and turtle2 change relative to the world coordinate system.

3.3 ​​Visualization of relative coordinate positions
3.3.1 tf_echo
If we want to see the relative transformation relationship between two little turtles, we can enter:

rosrun tf tf_echo turtle1 turtle2

Insert image description here
If we control the little turtle to move, the position will change:

Insert image description here
3.3.2 rviz
We can open the rviz tool:

rosrun rviz rviz -d `rospack find turtle_tf` /rviz/turtle_rviz.rviz

After opening the interface, select world in the Fixed Frame above
Add TF in the add in the lower left corner. You can see three coordinate systems.

Insert image description here

Finally, control the movement of the little turtle, the coordinate system changes, and then the origin of turtle2 of the coordinate system will be close to the origin of turtle1

Insert image description here
The operation of the transformation matrix on the left in the figure below is actually the essence of coordinate movement. The product of the transformations of the two coordinate systems relative to the world coordinate system can determine the relative transformation relationship between the two coordinate systems.

Insert image description here

The center point position of rviz corresponds to the lower left 0.0 point of the little turtle
Insert image description here

There is a simple cognitive concept. Most of the above comes from this article. The article does not explain how to control the movement of a small turtle. I will make a supplement.
https://blog.csdn.net/weixin_56197703/article/details/127098905

Guess you like

Origin blog.csdn.net/hai411741962/article/details/134374879