go away spammer

Author Topic: PID trajectory control  (Read 2377 times)

0 Members and 1 Guest are viewing this topic.

Offline mdavTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
PID trajectory control
« on: January 10, 2013, 09:15:27 AM »
I'm trying to implement PID control for a two wheeled car. The car has two DC motors with optical encoders and an H-bridge. The device needs to move along a straight-line path with predetermined acc/dec ramps on both ends. I can determine the target position of the wheels by calculating the area under the velocity/time curve at each sampling interval.

My question concerns how to use the PID error to keep the car on track and on schedule.

My guess is that I should determine the current error by subtracting the current encoder position from the previous target position (where I should be now). Then, for each wheel, by adding Kp*error + Ki*errSum + Kd*dErr to the new setpoint (next target position), I can calculate the speed of each wheel necessary to get to this new position in the time interval (speed = pulses x delta_t). From there I get the new pwm value. Etc.
For instance if my current error for the left wheel is +6 pulses I subtract whatever I get by running this through the PID algorithm from the change in setpoint (new target - previous target) and divide this by the sampling interval to get my new speed. From this I can determine the new pwm duty cycle.

Is my thinking correct?

Thanks

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,345
  • Helpful? 82
Re: PID trajectory control
« Reply #1 on: January 10, 2013, 11:03:02 AM »
Yes, that is how these systems work. Usually, the "sumError" is actually a "leaky integrator" -- either the sum of the error for the last N data points, or a simple "new = old * alpha + sample * (1 - alpha)" single-pole filter. This is so that very old errors don't affect the integrator for the current situation.

Getting good PID values can be a time-consuming trial-and-error process. While you can put in "theoretically correct" numbers, all the various non-ideal behaviors of the real world may make the best set of parameters significantly different. Sometimes, jumping one of the values by a factor of 2, or 4, just to get a good sense of what the right order of magnitude should be, is the fastest way to the optimal solution. It's like doing manual simulated annealing on the PID values with your eyes and senses as the "fitness function" :-)

Offline mdavTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: PID trajectory control
« Reply #2 on: January 10, 2013, 11:17:51 AM »
Thanks for the confirmation

Offline Robot Attack

  • Jr. Member
  • **
  • Posts: 16
  • Helpful? 0
Re: PID trajectory control
« Reply #3 on: January 10, 2013, 10:13:48 PM »
A good rule of thumb when beginning to tune a PID system is to start I and D gains at zero. Increase P until your system becomes unstable, then back it off, maybe by 1/2.

It is very likely that P gain is all that you will need

Offline mdavTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: PID trajectory control
« Reply #4 on: January 11, 2013, 07:56:03 AM »
Thanks for the tip. I understand that tuning is largely a matter of trial and error.

 


Get Your Ad Here

data_list