Results 1 to 6 of 6

# Thread: uncertain problem

- 11-17-2008, 02:01 PM #1Member
- Join Date
- Nov 2008
- Posts
- 4

- Rep Power
- 0

## uncertain problem

hey guys, just to start off i want to say i'm a complete noobie to java so please bare with me and not get frustrated if i'm asking something that is actually quite simple and obvious to you guys, after all i'm only wee lol

I have a problem implementing certain formulas to calculate the positioning of four theta angles when a user inputs coordinates to the system, the following is where i need to input my code for this but for some reason it doesn't want to compile i think i'm probably missing an important expression but i don't know what it is:

my formulas and code so far:

public void calcThetas(){

float theta1 = arctan(py/px);

float ax = ((cos(theta1))*(sin(alpha)));

float ay = ((sin(theta1))*(sin(alpha)));

float az = cos(alpha);

float theta234 = arctan((cos(alpha))/(((cos(theta1))*(sin(alpha))*(cos(theta1)))+((sin( theta1))*(sin(alpha))*(sin(theta1)))));;

float p1 = ((px*cos(theta1))+(py*sin(theta1))-(d4*cos(theta234)));

float p2 = p2 - d4*sin(theta234);

float c3 = ((sqr(p1)+sqr(p2)-sqr(d2)-sqr(d3))/(2*d2*d3));

float theta3 = ((arctan(sqrt(1-(sqr(c3)))))/c3);

float theta2 = arctan(((d3*c3)*p2)-(d3*sin(theta3)*p1))/(((d3*c3)+d2)+(d3*sin(theta3)*p2));

float theta4 = theta234-theta2-theta3;

/*********************** Note from Nick Taylor **************************

The limb lengths of the arm are held in the floats d1, d2, d3 and d4

The new x, y, z co-ordinates of the TCP are held in the floats px, py, pz

The new TCP orientation is held in the float alpha

These eight variables are available for use at this point in the program

The variables which you should determine values for are the floats

theta1, theta2, theta3 and theta4, all in radians

*/

anyone got any ideas?

Thanks for any help

Will C

}

- 11-17-2008, 02:45 PM #2Member
- Join Date
- Oct 2008
- Location
- UK
- Posts
- 65

- Rep Power
- 0

You are using static methods from the Math class:

Math (Java Platform SE 6)

so, your code needs to be like this:

Java Code:float x = Math.sin(y);

Good luck!

- 11-17-2008, 02:50 PM #3Senior Member
- Join Date
- Jun 2008
- Posts
- 2,571

- Rep Power
- 12

"cos" should be "Math.cos", likewise for sin.

"sqr" should be "Math.sqrt".

"arctan" should be "Math.atan" or, maybe, "Math.atan2"

Do you see the Pattern?

Check out the Math Class (or StrictMath class, read the disclaimer info at the beginning of the API docs for Math, to determine whether or not you should be using StrictMath).

Math (Java Platform SE 6)

StrictMath (Java Platform SE 6)

Edit: Slow, I am.

- 11-17-2008, 03:05 PM #4Member
- Join Date
- Nov 2008
- Posts
- 4

- Rep Power
- 0

right i commented the code and brought it down too:

public void calcThetas(){

float theta1 = Math.atan(py/px);

but this gives the error:

bash-3.2$ javac robot.java

robot.java:2804: possible loss of precision

found : double

required: float

float theta1 = Math.atan(py/px);

^

1 error

and to be honest that means nothing to me, i've tried searching the web, using different techniques to make it work but nothing is working, its giving me a headache like.

cheers for the response guys btw, lol i didn't want to sound rude there :)

- 11-17-2008, 03:13 PM #5Senior Member
- Join Date
- Jun 2008
- Posts
- 2,571

- Rep Power
- 12

Declare your variables as doubles, not floats. The Math class (as the API docs clearly show) takes doubles as arguments and returns doubles as values.

- 11-17-2008, 03:25 PM #6Member
- Join Date
- Nov 2008
- Posts
- 4

- Rep Power
- 0

## Bookmarks