OK.
In this material, we will try to apply this transformation mattresses, which contains also rotation
mattresses inside and also, you know, other angles, ends like this into practice by this video,
I would like to show you how much important and how useful can be the concepts that we have learned
in this chapter.
So let's start for in this tutorial.
I will try to I will try to apply what we have learned or simulate the environment in ROS.
As you know, I don't know whether you know or not, but it is very important for you to know or else
or rules because it is used in robotics very widely.
So you have to know this.
This is not an option, but you have to know this if you want to simulate or coordinate robots, or
how can I say or you want to write software for them?
You have to know this because it contains many of the tools that make your job easier in order to write
software for robots or programmed them.
So that's why you have to learn this during the lesson.
I will apply some concepts in our rules, but I will not teach you the rules.
So you have to learn it by yourself because otherwise the course would be very long.
You can learn it in C++, or you can learn it in Python, but I recommend you to learn in Python because
C++ can be a bit difficult.
But if you know C++, it would also be good because indeed you can apply different modes in our different
programming languages and you can communicate between these nodes.
So, OK, without further ado, let's start to see what first we will do, so we will simulate our program
inside gazebo.
So let's first start our environment, or let's start our environment in gazebo.
So Roseland, first, let me source the environment because this is very important if you don't know
what I am doing here.
You can just watch and see that.
How important is that?
Otherwise, if you want to know, you can learn or else.
But the learning curve of arroyos is steep, so it's a bit difficult.
So I would recommend you to learn the process while also watching this course and programs.
So let's start first.
Let's source the environment below.
Set up the marsh, OK, then roast lunch.
I think you have to be here and tim about three to two.
I will use Turtle about three in the simulation.
OK.
T. Both three, you have to and it is a start robot, not lunch.
But OK, let me first launch the environment.
This will launch otherwise total about three months.
Three Gazebo.
So Turtle bought three books, bought lunch.
I will send you or I will upload this launch file and other programs into GitHub so you can download
it from there and use.
OK, first, let's see our environment.
OK, so we have given a robot, which is Turtle Bot three.
This is a very famous robot.
You can what it is differential drive robot.
And this is our object.
So what's our purpose?
OK, this is our object.
So what's our purpose?
Our purpose is to make turtle bots.
Three Robot this robot to follow this object.
This object is dynamic.
I mean, we can change its position and we want the turtle bots three to follow this object.
So if I put it here, it's come to this point.
If I put it here, it come to this point.
Yeah, this can be seen a bit stupid, but it's very important because this is called go to goal behavior
for robots.
What the what do I mean by go to goal behavior?
So in many tasks, for example, in navigation or for searching something or doing something very different,
I don't know.
We have some.
Coordinates and we want the robot to go this.
This is gold, go to gold.
So go to gold, be here.
We just make robot to go to that point, so it simulates that behavior.
So let's start.
And the first let me see in presentation what we want to do.
OK, let's start with this one.
So we are given our robot, which is circle and square.
Our object, what we want for what we will do.
First, we will assign transformations.
Both of these transformations or excuse me, not transformations, but first coordinate frames.
As we have said before, we first have to assign frames for our objects that we are interested in this
case, our robot and our object.
We assign the frames in order to do relations between them.
OK.
So communicate between these frames and know the position and orientation of objects relative to the
robot and the robot relative to object.
OK, then what we want to do, we want we want to find the which is vector between the centers of these
two frames and which is also the distance between the robot and the object.
And also, we want to find Tita why we want to find Peter, because our purpose is first to rotate,
make the orientation of the robot the same as the object's current frame.
And so we want rotated degrees in order to face up with the object.
OK.
And then what?
We want to do it, then we want to apply for the velocity to our robot in order to go that point.
So it's indeed a very easy concept.
So what we are doing.
First, we are correcting our heading angle, which is TITA.
So if our robot watches these side, I mean, if our robot's heading is to decide and the object is
on this side, we first want our robot to watch to have the same orientation with the object.
And then we apply forward velocity in order to account for the distance and come near the object.
So how we will do this task first, we will separate our D vector, or we will project our vector D
onto X and Y axis.
OK, not z axis.
Because as you know, our robot is not a quadcopter or a drone.
It doesn't move in
that dimension.
It moves only in X and Y because it's a differential drive.
It's not flying.
So we have only two dimensions, so we will project on the X, a. y.
And if you remember from our tutorials how we will fund T to A..
So let's see for in order to find Tita Vivo, we use our time to function.
OK.
Item to function.
Um, well, I have a little talk about this one because we have learned it before, so we will use it
on to function and we are given from trigonometry.
You know, we are given d y, d x.
We can find this tita from other countries, but for some reasons we will use it.
And two, I have mentioned these reasons in previous tutorials.
If you want to remember or repeat, you can watch this trial again.
OK.
We are funding to our heading NGOs, and we rotate our robot by to degrees in order to face up with
the AI with our object.
Then how we will calculate deep.
It's very easy from trigonometry.
You know, we will find the this is models of the Vector D. So we are taking a modest more of it, and
this equals the square root of the X squared plus d y squared.
This is our formulas that we need to apply then.
OK, let's come to now.
Uh, the coding part people.
I wrote the code before and this I will send it.
I will attach GitHub link to this so you can download the code and you can analyze by yourself.
OK.
First of all, uh, for this one, we will use this sets our interpreter.
So Python interpreter, because as you know, Python two, there's Python two or Python three and like
that.
So we will use Python to.
OK, so we will import Ross Pay.
Um, as I said before, I will not explain all of this.
I will just explain what we have used here, so we will use the n t f to Ross.
What does t f to t f to is very important in Ross.
What you do is it means relations creates relations between different frames and also the coke leads
these homogeneous transformation matriz or not, it causes homogeneous transformation methods, but
it calculates something like that.
I mean, it calculates orientation and the distance between these two points.
So by using T f two Ross, you can find the relation between two frames, which we need in order to
calculate our T2 and D.
OK.
We will use t f conversions.
I don't know whether we will use.
I think we will not use OK.
Excuse me, it's something that we will not need in this case, but we will.
Let me explain for what is the purpose of this and how we can use this library in this case.
We will use it if we have given or angles we will use to convert it to cotton use.
And I think you remember the reasons why we use Quaternary is instead of angles.
OK.
Also additionally, Alia's angles are quite earnings are applied to inside are also that's why also
we are converting everything else to cotton spunk and then we will use geometry messages.
You will see why we are importing this model or this message.
OK, then we will use gazebo messages for models.
This and you will see y will need also.
OK, let's start from in.
First of all, we need our mode.
Then we subscribe to gazebo models, states where we are subs, why we are subscribing this.
Let's see.
OK.
Ross topic?
Let's see what's our first of all our topics?
Let's see our topics.
As you can see, these are topics that are published or subscribe.
You can subscribe or publish to these topics.
These are the topics created by this software.
I'm in the process.
So, OK, uh, let's see.
We need here.
A gazebo model states why we need gazebo models this.
We need that in order to get the position of our object relative to the autumn frame.
Autumn frame in this case is like world frame.
Yeah, yeah.
There can be some cases in which Adam Frame is different from world frame, and this is changing depending
on map.
However, in this case, autumn frame is the same as our world frame.
As you can see, this is our inertial frame, as we have said before, and these two frames, as you
can see these frame, this frame is our local frames.
First is belong to the robot and the second belongs to the object.
And we want to.
What we want to do is, first of all, we want to find the object's location relative to the ordem frame
located so relative to these inertial frame real world frame.
So that's why we are subscribing to gazebo models, states, gazebo model states.
As you can see, it lets rules, topic echo, uh, slash gazebo model states gazebo model.
This Stopit gazebo models this, as you can see, show us the objects on the roof on our Um, how can
I say on our environment?
As you can see, this is our box.
As you can see, this is total about three Berger.
This is our robot and it gives us their position and orientation.
This is position and orientation of unit box.
This is depending on index because the second or first index is four units bookstore.
The first will be for the position and orientation of unit box.
And the second index is our robot and this is for our robot.
Also, it gives us twist.
Twist Twist is a combination of linear and angular velocity of our objects.
In this case, we will not need that.
We will just need the position and orientation of the object.
We will need only to find the position orientation of objects because turtle bolts three itself.
We can get its position and orientation from by subscribing, it's all on topic, we will say it.
Uh, no.
OK, so we subscribed to this topic.
And as you can see, we have called back for our subscribers.
This is called our handle object posts, so we are going to explain this one.
And this is our callback function, the handle object pause.
And this accepts message from this topic.
This is the message that published by this model states topics topic, and we subscribe this topic for
this message.
So, OK, first of all, we get are we.
We get the name of the objects in our environment and we find index of the unit books because we just
need the unit books object to find its position and orientation.
So we get its indexed.
And from this index, we find it's positive x y position.
OK.
And this is it's orientation x, y z and W.
This is in what term you?
OK.
This is in cocoa attorney.
Be careful.
It is not in other angles, but it's in quaternary.
OK, so then what?
What we are doing, then we are publishing this frame.
So what do I mean by publishing?
So we get the orientation of this object and position of this object relative to other frame.
So what we are doing, we are doing what we are doing.
We are creating this frame as you can see this local frame and publish it.
So we broadcast it so other objects can see this frame and calculate their position and orientation
relative to this frame.
For example, if Turtle bought, our robot wants to find its position and orientation relative to this
object, it will listen to this frame.
So this broadcast of frame?
OK, its local frame, and it will calculate the difference between orientation and position in its,
uh, the object's local frame and the robot's local frame.
You know, OK, if you want to understand clearly this because surely I just assume that you know something
about it, because as as I have said before, I don't want to explain all of these things here.
I just want to show you how important it is that you can go to the t f to transformation in Ross tutorials,
official stores, and they have beginner explanation of this.
You can understand from there, and you can watch again this tutorial and try to understand the code
by running it yourself.
OK, then we are creating our frame.
As you can see, we are creating our frame here and then we will send this frame what we are doing here.
We first put the stamp of our frame.
So this frame is taken in.
This time this is needed for various purposes.
This can be synchronisation or some other things that it is not needed in this case, but they will
be needed in something in different situations.
So we just append the time to it, stamp different stamp of the frame.
Then this is frame.
This shows us what is the current frame?
OK.
So, um, for example, what do I mean?
The pound frame?
We are getting the position and orientation of this frame, OK, but it is relative to what it can be
relative to our robot.
It can be relative to some other fixed frame.
But in this case, this is relative to, I mean, the position and orientation we get by subscribing
to module states.
Topic is relative to ordem frame.
So relative to our world frame, OK?
So that's why we are writing it here, and this is our child frame.
What's our child frame?
Child frame is the local frame of our object.
We are just so that's why we are giving the name unit box the name of the object to as a child frame.
Then we are, uh, setting it's x y z, uh, coordinates.
As you can see there, we put that zero point zero because we are in two dimension.
Yeah, it's in three dimension if you watch, but the object moves into dimension.
The robot is also moved to dimension in x y plane, not in that plane because it's not a quadcopter
drone.
On something else, if you were controlling a plane, you would then use the zip also.
And we said also our orientation, as you can see in Quattrone and we then sent this frame or we are
broadcasting this frame in all the other frames and other objects can listen to this frame and calculate
their position and orientation relative to this frame.
OK.
So this is the final code.
The distrust by spin is for.
It is just like, um, just like a loop.
So our program doesn't finish here and continues until we stop it.
So let's not write the code for listeners.
What do I mean listeners saw in the previous code?
We have broadcasted this frame.
OK, this local frame now our turtle bought our robot have to listen to this frame and calculate its
relative, its relative position and orientation to this one.
OK?
With respect to local frame of objects.
So by doing that, we will get our D vector.
OK?
We will get our D vector.
Also, the X, the Y we have from here, I will.
I can.
I mean, we will get the X D Y from where we can find Peter and the absolute value of the.
OK, let's do that.
So what we are doing here is let's start first.
We need our load.
OK.
This is buffer transformation buffer.
This is needed in order to get our transformations and listen to them.
OK.
And this is listener which we'll use in order to lessen our transformations.
OK, then we are publishing the C and D.
Well, what is C and D?
Will C and D?
Well, this is common velocity.
This means common velocity.
And this message part is twist.
So we will command velocity.
I mean, angular velocity and linear velocity to our robot in order to go to that object.
OK.
So let's calculate, um, let's first look up transform.
So we are looking up for transforms from which to reach.
OK.
This is very important.
We want transformation from the frame of our object.
Let's, uh, from frame of our robot to frame of our object.
As you can see it, this is we want to find this the.
Yeah.
So we have to look for the transforms from robot's frame to objects frame.
And we are doing that here from Bayes footprint.
What's based footprint based footprint is local frame of our robot.
This is given default to this, uh, robot.
OK?
The programmers of this robot created that frame.
It is attached to the our robot, so it is based footprint is local frame of this robot.
And there we go.
If we want transformation from base footprint to object.
OK.
This is our object.
Uh, frame.
OK.
Um, and then what we are doing after we get this transformation, we are creating new message for twist.
Our twist message, new message, twist message.
Then we are setting our angular velocity and our linear velocity.
Our angle of velocity is proportional as you can see it.
Or it's equal, let's say, equals the Method eight to as you can see, we calculated by using Item
two and we get from D, Y and the X by calculating the 8m to we get our T to and we assign it to our
angular velocity and our, um, linear velocity is we equals it to the distance between these two objects.
So we are how we calculate by calculating D x squared plus d was squared and we find the square root.
And this gives us distance.
However, why we are doing here and we are assigning maximum velocity.
Maximillian University, why we are doing that because as distance increase.
Uses our linear velocity increases, and if the distance is too big, it calls some anomalies in the,
you know, the robot becomes very fast, so it drifts.
And instead of reaching to the given desired point, it just does something.
It just drifts and because its velocity is too much.
So that's why it creates problems.
So we try to keep its velocity in some range.
OK, so that's why we are finding minimum of this velocity and between our maximum linear velocity.
After that, we just publish this comment, this velocity to our robot.
OK.
After speaking that much?
OK, let's create our launch file.
So we launch here our two nodes, which is our first of all, its object to broadcaster.
By doing that, we broadcast our local frame of our object.
And by doing that, we listen and by launching team bots to lease their node.
We listened to this transformation and calculated desired heading angle and distance between this object.
OK, let's try to run then.
Let's do.
I hope it will work.
OK.
Indeed, I have checked before.
Surely roast lunch.
Let's do that.
So what was OK?
T both three t f two and the start robot launch?
OK, let's bring our here and let's run this book, but let's see what's happening.
OK?
As you can see, our robot now comes to object and it touches and stop it.
So if you make it like that, OK, as you can see it, come to this.
If you make it in this way, it will all and come closer to object by just calculating the, um uh,
relative orientation and distance between this object.
As you can see, this is how important to understand these transformations.
I mean, the um homogeneous transformation matrix rotation matrix, ail or angles, Quattrone and angles.
And this is a very simple example of it.
We will use them as you will see, we will use them in our future left since very, very, very frequently
and they are needed in robotics very, very frequently.
And if you start to learn our OS or Ross, you will see that they are also used, um, you know, uh,
very, very frequently in our office, in robot programming, because this is something like, um,
communication between they are, you know, they are like eyes of the robots and objects.
You know, based on these frames, they can calculate what's my position orientation relative this frame,
that frame and like that, OK?
I hope that with that tutorial, you can understand how important for us to know the homogeneous transformation
mattresses, rotation, mattresses, aler angles, continuous and so on.
I hope that I will see you in the next lesson.