Arduino Forum

Topics => Robotics => Topic started by: bolus66 on Mar 12, 2015, 09:45 pm

Title: self balancing pid?
Post by: bolus66 on Mar 12, 2015, 09:45 pm
I know there were many similar topics, but I am still confused. I cannot get the right values of pid. I know the whole 'procedure' or finding pid values. I tried many times, many combinations. Still nothing. It is even hard to find the value of kP when the robot oscillates, because it's kind of vibrating at balanced position for most of the time. The best I did, it was vibrating for 3 seconds and then falling over. I tried with only PD, only PI or all PID. The other thing is I had to 'move' the speed from 0->255 to 70 -> 255 because my motors don't move at low values. These are motors I am using: http://www.ebay.ie/itm/141580923267?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

Code: [Select]

float lastError = 0;
float integrated = 0;
float setPoint = 0;
float error = 0;
float Pterm = 0;
float Iterm = 0;
float Dterm = 0;
// set PID gains
float kP = 120;
float kI = 0;
float kD = 190;
// set max and min outputs
int outMax = 255;
int outMin = -255;

float calcPid(float currentInput)
{
 
  error = setPoint - currentInput;
  Pterm = error * kP;
  integrated += error;
 
  Iterm = kI * constrain(integrated, outMin, outMax);
  Dterm = (error - lastError) * kD;
 
  float calcPID = Pterm + Iterm - Dterm;
 
  if(calcPID > 0) calcPID = calcPID + 70;
  if(calcPID < 0) calcPID = calcPID - 70;
 
  calcPID = constrain(calcPID, outMin, outMax);
  // remember variables
  lastError = error;
 

  // send pid to drive motors
  return calcPID;
}

Title: Re: self balancing pid?
Post by: bolus66 on Mar 13, 2015, 05:00 pm
Update: Even with value kp = 2000, robot only vibrates/jitters around error = 0. I cannot find the 'oscillation point'. Oscillation means that the robot vibrates? I am not sure how to understand it. Anybody knows something about it? Thanks
Title: Re: self balancing pid?
Post by: jremington on Mar 13, 2015, 09:05 pm
No one will be able to help, unless you post all the code.
Title: Re: self balancing pid?
Post by: bolus66 on Mar 13, 2015, 09:39 pm
I'll answer to myself  :D  I've found a solution. Thanks