View Single Post
  #3   Spotlight this post!  
Unread 02-02-2006, 15:08
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: Strange but...need fresh eyes

Quote:
Originally Posted by Joel J.
Are you overflowing?

Does p1_y go from -128 to 127, or from 0 to 255.

If its from 0 to 255, then adding 127 definitely takes you out of the range of an unsigned char.

If its from -128 to 127, then it seems that saving (127+127) to a signed char would also result in overflow.

If you want to scale by 75% you can multiply by three, then divide by four:

p1_y = 3*(p1_y + 127)/4;

No need for floats.
Well the first line of the code works ok I believe. p1_y from the steering wheel goes from around 60 to 150 or something like that. The correction fixes it ok. If I change the if statement to, say, 254, the code will work correctly until 254 then flop to 1. If I change the if statement to 145, the code will work correctly until 145 then flop to 1. So I am deducing that my assignment in the if block is causing the headache. That being said, I am going to try what you suggested, because once things over range, all logic can be thrown out the window!