View Single Post
  #12   Spotlight this post!  
Unread 19-02-2007, 15:04
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Looping a function

The problem is that you are doing a bunch of floating point calculations, then truncating them to integers.

This is the biggie:
tiltR = (tiltD * 3.14159265) / 180.0;

For tiltD values between 0 and 57, you're going to get a value of 0 in tiltR. For 58-114, you're going to get 1. All three of your main calculating lines will all round into integers. The combination of all that rounding will probably result in you seeing what you are.

Recomendation:
1) Use fixed-point math (multiply everything by 1000 and be careful with multiplications/divisions),
-or-
2) declare everything as a float and make sure you don't call this function often (floats are very expensive).

Last edited by Bongle : 19-02-2007 at 15:07.