View Single Post
  #7   Spotlight this post!  
Unread 05-02-2008, 18:32
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,753
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Code spitting out -16256?

Quote:
Originally Posted by Tanis View Post
We've found the problem to lie in-
Code:
    velocity = (p1_y - 127);
    rotation = (p1_x - 127);
    strafe = (p2_x - 127);
We've put some printf statements before and after these 3 lines, but the p1 and p2 variables are correct. For some reason the code is adding 129 to p1_x and p2_y and storing that into rotation and strafe instead of subtracting 127.

We can't figure out where this is coming from. Any ideas?


Sorry we couldn't try the last poster's suggestion today- our lab lost its internet connection, and we forgot what it was. We'll try that tomorrow.
p1_x, p1_y, and p2_x are of type unsigned char. If they are less than 127, your subtraction will wrap around (since negatives aren't allowed) - i'm guessing your input is 126 (126 - 127 = -1, which is 255)

To fix it, you just need to typecast the inputs to ints:
Code:
    velocity = (((int)p1_y) - 127);
    rotation = (((int)p1_x) - 127);
    strafe = (((int)p2_x) - 127);