ROBOTC.net forumshttp://www.robotc.net/forums/ Modified Atan2 Errorshttp://www.robotc.net/forums/viewtopic.php?f=1&t=4969 Page 1 of 1

Author:  recondelta090 [ Wed Oct 10, 2012 10:44 pm ]
Post subject:  Modified Atan2 Errors

I am working on using the position of the joystick to calculate an angle between 0 to 360 or -180 to 180 and the built in atan2 function doesn't do that. I have a modified Atan2 code that displayed a value between 0 to 360 before RobotC 3.50 but now I get the following errors.
 Code:#define yDirection (joystick.joy1_y1)#define xDirection (joystick.joy1_x1)float angle = 0.0short x = xDirection, y = yDirection;short vectorAngle = angle;void getJoystickVector(){  x = -xDirection; y = yDirection;    angle = x == 0 && y > 0 ? PI/2 :(            x == 0 && y < 0 ? 3*PI/2 :(            x >= 0 && y == 0 ? 0 :(            x > 0 && y > 0 ? atan(y*1.0/x) :(     **Error**:Invalid numeric type (float, string) for assignment to byte variable            y >= 0 ? atan(y*1.0/x) + PI :(          **Error**:Invalid numeric type (float, string) for assignment to byte variable            y < 0 && x > 0 ? atan(y*1.0/x) + 2*PI :                    atan(y*1.0/x) + PI)))));}

Author:  mightor [ Thu Oct 11, 2012 3:47 am ]
Post subject:  Re: Modified Atan2 Errors

You could also just use the atan2 function in ROBOTC
 Code:float atan2(const float Y, const float X);

- Xander

 Author: fxlj007 [ Fri Oct 12, 2012 3:17 pm ] Post subject: Re: Modified Atan2 Errors What's the difference between atan() and atan2()? Seems atan2() is a newly-added function, as it doesn't appear in the Help document?

 Author: Spiked3 [ Fri Oct 12, 2012 4:56 pm ] Post subject: Re: Modified Atan2 Errors Welcome to the internet. Google is your friend; http://en.wikipedia.org/wiki/Atan2

 Author: mightor [ Sat Oct 13, 2012 3:09 am ] Post subject: Re: Modified Atan2 Errors atan2 is twice as healthy as a regular atan but has fewer calories while still maintaining the same fresh flavour.Regards,Xander

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/