/******************************************************
 * pid                                                *
 *                                                    *
 *  Created on: Apr 15, 2013                          *
 *      Author: jdn                                   *
 *                                                    *
 ******************************************************
 *                                                    *
 *                                                    *
 * this version adapted for Arduino                   *
 *                                                    *
 * (C) 2012,2013                                      *
 *                                                    *
 * Jens Dalsgaard Nielsen <jdn@es.aau.dk>             *
 * http://www.control.aau.dk/~jdn                     *
 * Studentspace/Satlab                                *
 * Section of Automation & Control                    *
 * Aalborg University,                                *
 * Denmark                                            *
 *                                                    *
 * "THE BEER-WARE LICENSE" (frit efter PHK)           *
 * <jdn@es.aau.dk> wrote this file. As long as you    *
 * retain this notice you can do whatever you want    *
 * with this stuff. If we meet some day, and you think*
 * this stuff is worth it ...                         *
 *  you can buy me a beer in return :-)               *
 * or if you are real happy then ...                  *
 * single malt will be well received :-)              *
 *                                                    *
 * Use it at your own risk - no warranty              *
 *                                                    *
 *****************************************************


SIMPLE PID CONTROLLER - full configurable

	err = setpt - output
  sys = Kp*err + Kd d(err)/dt + Ki Intr(err)
  output = output from phys proces with sys as input

See pid.png in this directory
*****************************************************/

#include <pid.h>

struct parmBlk pid;


void setup()
{
  pid.epsilon = 0.01;
  pid.dt = 0.01;  // 10 msec sampling assumed
  pid.imin = -4;
  pid.imax = 4;
  pid.kp = 0.1;
  pid.kd = 0.01;
  pid.ki = 0.005;
  pid.pre_error = pid.integral = 0.0;
}

void loop()
{
float pos, output;

  //measure output from proces
  //pos = analogRead(xx); ...

  output = pPID(&pid,2.4,pos);

  //and now output to proces
  //analogOut(output);

	//proper timing is your problem
}
