top of page

ROBOT ARM: PART IV

1. Introduction

Now that we are able to move the end-effector at a chosen velocity, we can develop one of the most interesting things about robot manipulators: path-planning and path-following algorithms. This opens up many possibilities for different applications, such as painting, obstacle avoidance, optimizing tasks by finding the best trajectory, among others. In this part, we'll develop path-planning and path-following models for the manipulator to follow a set of waypoints both when just moving and when picking up and dropping off an object.

2. Path-Planning Algorithm

We are going to perform this task using a Matlab livescript. It would be better to have a more interactive app with buttons, but unfortunately the App Designer in Matlab was crashing a lot when using the tools from the image processing toolbox, so we had to use a script instead.

​

The way it works is that the user first plots the waypoints that he wants on the XY plane by clicking on it. He then can click and drag the points to better position them. Next, the same set of points is shown in the YZ and XZ plane, where the user can again drag them to place them exactly where he wants. Finally, a smooth spline is generated passing through the chosen coordinates and is shown in 3D. The spline points are then sent to the workspace, from where the Simulink model uses it on the simulation. We've also created a function located at the end of the algorithm to check if all the points on the path are reachable. In this case, we want the last link to always maintain an angle of 0 degrees with the base plane, so the calculations are done based on this configuration. Any unreachable point is marked red on the final plot. Let's take a look at the script:

1. path-planning 1.PNG
2. path-planning 2.PNG
3. path-planning 3.PNG

The checkCoords is the function that verifies if all the points are reachable. Let's see it too:

4. check coords fcn 1.PNG
5. check coords fcn 2.PNG
6. check coords fcn 3.PNG

Notice that in the script we have to choose between picking up an object or not. This changes the first and last Z coordinate to be the same as the object that we are going to grab. Now let's test it and create a few paths with it.

​

First, we'll draw a circle on the Z plane:

In this example, we only set the coordinates on the XY plane. By default, the first coordinates on the Z plane are all 150, and the user can change it as he wants by dragging them, as we'll see. Here's the final 3D path:

8. circle path.PNG

Now we'll draw a star, also on the Z plane:

Notice that our idea here is to test the path planning algorithm. The fact that our star is not made of straight lines is what we want, otherwise we could just easily make it go through the 11 original coordinates to get one with straight sides. Here's the 3D view:

10. star path.PNG

Now let's draw a more random trajectory and also change the Z component:

Sometimes it's not so easy to see all the points on a plane, and we may drag an unwanted point. However, as we go through all three planes, it becomes easy to see and organize them the way that we want. Here's the final path:

12. path1 path.PNG

Lastly, since we're also going to develop a model to pick up and drop off an object while going through a given path, we're going to create it now:

And the final path is:

14. pathObj path.PNG

To finish, let's see what happens when we select points that are unreachable. These points are either outside of the robot's reach, require angles that violate joint ranges, or would result in a collision with the robot itself:

The red points indicate the parts of the path that are unreachable:

16. bad path.PNG

Next, we're going to create models to follow these paths that we've saw.

2. Path-Following Model

Below is the model that we're going to use to make the end-effector follow the desired path. The only new block is the one from Stateflow. The others are the same from previous chapters:

Path-Following Model

17. path following model 1.PNG

(click to enlarge)

Stateflow Chart

18, path following state flow.PNG

It's a simple feedback model. We go from one point to the other, and when we're within at least 1mm from it, we jump to the next.

 

Notice that we already have a model to move the end-effector at a chosen velocity in each of the XYZ directions. Now, however, to move from one point on the path to another, we're going to be working with a velocity vector on the 3D cartesian plane. This means that first we're going to need to decompose it in the XYZ directions so that we can use the inverse velocity (or inverse Jacobian) algorithm block:

Velocity Calculation Function

19. path following fcn.PNG

The function in our model does this. It uses the distance between the current and next point to calculate the projecting angles in each axis, and then with them, it calculates the required velocity in each direction so that we have the constant linear direction that we want (desVel). Below is a diagram showing basically what we're doing. The only difference is that in order for it to be easier to visualize we have the vector starting from the origin, instead of the current point in space:

20. vector dec.PNG

Now let's test our model. A spline block from Simscape will be used to show the desired path on the simulation. It's being fed the same variable coords3D as our Stateflow chart. We'll use the paths that were generated on the previous section, starting with the circle:

As we can see the model works pretty well. Lets try the next path, the star:

Here we're moving the end effector with a velocity of 80 mm/s, and we can see that we get a smooth movement throughout the path, which is what we are aiming for. Finally, let's see the third path, which is a more random one:

It's clear that our model performs the way we intended. The algorithm could be further improved to include orientation as well and to make it automatically compute if there's another possible orientation for the positions that the tool is unable to reach at zero degrees, for example.

4. Moving objects

Next, we'll combine the previous model with the one from Part II to obtain a model that will pick an object located at the first path coordinate, move it along the desired trajectory, and drop it off at the last coordinate. The robot starts at an initial position and goes back to it after dropping the object:

Pick Object Model

24. pick_obj_model.PNG

(click to enlarge)

The Stateflow logic is also basically a combination of the two previous models. The robot goes from the starting position to one above the target, so that is no chance of hitting it. Then, it stops, moves down, stops again, and closes the gripper to grab the target. Once it's closed, it goes moves through the planned path until the last coordinate, where it drops off the object, moves above it so that it doesn't hit it, and then moves back to the original position:

Stateflow Chart

25. stateflow_1.PNG
26. stateflow_2.PNG

Pick Up Subchart

27. stateflow_3.PNG

Drop Off Subchart

28. stateflow_4.PNG

The velocity function is the same from the previous section, but we'll show it here again to keep the flow:

Velocity Calculation Function

29. stateflow_fcn.PNG

Now it's time to see it working. First, let's use the last path that we generated on the previous section and see how it performs:

It performs very well, picking up and dropping off the object at the right locations, while following the path in between these points. Lastly, let's create another path and run another simulation to see it working again. Here's the path:

31. path_obj2.PNG

And the simulation:

This simulation also works well. We can conclude that our model is correct and our calculations accurate.

5. Conclusion

With this, we conclude the robot arm project. We went from the basic, regarding spatial representation, all the way to inverse velocities and path-following algorithms. The project could be further developed by constructing a real model and getting into the control part. We could also learn more about mechanical design and construct other grippers for the manipulator in order to perform different tasks.

1. Introduction
2. Path-Planning
3. Path-Followig
4. Moving objects
5. Conclusion

Part III

Projects

© 2026 by Matheus Lino

bottom of page