"TrashE" Robot and PID Lib problems

Hi,

I was recently experimenting with a crappy little robot, made mostly (beside the Arduino!) out of crap, like old wacky servos, CDs, old Lipo accumulators etc.

Hardest thing is to get that thing go in a straight line…

So I use the PID Library. But when I start TrashE turns a while to the right, then slowly it goes straight. After that “init” it keeps quite a straight line.

Here some code to illustrate:

[...]

float p = 3.0;       // 2.0
float i = 1.15;      // 0.15

[...]

void driveDist(long dist, int dspeed)
{
  long startdist = odoy;
  long odxa = 0;
  long ddx = 0;
  int count=0;
  float steer=0.0;
  int speed=0;

  myPID.SetSampleTime(70);
  myPID.SetOutputLimits(0.0,MIDH);    // clamp output

  Setpoint=125.0;                // 127 means no deviation, 0 full right, 255 full left
  Output=MID2;

  while(odoy<startdist+dist)
  {
    safemode();                    // checks "safety" switch

    getSensors();                  // get Sensors
    ddx = odox-odxa+128;           // is PID Lib capable of doing +/- values? I think not, therefore add 128
    odxa = odox;

   if (count<10)
    {
      speed = (dspeed * count)/10;
    }

    steer = (Output-MID2)*speed;

    if (enable)
    {
      lservo.write(STOP-speed+steer);             
      rservo.write(STOP+speed+steer);              
    } 

     Input=float(ddx);
    myPID.Compute();

    count++;
    if (count%5==1)                  // refresh display every 50th cycle
    {
      myPID.SetTunings(p, i, 0.0);    // set p/i according to interactive setup (panel on robot)

      lcd.clear();
      lcd.print(ddx);
      lcd.setCursor(5,0);
      lcd.print(p);
      lcd.setCursor(11,0);
      lcd.print(i);

      lcd.setCursor(0,1);

      lcd.print("PID: ");
      lcd.print(Output);      
      lcd.setCursor(11,1);
      lcd.print(steer);      
    }
    delay(70);
  }
  stopServos();  
}

Oh, BTW: The information about the distance and the deviation in x direction comes from a optical mouse sensor. That works quite well.

So when I reset the arduino, the Output is always 0.0 making the robot turn right the first few centimeters. As you can see I try to set Output but with no luck…

I have only a very small understanding of the PID params, p I can understand a bit, but the real influence of I is quite obscure to me.

The control when it has moved a while is ok for the first try but the behaviour after a reset is bad.

Any ideas how to get that beast going straight?

Carsten

Argh!

I did set D to 0.0… :-[ :-[

Seems I am coming close now.

Carsten

I still have a drift to the left, is this possible to fix with some PID params?

Carsten