View Single Post
  #2   Spotlight this post!  
Unread 27-07-2005, 20:13
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,355
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: Limit_Mix() Function

Quote:
Originally Posted by Ewilliams2006
I understand the Limit_Mix function combines the 2 joystick values (x,y) into a PWM value - one for each side of the drive. Can someone explain to me exactly how this function works. I see the code (obviously) and understand it, but how does the mathematical side work? Also, I remember we had some acceleration problems and a cubed value of the actual joystick input would work better (between a certain range). Any help would be greatly appreciated.

Thanks,
Eric
Not meaning to pick apart your understanding, but Limit_Mix quite literally only limits the values passed to it to so that the returned value, to the calling function, is between 0 and 254.
The actual calculation of PWM values is done by the line that calls the Limit_Mix function. The arguments that are sent to Limit_Mix are then limited to between 0 and 254, then returned.
So, "pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);" is used to calculate for the right side motor, and " pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);" if for the left. What each of these lines do is to take the p1_Y value and add or subtract from it the p1_x value and add or subtract 127 from that. (When you add p1_x you subtract 127 and vise verse.) These are the offset by 2000 for good measure then sent to Limit_Mix. Limit_Mix limits the values and then removes the 2000 offset and returns the limited value.

Now, if you are totally confused, get out a piece of paper and right down the values with the joystick in various positions, substituting in the values for p1_x and p1_y for the various positions. It will become clear very quickly what the functions do.