View unanswered posts | View active topics It is currently Wed Aug 20, 2014 3:20 pm






Reply to topic  [ 5 posts ] 
Modified Atan2 Errors 
Author Message
Rookie

Joined: Fri Jan 13, 2012 5:17 pm
Posts: 9
Post 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.0
short 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)))));
}


Wed Oct 10, 2012 10:44 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3188
Location: Rotterdam, The Netherlands
Post Re: Modified Atan2 Errors
You could also just use the atan2 function in ROBOTC :)
Code:
float atan2(const float Y, const float X);

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Oct 11, 2012 3:47 am
Profile WWW
Rookie
User avatar

Joined: Sun Jun 17, 2012 11:18 am
Posts: 26
Post 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?


Fri Oct 12, 2012 3:17 pm
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Modified Atan2 Errors
Welcome to the internet. Google is your friend; http://en.wikipedia.org/wiki/Atan2

_________________
Mike aka Spiked3
http://www.spiked3.com


Fri Oct 12, 2012 4:56 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3188
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Oct 13, 2012 3:09 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.