I'm breaking up some messy code into separate functions, and can't seem to figure out how to pass two parameters into a function, and get two back. The passing part is easy - I can just call get_angles(somenumber, somenumber), but how do I make theta1 and theta2 available within the loop() or wherever I call the function? If anyone has insight or a good link to a reference that would be great! Thanks

Oh, and in case you're interested, this function is supposed to pass an x,y position and return two joint angles, so I can control this:

http://youtu.be/IHGXqud2m9Qdouble get_angles(double Px, double Py)

{

// first find theta2 where c2 = cos(theta2) and s2 = sin(theta2)

double c2 = (pow(Px,2) + pow(Py,2) - pow(a1,2) - pow(a2,2))/(2*a1*a2); // is btwn -1 and 1

double s2 = sqrt(1 - pow(c2,2));

double theta2 = degrees(atan2(s2,c2)); // solves for the angle in degrees and places in correct quadrant

// now find theta1 where c1 = cos(theta1) and s1 = sin(theta1)

double theta1 = degrees(atan2(-a2*s2*Px + (a1 + a2*c2)*Py, (a1 + a2*c2)*Px + a2*s2*Py));

//return?

??

}