Matlab and ROS---TF coordinate system (7)

0. Introduction

We have talked about the most basic communication mechanism and how to use these communications in Matlab. In the following, we will mainly introduce the use of the most commonly used TF coordinate system in ROS in Matlab. tf is distributed, so all coordinate frame information is available to every node in the ROS network. So this section is to lead readers to familiarize themselves with how to use ROS's TF coordinate system in Matlab

1. The concept of TF

To create a realistic environment for this example, use exampleHelperROSStartTfPublisher to propagate a few transformations. Here the pose of the camera mounted on the robot is represented by a transformation.

Three coordinate coordinate systems are defined in this transformation tree:

  1. Robot Basic Framework (robot_base)
  2. Camera mounting point (mounting_point)
  3. The optical center of the camera (camera_center)

Two transformations are published at the same time:

  1. Conversion from robot mount to camera mount point
  2. Transformation from mount point to camera center
exampleHelperROSStartTfPublisher

A visual representation of the three coordinate coordinate systems is shown below

insert image description here
Here, the x, y and z axes of each frame are represented by red, green and blue lines respectively. The parent-child relationship between coordinate frames is shown by a brown arrow pointing from the child frame to the parent frame.

Create a new transition tree object using the rostf function. You can use this object to access all available transformations and apply them to different entities.

tftree = rostf

tftree =
TransformationTree with properties:
AvailableFrames: {0x1 cell}
LastUpdateTime: [0x1 Time]
BufferTime: 10
DataFormat: ‘object’

Once the object is created, it starts receiving tf transforms and buffers them internally. Leave the tftree variable in the workspace so it continues to receive data.

Pause to ensure all transitions are received.

pause(2);

You can see the names of all available coordinate frames by accessing the AvailableFrames property.

tftree.AvailableFrames

ans = 3x1 cell
{‘camera_center’ }
{‘mounting_point’}
{‘robot_base’ }

Three coordinate frames are shown here, describing the relationship between the camera, its mount point, and the robot.

2. Get TF coordinate system

Now TF transformations are available and they can be checked at the same time. Any transformation is described by a ROS geometry_msgs/TransformStamped message, which has translation and rotation components in it.

Retrieves the transformation describing the relationship between the mount point and the camera center. Use the getTransform function to do this.

mountToCamera = getTransform(tftree, 'mounting_point', 'camera_center');
mountToCameraTranslation = mountToCamera.Transform.Translation

mountToCameraTranslation =
ROS Vector3 message with properties:
MessageType: ‘geometry_msgs/Vector3’
X: 0
Y: 0
Z: 0.5000
Use showdetails to show the contents of the message

quat = mountToCamera.Transform.Rotation

quat =
ROS Quaternion message with properties:
MessageType: ‘geometry_msgs/Quaternion’
X: 0
Y: 0.7071
Z: 0
W: 0.7071
Use showdetails to show the contents of the message

mountToCameraRotationAngles = rad2deg(quat2eul([quat.W quat.X quat.Y quat.Z]))

mountToCameraRotationAngles = 1×3
0 90 0

Here it means that relative to the installation point, the camera center is located at a position of 0.5 meters along the z-axis and rotated 90 degrees around the y-axis.

3. Publish the TF coordinate system

…For details, please refer to Gu Yueju

Guess you like

Origin blog.csdn.net/lovely_yoshino/article/details/128308309