View Single Post
  #14   Spotlight this post!  
Unread 15-01-2007, 16:09
maniac_2040's Avatar
maniac_2040 maniac_2040 is offline
Registered User
AKA: Matt
FRC #3302 (Turbo Trojans)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Clawson, Michigan
Posts: 34
maniac_2040 is infamous around these partsmaniac_2040 is infamous around these partsmaniac_2040 is infamous around these partsmaniac_2040 is infamous around these parts
Send a message via MSN to maniac_2040
Re: Potentiometer PID

Quote:
Originally Posted by DustinB_3 View Post
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