View unanswered posts | View active topics It is currently Fri Dec 19, 2014 12:15 pm






Reply to topic  [ 3 posts ] 
Math calculation error 
Author Message
Rookie
User avatar

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

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

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.