View Single Post
  #39   Spotlight this post!  
Unread 07-04-2008, 14:44
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Unique ways of controlling your robot (driving)

Quote:
Originally Posted by AmoryG View Post
How did they get those numbers?
Are you asking about the inputs to the Limit_Mix() function in the default code?

Code:
  pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);
  pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);
The 2000 is just to force the compiler to use 16-bit arithmetic. Otherwise it would decide that because p1_y, p1_x, and 127 each fit in eight bits, the addition and subtraction should be done with eight bits, and there could be overflows and unexpected results. Limit_Mix() itself subtracts 2000 when it returns the value.

The first line adds the x and y values, correcting the offset so that when both inputs are neutral (127) the sum is also neutral.

The second line does the same thing as the first, but it "mirrors" the x value by subtracting it from 254 first. Then it obscures that step by combining the new +254 and the -127 from the first line into a single +127.