Assignment 3: My Little Robot (Kinematics)

by Mike Gleicher on September 16, 2014

This assignment is due Wednesday, September 24th.

You will turn this assignment in on Moodle.


The goal of this assignment is to give you a chance to experiment with deep hierarchies (kinematic chains), to make sure that you see how the computations are done, and can implement them yourself.

A side goal is to let you do a little bit of programming.

The (optional) advanced parts of the assignment will give you a chance to think about some concepts that are just a little beyond what we do in class (Inverse Kinematics), but on a problem that you will be able to figure out (but to appreciate how hard the general case is). If you work in graphics, solving little geometry problems (like the IK bonus) is the kind of thing you do all the time.

The Basic Idea

In class, on the board, I made a little 2D robot arm with hierarchical transformations.

With hierarchical transforms, it is really easy to draw a picture of the robot given the joint angles.

The down side of this, is that you don’t ever compute where the points are for the joints – they are just intermediate computations that happen inside the SVG interpretter. Your task is to compute where these points are. (well, to write a program that computes it).

To check that you are computing things correctly, we can use the positions you compute to put squares over the joints. Note that you could place the squares without doing the computations themselves, but they would be rotated (aligned with the joint), not parallel to the screen axes. (there are other ways to do the drawing – but for this assignment, I want you to compute the positions).

Here is the robot with all of its joints at zero:

Here is the robot with its joints set to (45,-45,45,90). I have drawn a red box at the end point – notice that it is rotated. You could draw the box “un-rotated” by either adding a transformation to make it level, or by computing where the end point is, and then translating the box there (from the “root” coordinate system).

The Basic Robot

The basic robot has 4 links. The first one starts at the origin. There are 4 joint angles (the first one applies to the first segment). Each segment is 10 units long, and goes straight along the X axis. So when all of the joint angles are 0, the end point is at (40,0). Rotations are counter-clockwise if Y is going up (note: in my SVG pictures, I have flipped the Y axis so it goes up, therefore rotations are counter-clockwise). Rotations are given in degrees (not radians).

The configuration of the robot is 4 numbers (the 4 rotations). They are listed from the base (the point at the origin) out.

Your task: given a set of 4 numbers (the angles), compute the 4 positions for the ends of the segments (8 numbers).

So, for the easiest case: if you input 0,0,0,0, your output should be (10,0), (20,0), (30,0), (40,0).

If you prefer, have your program take in the 4 numbers and output an SVG file that draws the robot, and the points (done in a way that makes clear that you have computed the positions correctly. For example, you could output something that looks like this:

Even if you output SVG, you should still print out the numbers (since we’ll ask you for them).

A Less Basic Robot

After you get that to work, I recommend trying 2 extensions:

  1. Allow your program to input the lengths of the links (so they aren’t all 10)
  2. Allow your program to allow for any number of links (not just 4).

If you do number 1 and 2, you could input “10,10,10,10” and “0,0,0,0” to get the answer from the example above. But you could also input a longer list of lengths to make a snaky thing.

For a Real Challenge…

Assume the basic robot.

Suppose I give you a position where I’d like the end point to be. Can you figure out what the joint angles should be?

This problem is called “Inverse Kinematics” or IK (the computing the positions from the angles is called “Forward Kinematics”). In general, IK problems are hard. However, in 2D they are not so hard.

You can start with an even easier problem: assume a 2 link arm (or that I am telling you the position of the middle point, and only asking for the first two angles). Notice:

  1. For a large range of values (positions outside the circle of radius 20) there are no solutions.
  2. For most values, there are multiple solutions (you can have the elbow go up or down).
  3. For at least one value (0,0), there are lots of solutions.

For the 4 link problem, for most cases, there are many solutions. (if the point is exactly on the circle of radius 40, there is exactly one solution). To start with, just try to find any solution. And, of course, check that its right by drawing an SVG picture that draws the robot and places a mark over where the end goal was.

About Programming

For this assignment you need to write a program that computes the positions of points on a robot arm.

The simplest version of the assignment would just print the numbers. A better version of the program would write out an SVG file with the numbers in it. An insane version of the program would be a web page that has the program written in javascript and have it automatically update the SVG on the page. If you have the skills to do that, and enough spare time to do it, come talk to me: I can find better things for you to do.

Note that for this assignment, we don’t care what programming language you use. We will not run your program. We do ask that your program is readable so we can see that it does the right thing, and we’ll ask you to run your program (for various inputs) and turn in the outputs as well.

You might pick a programming language that you are most comfortable working in. You might pick C++ since it will be a good practice for the projects that are coming up (where C++ will be pretty much a requirement).

What you have to turn in

  1. There will be a list of example problems for the basic case. In the Moodle type-in box, you need to give the answers to each of these (8 numbers each). There are some “bonus” problems if you do the less basic problem version. You only need to give 1 or 2 decimal places of precision (please don’t type more than that in – we prefer “10.5” to “10.4898737584”)
  2. You have to upload the complete source code for your program. If it’s more than one file, make a ZIP archive and upload that. While you don’t need to include any libraries you use, please make it clear in the comments of the program AND the type-in box for Moodle what we would need to know to run the program (what language, what version of the language, any libraries). Your program must be clear enough that we can quickly look at it and believe that it would actually do what its supposed to do.
  3. If your program outputs SVG files, please upload SVG files for the answers (that you’ve typed the values into the text box). Please put all of them as a single ZIP file.


This is an ungraded assignment. The scale is:

  • Nothing – if you don’t turn anything in
  • Something – if you turn in answers that aren’t right, or if we don’t believe your program is actually capable of producing the right answers.
  • Everything – if you turn in the right answers for the basic parts, and a program we believe works.
  • Above and Beyond – if your program also gets some of the non-basic stuff and/or you do the IK challenge

Note: the way that grading works in the class, Above and Beyond doesn’t help you that much for your grade. But its more fun.

Also, your robot pictures can be simple – connect the dots, and put squares over the joints (aligned with the screen axes, to show they aren’t hierarchical). You can even take my SVG files for the pictures on this page and use them (just add the boxes the right way, and change the rotation values as needed). If you want an easy link, here is arm-1.svg (all zero joints) and arm-2.svg with the red box

But… it’s a lot more fun for everyone if you draw your robots nicely.

The problems

For the basic part, give the 4 positions of the joints (and pictures, if applicable) for the angle sets:

  1. (45,45,45,45)
  2. (30,-15,30,-15)
  3. (15,30,45,60)
  4. (45,0,-30,-15)
  5. (180,90,30,15)

For the non-basic parts, give all of the point values (and pictures):

  1. lengths: (10,10,5,5) angles: (30,-15,30,-15)
  2. lengths: (20,10,10,5) angles: (60,-15,-15,-15)
  3. lengths: (10,10,10,10,10) angles: (60,-30,15,15,15)
  4. lengths: (20,15,10,10,10,10,10,10) angles: (60,-45,30,15,-15,15,-15,15)
  5. lengths: (10,9,8,7,6,5,4,3,2,1) angles: (all 30 degrees)

For the IK problem, give the 4 joint angles (and pictures)

  1. (0,0)
  2. (20,0)
  3. (0,20)
  4. (25,10)
  5. (-20,10)

{ 1 trackback }

Previous post:

Next post: