View unanswered posts | View active topics It is currently Fri Jul 29, 2016 8:04 am

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Modified Atan2 Errors
Author Message
Rookie

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

Wed Oct 10, 2012 10:44 pm

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

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

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 197
Re: Modified Atan2 Errors

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

Fri Oct 12, 2012 4:56 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 5 posts ]

Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning