Arduino PID Library - Advanced Methods by Brett Beauregard contact: br3ttb@gmail.com
Description: Same as the standard creation function, with an added parameter to allow the implementation of Feed Forward control (see Example 3 below)
Arguments:
Description: Sets the period, in Milliseconds, with which the PID calculation is performed. default is 1000.
Arguments:
Description: Reinitializes the PID working variables. (Input and Output limits remain unchanged.) This function is automatically called on a manual to auto transition
Description: This function tells the controller What 0% and 100% are for the Input. By default these limits are 0-1023: the Arduino analog input limits. Usually the input Min and Max should stay at 0 and 1023, but if you expect your input to be outside this range, you can adjust the limits using this function.
Arguments:
In certain situations, it helps to know when the PID has computed this bit will be true for one cycle after the pid calculation has occurred.
Returns the current Mode
Returns the current Input Minimum
Returns the current Input Maximum
Returns the current Output Minimum
Returns the current Output Maximum
Returns the current Sample Time
Returns the current P_Param
Returns the current I_Param
Returns the current D_Param
/*************************************************** * Feed Forward Example : RepRap Extruder Nozzle Temperature * PID input: Nozzle Temperature * PID output: PWM signal (0-255) to the heater control * Other Input: Plastic Feed rate is being read on input 1 * For the feed forward piece... * The amount of heat we want to add to the nozzle is largely dependent * on how fast plastic is being fed. if the feed is stopped we're going * to want a lot less heat than when the system is running. A pid * control by itself will eventually adjust the heat, but by then the temp * will be really high. feed forward can help with this. * so to make Feed Forward work, at every cycle we look at the current feed speed * and compute a "bias" which we feed to the pid controller. sort of: "Based on my * knowledge, your output should be about X. adjust off of that as you see fit" * What does it get you? well, the instant the feed stops, the baseline drops. That * means that the controller output immediately drops. if you had been using just a pid, * you'd have to wait for the temperature to rise quite a bit before seeing the same * drop in output. * * (for this example, we're assuming that for a feed rate of 1023 the output should be * about 130, and at a rate of 0 the output should be around 10) ***************************************************/ #include <PID_Beta6.h> int FeedRate; double Input, Output, Setpoint, Bias; PID pid(&Input, &Output, &Setpoint, &Bias, 3, 4, 1); void setup() { Setpoint = 400; pid.SetMode(AUTO); //turn on the PID } void loop() { //Read in the Feed rate and compute a baseline output to the heater FeedRate = analogRead(1); //read the feed rate Bias = (FeedRate/1023)*(120)+10; //give the PID the opportunity to compute if needed Input = analogRead(0); pid.Compute(); analogWrite(0, Output); }