View unanswered posts | View active topics It is currently Fri Mar 22, 2019 9:01 pm

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Math calculation error
Author Message
Rookie

Joined: Sun Jun 17, 2012 11:18 am
Posts: 26
Math calculation error
I have a simple sentence of arithmetic in my code

 Code:   vx = (2.0/3)*a - (1.0/3)*(b+c);vy = (1.0/(2.0*Sin60))*(c-b);

Nothing goes wrong except at certain data points:
When
a = 0, b = -87, c = 87,
it comes up with a strange result:
vx=0.000000 vy=20184.000000 (<- this is wrong)

Can you suggest any reason?

P.S. "Sin60" is just a constant float variable
 Code:static const float Sin60 = sinDegrees(60);

Fri Feb 01, 2013 4:52 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Math calculation error
Moved to this sub forum for better visibility.

= 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]

Sun Feb 03, 2013 3:23 pm
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 207
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Re: Math calculation error
Well, the vx variable works fine. The vy is the problem. I guess you knew that, but I'm not exactly sure why that would happen. Sometimes, robotc treats assignment statements as being calculated as shorts unless otherwise specified. The way to specify is to put the data type in front of the information inside parentheses, like (float) or (char) or (long). I don't know where the type statements have to be placed, so first put them in front of everything like:

vy = (float) (1.0/ (float) (2.0* (float) Sin60))*(c-b)

and then get rid of unnecessary (float)'s. Possibly, that may not work at all. could you tell me the types of a,b,c,vx,and vy? That might help. Keep us updated on how to help!

-Coder A

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot

Mon Feb 11, 2013 2:34 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 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