Author Topic: Line follower PID help  (Read 2974 times)

0 Members and 1 Guest are viewing this topic.

Offline CanElecTopic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Line follower PID help
« on: January 11, 2009, 07:25:47 PM »
I am trying to implement PID control with my line follower but I am having some trouble. It currently runs with just a big switch case that chooses which outputs to send to the motors depending on the sensor input.

Technically with 6 sensors I have 64 possible sensor combinations, but only 12 that are usuable for the purpose of line following (there would be more used combinations if I wanted to program it to deal with some of the advanced obstacles they put on some of the tracks).

It tracks the line great using what I have implemented so far. Unfortunately when I try to increase its speed, it begins oscillating and can't really track the line at that point. This is where I believe the PID control would be useful, or at least PD control. I believe the derivative would help prevent a lot of these overshots.

I was thinking to make the center position sensor output equal to zero(setpoint), and the outer sensors -5, +5. Then use the PID. Up to this point I can figure things out.

Once the PID calculates an output, I'm confused as to how to send this to the motors, since I'm using a differential drive system. I think I will have to take the PID output, and then use a switch case similar to what I'm using now and map ranges of the PID output to various output combinations for the motors. IE: PID output is -4.77, this would fall within the -4.5 to -5.0 range in my switch case and drive the motors 100% L and 20% R.

This would basically be the same as what I'm using now with the exception of using the PID equation for output. I think what I'm using right now is basically very similar to just the proportional.

Offline cosminprund

  • Robot Overlord
  • ****
  • Posts: 284
  • Helpful? 8
Re: Line follower PID help
« Reply #1 on: January 12, 2009, 02:54:01 AM »
It tracks the line great using what I have implemented so far. Unfortunately when I try to increase its speed, it begins oscillating and can't really track the line at that point. This is where I believe the PID control would be useful, or at least PD control. I believe the derivative would help prevent a lot of these overshots.

Take a look at the OpenServo project, you'll find a lot of information on implementing an PID over there. If you're not strong on C just read the available technical info, don't remamber where I found it but there's a section about algorithms - I'm pretty sure the "C" is "efficient" so it would be difficult to read!

Quote
Once the PID calculates an output, I'm confused as to how to send this to the motors, since I'm using a differential drive system. I think I will have to take the PID output, and then use a switch case similar to what I'm using now and map ranges of the PID output to various output combinations for the motors. IE: PID output is -4.77, this would fall within the -4.5 to -5.0 range in my switch case and drive the motors 100% L and 20% R.

You should calculate the duty cycle, don't use a case statement. The PID algorithm is designed to give you close-to-perfect values for the change in direction, but if you're using a case statement to transform those values in duty cycle's you're limiting the resolution of the PID algorithm output, reducing (or compromising) it's efficiency.

Here's an example. Let's say there's a function named PID that implements the PID algorithm. It takes as input the values from your sensors and returns as output a value from 0 to 100 to be used as the base for the duty cycle calculation:

Code: [Select]
unsigned int PID(void) {
  return 50; // return something based on sensor input
}

int main(void) {
  unsigned LeftDutyCycle;
  unsigned RightDutyCycle;
  while (1) {
    LeftDutyCycle = PID();
    RightDutyCycle = 100 - LeftDutyCycle();
  }
}


 


Get Your Ad Here