

I look to the youth for inspiration.  Chief Hedgehog [more] 



Thread Tools  Rate Thread  Display Modes 
#1




Help with limit mix
what's the point off adding 2000 to the following functions:
pwm01 = pwm03 = Limit_Mix(2000 + PWM_in1 + PWM_in2  127); /* LEFT WHEELS */ pwm02 = pwm04 = Limit_Mix(2000 + PWM_in2  PWM_in1 + 127); /* RIGHT WHEELS */ the coding seems all fuzzy to me, i dont' get it 
#2




Re: Help with limit mix
I'm n00b myself so maybe I'm wrong.
I had problems with this myself when I came across it. I think it has something to do with the hardware it is slower to run the program if it starts getting decimals (floating point #'s) I think later in the program it negates the 2000 correct me if I'm wrong 
#3




Re: Help with limit mix
You're right, noob. () It does that just so that it can get decent precision without decimals or negatives.
I think... Last edited by Ryan M. : 07312005 at 06:35 PM. 
#4




Re: Help with limit mix
Quote:
The Limit_Mix() function subtracts 2000 from its result, neatly compensating for the extra 2000 in its input. 
#5




Re: Help with limit mix
The Limit_Mix function assumes that its input value has had 2000 added in, and thus subtracts it back out before returning.
Back in the Basic Stamp days, there were certain circumstances where it was necessary to avoid negative numbers. This Limit_Mix function is a legacy of those days. By rights, the function should now be: Code:
unsigned char Limit_Mix (int intermediate_value) { static int limited_value; if (intermediate_value < 0) { limited_value = 0; } else if (intermediate_value > 254) { limited_value = 254; } else { limited_value = intermediate_value; } return (unsigned char) (limited_value); } Code:
pwm01 = pwm03 = Limit_Mix(PWM_in1 + PWM_in2  127); /* LEFT WHEELS */ pwm02 = pwm04 = Limit_Mix(PWM_in2  PWM_in1 + 127); /* RIGHT WHEELS */ 
#6




Re: Help with limit mix
Quote:
Code:
pwm01 = pwm03 = Limit_Mix((int)PWM_in1 + PWM_in2  127); /* LEFT WHEELS */ pwm02 = pwm04 = Limit_Mix((int)PWM_in2  PWM_in1 + 127); /* RIGHT WHEELS */ 
#7




Re: Help with limit mix
Quote:
does it make the PIC treat all variables (PWM_in2 & PWM_in1) in the Parenthesis like an int instead of a char ? 
#8




Re: Help with limit mix
Quote:

#9




Re: Help with limit mix
Quote:
This "Limit Mix / why add 2000?" question is one that gets asked A LOT by teams up in Canada. I usually refer people to a post on the FIRST Greater Toronto Regional forums: http://www.firstcanadianregional.org...opic.php?t=500 Hope that sheds some light into the situation! SlimBoJones... 
Thread Tools  
Display Modes  Rate This Thread 


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Robot Weight Limit: Rule Conflict  Specialagentjim  Rules/Strategy  10  08062005 04:52 PM 
limit switches  stephenthe1  Programming  28  05112005 03:37 PM 
Robot Controller File Size Limit ??  RoboGeek  Programming  1  01172005 06:59 PM 
material cost limit  haverfordfords  Fundraising  3  12062004 06:21 PM 
Limit Switches help.  Xufer  Programming  9  04212004 08:21 PM 