This is caused by 1 - c2^2 being a negative, which Processing will not allow. My c2 variable is around 832673, the x and y are between 0-800 and L1 and L2 are set at 300. My question is where is the 1 coming from and why 1?

Logged

There are 10 types of people in the world: those who understand binary, and those who don't.

It's not just Processing that doesn't allow square roots of negative numbers; it's the entire family of real numbers that don't allow it :-)You are not deriving the c2 variable correctly It should be normalized to the 0..1 range, because it's divided by double the product of L1 and L2.Have you properly implemented this line?

If you look at what the values mean, "x*x + y*y" is just "square of distance to x,y coordinate" which must be less than the length of the two links, or the arm won't reach. Thus, it is possible that the numbers you're trying to put in are simply impossible to satisfy.Another option for what could be going wrong is the frame of reference -- is the origin (x=0, y=0) at the center of the J1 joint, or somewhere else? (The tutorial doesn't mention this, but it looks like it assumes the x,y coordinates of the J1 joint are 0,0)

L1 and L2 are the lengths of each are segment.x and y are the 2D position at the end of the arm.The distance to x,y can not be greater than the total length of the arm.Like this:L1 + L2 >= sqrt( x^2 + y^2) else the robot arm can not reach the given x.y position.

If that statement is false then the value of c2 will be greater than 1.0 and thus give a negative value under the radical.

Try your value in a spreadsheet (like Excel) to see all the calculation and to easily adjust values.

Thanks a lot for the help, I did exactly what you thought I did jwatte. I left out a parentheses, leading to incorrect value assigned to the variable c2. This made the number to be sqrt() negative. Silly mistake :-)

~Thanks Idan

Logged

There are 10 types of people in the world: those who understand binary, and those who don't.