## Robot control part 7: OSC of a 3-link arm

So we’ve done control for the 2-link arm, and control of the one link arm is trivial (where we control joint angle, or x or y coordinate of the pendulum), so here I’ll just show an implementation of operation space control for a more interesting arm model, the 3-link arm model. The code can all be found up on my Github.

In theory there’s nothing different or more difficult about controlling a 3-link arm versus a 2-link arm. For the inertia matrix, what I ended up doing here is just jacking up all the values of the matrix to about 100, which causes the controller to way over control the arm, and you can see the torques are much larger than they would need to be if we had an accurate inertia matrix. But the result is the same super straight trajectories that we’ve come to expect from operational space control:

It’s a little choppy because I cut out a bunch of frames to keep the gif size down. But you get the point, it works. And quite well!

Because this is also a 3-link arm now and our task space force signal is 2D, we have redundant space of solutions, meaning that the task space control signal can be carried out in a number of ways. In other words, a null space exists for this controller. This means that we can throw another controller in our system to operate inside the null space of the first controller. We’ve already worked through all the math for this, so it’s straightforward to implement.

What kind of null space controller should we put in? Well, you may have noticed in the above animation the arm goes through itself, here’s another example:

Often it’s desirable to avoid this (because of physics or whatever), so what we can do is add a secondary controller that works to keep the arm’s elbow and wrist near some comfortable default angles. When we do this we get the following:

And there you have it! Operational space control of a three link arm with a secondary controller in the null space to try to keep the angles near their default / resting positions.

I also added mouse based control to the arm so it will try to follow your mouse when you move over the figure, which makes it pretty fun to explore the power of the controller. It’s interesting to see where the singularities become an issue, and how having a null space controller that’s operating in joint space can actually come to help the system move through those problem points more smoothly. Check it out! It’s all up on my Github.

## 8 thoughts on “Robot control part 7: OSC of a 3-link arm”

1. thesuisse says:

thanks for sharing¡¡, I’m doing a course in robotics and python use, this really helps me to complete the course to avoid using language that is adopted Matlab

• travisdewolf says:

Glad you found the code useful!

Good luck with your course, and I hope you can continue avoiding Matlab! 😀

2. Aisha says:

how can i do this same thing in matlab?

3. Jovian5 says:

Hi Travis,

• travisdewolf says:

Hello! Sorry about that I changed things around on my github a while ago, the link should work now! You can run the demo in this script with ‘python run.py arm3 osc random_movements’
Cheers!

4. Jovian5 says:

Thanks Travis for the prompt reply!! I ran the combination of ‘arm3 osc X’ and it worked great. Gave me a great insight into 3link manipulators. Thanks for the thorough tutorials.
However, I couldn’t get it worked for ‘arm3 dmp X.’ Can you guide me thru for dmp cases?
Also, in the ‘task’ folder, write.pyc is not present; how can I generate this file using write.py?

Thanks again!

• travisdewolf says: