Quote:
Originally Posted by DustinB_3
Thanks for the whitepaper
I think I understand fairly well, would this work:
int Target;
int Error;
int Gain = 0.5;
int Drive;
int Arm_Out;
if ( p1_sw_trig == 1 )
{
Target = 600 ;
}
else if ( p2_sw_trig == 1 )
{
Target = 1000 ;
}
else if ( p3_sw_trig == 1 )
{
Target = 1600 ;
}
Arm_Out = Get_ADC_Result(2); //GetAnalogInput(Port) Checks the Port and Return 0-1024
Error = (Arm_Out - Target); // Computes Error Based on How Far you are from the goal
Drive = ((Gain * Error)+127); // Based on the gain it outputs a number and then add 127 so the Victor Understands
pwm01 = Drive;
|
Well this particular code will not work because there is one small error. "Gain" is an integer. When you assign the value 0.5 to it(a double) it will chop off the decimal places and just assign 0 to it. This means the Drive pwm will always be 127:
(Gain * Error)+127
is really
(0 * Error) + 127