View unanswered posts | View active topics It is currently Tue Sep 22, 2020 5:16 pm

Reply to topic  [ 3 posts ] 
Math calculation error 
Author Message
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

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:
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
static const float Sin60 = sinDegrees(60);

Fri Feb 01, 2013 4:52 pm
Site Admin
Site Admin
User avatar

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

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 207
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
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.