To continue studying the features offered by the TF2 Library.
In this lesson, we will explore some tools and nodes that are already developed and available in this
library, offering additional analytical functionalities for the use and management of reference frames.
To use these tools, let's start by launching the visualization of the robot in our office.
So let's open a new terminal and go to the workspace.
Here, let's source the file setup bash and then let's start the robot visualization in our VS.
So let's launch from the Arduino bot description package.
The display dot launch.
So this will enable the visualization in.
And now that we can correctly visualize the robot and the frames, we can use a node that is available
in the TF2 library that allows us to graphically visualize the frame tree and also its connections.
So if we split a terminal, so let's open a new terminal and we take a look at the list of the currently
available topic in Ros2 with the command Ros2 topic list, we can see that among these topics there
are DTF where the dynamic transformations are published and the TF static topic where the static transformation
and published.
Let's see which nodes are currently interacting with these two topics.
So who is publishing this information that is then visualized in Arviz?
We can use the command Ros2 Topic info.
For example, let's take a look at the topic TF and let's also use the verbose flag to see the names
of the nodes.
So now for example, we can see that there is only one node that is publishing and this is exactly the
robot estate publisher node.
So the one that was reading the Urdf model of our robot was interpreting it and is publishing the respective
transformations.
We can also see, which are the messages that currently the robot estate publisher is publishing within
the TF and the TF static topic and we can use the command Ros2 topic echo.
And for example, let's read for the moment the TF topic.
Let's make this one a little bigger.
And so in this topic, we can see that constantly are published messages that define the position of
each reference frame relative to the previous one.
So let's stop this one for a moment for a little bit.
In order to examine the structure of these messages.
So each message that is published within the topic contains a list of transformation.
So here it begins, a new message.
So as we can see, it begins with an header.
And so it has a list of headers.
So there is a list of transformation.
For example, we can see this one that expresses the transformation between the base plate and the base
link.
And so we can also see that here there are the rotation values.
So this is basically the rotation matrix that expresses how the base plate is oriented with respect
to the base link and also the translation that is the translation vector.
We can see that the rotation that is representing the orientation.
So this one has four components that are X, Y, Z, and W.
So actually, this is because the convention that is used in TF2 library and in general in Ros2 is expressing
the orientation of any two reference frames using the quaternion.
And this is a topic that we will study later on in the course.
For the moment, let's use another node from the TF2 Tools library that allows us to graphically visualize
the frames and their connection in a tree structure.
So let's use the command Ros to run and from the TF2 Tools library.
Let's start the node that is called view frames.
So let's press enter and this node will listen for all the frames that are published within the TF and
TF static topic for a few seconds and will generate a graph that contains all the frames and also their
connections.
So once it finished we can see that it created two new files.
So it created these two files.
And also we can take a look at how this file looks likes.
So let's use the evidence.
And as this is a PDF, let's open it in this file.
Let's zoom a little bit back.
We have a simple and immediate and intuitive visualization of all the frames that are currently available
in Ros.
So all the frames that are published both in the TF and in the TF static topic.
For example, we can see that the base link.
So this one is connected to the base plate and that the note that is in charge of publishing this transformation
is publishing it with a rate of ten hertz.
So this is the average rate at which they are published.
Also, we can see that, for example, the transformation between the word and the base link is published
with an incredibly high average rate.
This is because actually this is a static transform.
So as you will see, all the transform that are published in the static topic in this graph will have
an average rate of 10,000.
Let's close this PDF and now let's take a look to another useful tool that is available in the TF2 library
that is called Echo.
This allows us to display the transformation matrix between any two frames in the Tree of Connections.
So to launch it, let's use the command Ros to run.
And from the TF2 Ros package, let's start the TF to echo Node and we need to provide to this node the
names of the two reference frame from which we want to know the transformation matrix.
For example, we want the one from the base link to the horizontal arm.
So let's press enter.
And here in the terminal we can see that the translation and the rotation values of the transformation
between the two frames that we have indicated are continuously printed in the terminal at our regular
time intervals.
And also we can see that the rotation.
So here the rotation is expressed in terms of quaternion, in terms of rpy, both in radians and in
degrees, if we take a look again.
So if we open again the pdf.
That was created.
So this one with Evans.
And let's open the PDF.
We can see that the two frames from which we asked to transform from.
So basically the base link and the horizontal arm, this one and this one are not directly connected
by a transformation.
However, there is a chain.
There is a chain that is connecting the base link and the horizontal arm.
And this chain passes through the base plate, the forward drive arm, and then reaches the horizontal
arm.
This is possible because behind the scenes, the TF2 library and also all the necessary calculations
to compose intermediate transformation matrices and returns the resulting transformation matrix.
As long as there is a chain or a sequence of transformation matrices that connects one reference frame
to another, the TF2 library can calculate the resulting transformation matrix.
So basically, to solve the forward kinematic problem, it becomes as simple as running again the command
TF2 ACO, and this time asking for the transformation between the world reference frame and the low
support reference frame.
So as we press enter, so with this, basically we are solving the forward kinematic problem.
And here we can also see the full transformation matrix.
So this is the rotation, this is the translation vector and this is the full transformation matrix.
Also, we can see that if we take the joint state publisher.
So let's take the joint state publisher.
Let's keep this node running and let's move a little bit.
The robot with the joint state publisher.
We can see that while we move the robot, the values of the transformation are changing and so are constantly
update.
And so if we move the position of the joints, we are moving, of course, the position of the gripper.
And so the transformation is updated.
And so the transformation matrix is recalculated with the new values of the joint angles.
In this way with a bit of mathematics and the help of the TF2 library, we have solved the problem of
the forward kinematics and we can determine at any moment in time the position of the gripper of the
robot in the space.