Many machines and robots have got multiple axis of motion. An industrial robot typically has six joints and they have to move smoothly and in a coordinated fashion. A technique we can use to help us is linear interpolation. Consider this simple function here where x of s is a function of an initial value of x and a final value of x. And, s varies from 0 to 1. In this case, then, x of s is some sort of intermediate value. X of 0 is the initial value, x of 1 is the final value, and x of 0.5 is halfway in between the initial and final value. Now, x could be a vector which makes the multi-dimensional case quite straightforward. For instance, it could be the xyz position of some sort of machine or simple robot. So, x is a vector with the three elements xyz and we can interpolate linearly between an initial position, an initial xyz and a final xyz. S is a scalar which varies from 0 to 1.
So, what is s? Well, S is a scalar that varies smoothly from 0 to 1. And, if S is a smooth function of time, then x will be a smooth function of time since x is simply a linear function of S. We already know how to make a smoothly varying function of time. It can be a polynomial function of time or it could be a trapezoidal velocity profile function of time. Let’s look at a two-dimensional example. We want to move in the xy plane and I’ve got a starting point and an ending point. Now, I want to move in a straight line from the start to the end. I’m going to assign some arbitrary coordinates to the start and the end. We’re back in MATLAB and now our first point is a vector, not a scalar. So, the first point is the coordinate 10, 20, and our last point is a vector 30, 10. And this time, I’m going to use the function jtraj, stands for joint interpolated trajectory. I’m going to move from the first point to the last point in 50 time steps, and we see it all scrolling past. If we scroll back, we see that the first point has indeed got the vector value of 10 and 20, and the last point has got the value of 30 and 10.
Let’s plot x as a function of time and we can see here that our first axis has moved from 10 up to 30, second axis has moved from 20 down to 10. This function also returns the velocity. So, I can add that as an extra output argument, XD. And now, we see x velocity as well and I can plot XD versus time, and we can see that the velocity of each axis starts and ends at 0 and has a finite value in between. The function also allows me to specify an initial and final velocity for the trajectory. So, if I ask for the initial velocity to be 0 which is the default condition, if I ask for the final velocity to be equal to 10. Now, if I plot the trajectory versus time, we can see that at the end of a trajectory, the slopes of a line are not equal to 0 and that’s because it is achieving its destination position at a finite velocity as we specified.
Let’s consider a more complex two-dimensional example. I’m going to start and end at this point in the XY plane. I’m going to move to this point, this point, this point, and back to where I started from. So, there are now three via points. I can assign some arbitrary coordinates to these. In order to move smoothly through the via points, we need to introduce blends and we talked about blends in a previous section. Here, we want to apply this idea of blends which, in this example, is shown for a scalar variable x. We want to apply it to a multi-dimensional case because now we’re talking about a robot moving in the xy plane.
So now, each of the positions XI is a vector rather than a scalar. Now, we’re going to look at a scenario where points on the trajectory are vector quantities, two-vector in this case, and we have via points. Let’s do this square trajectory in MATLAB.
Our starting coordinate is 40, 50 and the via points are 60, 30 which is one row of the matrix, 40, 10 which is another row of the matrix, 20, 30 and we finish where we started. And, that’s the list of via points. Now, I use the Toolbox function, mstraj. I pass in the list of via points. Passing the speed at which we’re going to move along the path, the time of the segments is default. Now, start coordinate. The time step, 0.1 seconds and the acceleration time, which I'm going to consider to be just 1 second. And, I’ve created in the workspace variable x. It’s got 435 rows, so that means that the trajectory took 435 time steps to execute each time steps 0.1 seconds. That’s 43.5 second to execute.
I can plot x versus time and we can see the trajectory of the first and second coordinates versus time first coordinate shown in blue. If I plot the first coordinate against the second coordinate, so that could be the x coordinate and that could be the y coordinate. I have a plot like this. So, this shows the motion of the point on the xy plane and, indeed, it has the square profile that we are looking for, but it’s got rounded corners because we have specified a finite acceleration time. Let’s consider now an extra degree of difficulty. Let’s consider that the machine is capable of moving at 2 meters a second in the x direction, but only 1 meter per second in the y direction.
We need to take this in to account when we figure the trajectory for the robot. Consider again this two-dimensional example and this is the path that we want from the start to the end, that’s our desired path. But if the robot is capable of moving more quickly in the x direction than in the y direction, the path might look something like this. It will go very, very quickly in the x direction and also move a little bit in the y direction. But then, the x-axis will have achieved its goal, so it will stop moving. But, the y-axis which is moving more slowly has to keep on going, and so we end up with this dogleg path instead of our desired path. If I was cutting material on something like a flatbed profiling machine, then I’d be rather upset if I had this path rather than the desired one.
So in order to achieve the desired path, we need to take in to account the velocity of each of the axes. We need to work out how long the slowest axis requires to get to the next via point. And then, we scale the velocity of the other axes so that they all arrive at the same time at the via point, and then they all set off again to the next via point. We repeat this process indefinitely.
Now, we’re going to repeat the trajectory, but this time we are going to specify the velocities of the axis being different. So, previously, the velocity was 2 units per second in the x and y direction. Now, I’m going to specify a very slow x-axis, only 1 unit per second, and a fast y-axis. If we now look at the trajectory level in our workspace, we see it’s got 835 rows, 0.1 second time step, so that means the trajectory now takes 83 seconds, almost twice as long. And, that’s to be expected because, now, the trajectory is being paced by the slowest axis.
The slowest axis now can only move at only 1 unit per second. Previously, it was 2 units per second, so we are limited now by an axis which is half the original speed, the trajectory has taken roughly twice as long to execute. I can plot x versus time. We can see the 835 time steps and I can plot x versus y.
We learn to compute a trajectory that involves simultaneous smooth motion of many robot joints.
This content assumes high school level mathematics and requires an understanding of undergraduate-level mathematics; for example, linear algebra - matrices, vectors, complex numbers, vector calculus and MATLAB programming.
y = mstraj(via, 2, , start, 0.1, 1);
Error using mstraj (line 78)
Length of QDMAX does not match number of axes
I got this error please tell me what should I do to remove this.
I have latest version of tool box.
This is a bug in RTB10, thanks for spotting. For videos in Robot Academy it is best to use RTB9, and this error is not present. There are some slight differences in calling conventions between RTB9 and 10.
mstraj(via, [1 2], , first, 0.1, 4)
Error using mstraj (line 78)
Length of QDMAX does not match number of
I think this one is also a bug.
As per previous comment, the syntax used in the Academy video is for RTB9.
Please can you tell us how to write it in RTB10. I have read the documentation in matlab but not getting anywhere with it.
THANK YOU SIR.
This should be a reply to SirClems but cant find the reply button on his post.
mstraj(via, [1 2], , first, 0.1, 4) is working fine in 10.3.x but mstraj(via, 2, , first, 0.1, 4) is also working in 10.4.x the newest release.
I made the function backward compatible with RTB9.
This error I encountered, and as far as I know is not a bug in the latest version of the toolbox, the via points array must be in the form of columns, for example:-
via = [20; 10; 30]
via = [20, 10, 30]
Hi Professor, at the beginning of the matlab part on video, you have used ‘jtraj’ function for intermediate cartesian points of start and end points. I have searched some books but they used polynomials for joint space. Did I miss or misunderstand anything?
In addition, I looked ‘jtraj’ and ‘tpoly’ functions both of are fifth order polynomials. Is there any difference between of them?
jtrajsimply creates a 5th order polynomial path between start and end vectors. It is useful to apply to robot arm joint coordinates, but is really quite general.
tpolyuses the same type of polynomial but considers only a scalar.
We talked here about linear interpolation and used jtraj to interpolate between two points. Hiwever the graph we get has a curve, seems polynomial. Shouldn’t linear interpolation between two points give a straight line between the points?
To be precise, we interpolated joint angles, between two sets of joint angles (not points). The motion in joint-angle space is straight lines, but after applying the non-linear forward kinematics function, the resulting Cartesian-space motion is not straight.
Thanks for your explanation, I’d like to kindly ask why S=[0,1], why it can’t take further values?
I think I got it, it’s like the percentage which represents at which part of the trajectory the agent is. As you mentioned, at x(s=0.5) the agent would be at the mid of the trajectory