3 Responses to Scara Arm forward kinematic equation simulator

This is cool! If my Robotics module runs next year, I’ll have to remember to show the students this. I’ve come across processing before, but I’ve never written anything in it – I’m impressed by how short your code is.

I’m getting strange results when x < 0. The end effector remains in the right half plane when I move the mouse to the left of the x axis. I think the problem is with the atan function on line 73:

shoulder_angle = degrees(atan(yx_div) -q_ang);

Does processing provide a function called "atan2"? In most languages, the list of trig functions includes this additional inverse tan function which takes x and y as separate float arguments, rather than y/x as a single float argument. This means that it can output a different angle when x and/or y is negative. The atan function gives the same answer for (-x,-y) as for (x,y), but atan2 gives you two different answers.

I always thought that the left hand plane was out of bounds or something because of the way the equations work – the x and y values are squared in some places so I thought it was something to do with that. I’ve been doing some mad work arounds when using servo scara arms like if I had a negative x and y val I’d put them into the equations as positive and then try and rotate the angles to the right quadrant – literally hours wasted away thinking it was really complicated to do, D’oh! – boom stick in atan2 – took 2 seconds and it’s working perfectly. so uh…Thanks! I’ve updated this post btw so it should be working now 🙂 processing is handy it’s kinda like the arduino ide but for graphics.