Common components in ROS (two)-TF coordinate transformation

Common components in ROS (two)-TF coordinate transformation

Overview

Coordinate transformation is a very basic and also very important concept in robotics. There are often a large number of component elements in the robot body and the working environment of the robot. The position and posture of different components are involved in robot design and robot application, which requires the introduction of the concept of coordinate system and coordinate transformation.
Coordinate transformation is a basic function commonly used in robot systems. The coordinate transformation system in ROS is maintained by the TF function package.

1. TF function package

TF is a function package that allows users to track multiple coordinate systems over time. It uses a tree data structure to buffer and maintain the coordinate transformation relationship between multiple coordinate systems according to time. It can help developers at any time and in the coordinate system. Complete the transformation of coordinates such as points and vectors in the middle.
Insert picture description here

A robot system usually has many three-dimensional coordinate systems, and they will change over time, such as the world coordinate system (World Frame), the base coordinate system (Base Frame), the mechanical gripper frame (Gripper Frame), and the robot head Coordinate system (Head Frame) etc. TF can track these coordinate systems as the axis of time, and allows developers to request the following types of data:

  • 5 seconds ago, what was the relationship between the robot head coordinate system and the global coordinate system?
  • Where is the position of the object gripped by the robot relative to the center coordinate system of the robot?
  • Where is the position of the robot center coordinate system relative to the global coordinate system?

TF can be operated in a distributed system, that is, all coordinate transformation relationships in a robot system are available for all node components, and all nodes subscribing to TF messages will buffer a copy of all coordinate system transformation relationships Data, so this structure does not require a central server to store any data.
To use the TF function package, the following two steps are required:
1) Monitor TF transformation
Receive and cache all coordinate transformation data released in the system, and query the required coordinate transformation relationship from it.
2) Broadcast TF transformation
The coordinate transformation relationship between broadcast coordinate systems in the system. There may be multiple different parts of the TF transformation broadcast in the system, and each broadcast can directly insert the coordinate transformation relationship into the TF tree without synchronization.

Two, TF tools

Although the coordinate system is a basic concept, it is not easy to imagine because it involves transformations between multiple spaces, so TF provides a wealth of terminal tools to help developers debug and create TF transformations.
1. tf_monitor
The function of the tf_monitor tool is to print the release status of all coordinate systems in the TF tree, and you can also check the release status between the specified coordinate systems by inputting parameters.

tf_monitor
tf_monitor <source_frame> <target_frame>

2. tf_echo
The function of the tf_echo tool is to view the transformation relationship between the specified coordinate systems. The format of the command is as follows:

tf_echo <source_frame> <target_frame>

3. static_transform_publisher
The function of the static_transform_publisher tool is to publish the static coordinate transformation between two coordinate systems, and the relative position of these two coordinate systems does not change.
4. view_frames
view_frames is a visual debugging tool that can generate pdf files to display the information of the entire TF tree. How the command is executed:

rosrun tf view_frames

Then use the following command, or use a pdf reader to view the generated pdf file.

evince frames.pdf

Three, TF in the turtle routine

Fourth, create a TF broadcaster

Realization function: Create TF broadcaster, create coordinate transformation value and publish coordinate transformation in real time.
Programming ideas:
1. Initialize ROS node and subscribe to turtle's position message;
2. Loop waiting for topic message, and enter the callback function after receiving it. This callback function Used to process and publish coordinate transformation;
3. Define a broadcaster inside the callback function;
4. Create coordinate transformation values ​​according to the received position information of the turtle;
5. Publish coordinate transformation through the defined broadcaster

Five, create a TF listener

Realization function: Create a TF monitor, create a second turtle, monitor coordinate transformation and issue motion control instructions to make the second turtle move to the first turtle.
Programming ideas:
1. Initialize the ROS node and register the node information with the MASTER;
2. Generate a second turtle through the service call;
3. Create a speed control publisher for turtle2;
4. Create a tf listener and monitor turtle2 relative to turtle1 Coordinate transformation;
5. Issue speed control commands according to coordinate transformation;

Six, achieve the effect

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45661757/article/details/112769158