Robot PID Sample Rate Question
I’m building a PID experimental robot and need some ideas on PID sample rate.
The robot has three wheels, a front drive wheel and two rear steering wheels in ackerman (automobile type) configuration. The robot is similar to the Arrick Arobot.
The robot is a wall follower. Ultrasonic sonar tells the robot how close it is to the wall. The robot controller, a Basic Stamp 2, times the sonar echo and drives a steering R/C servo. The PID controls the steering servo to maintain a fixed distance from the wall.
How often should I sample the sonar? My Stamp robot control loop will take about 20 milliseconds so I could sample up to 50 times per second. As steering anomalies are occurring slowly I presume a slower sample rate would be reasonable.
The robot has three wheels, a front drive wheel and two rear steering wheels in ackerman (automobile type) configuration. The robot is similar to the Arrick Arobot.
The robot is a wall follower. Ultrasonic sonar tells the robot how close it is to the wall. The robot controller, a Basic Stamp 2, times the sonar echo and drives a steering R/C servo. The PID controls the steering servo to maintain a fixed distance from the wall.
How often should I sample the sonar? My Stamp robot control loop will take about 20 milliseconds so I could sample up to 50 times per second. As steering anomalies are occurring slowly I presume a slower sample rate would be reasonable.
Comments
PID tuning can require a lot of trial and error but a good starting point is one using the Ziegler-Nichols method. Basically the I & D functions are temporarily turned off and the P (proportional ) gain is adjusted to a minimum point so that the system will sustain a consistant amplitude oscillation when upset (hunting). This gain level is called the ultimate Proportional Gain (Pu) . If you plot the output you will see a sinusoidal wave at a constant frequency. The period of this frequency is called the ultimate period (Tu).
Once you determine the Pu and Tu the Ziegler-Nichols method calculates starting PID values as follows:
P= 0.750 * (Pu)
I= 0.625 * (Tu)
D= 0.100 * (Tu)
Using these values as a starting point tune the PID loop so as to quickly adjust the process variable to the setpoint without hunting. If you plot the process variable on a chart you would again see a sinusoidal wave form. But this time it would quickly decrease in amplitude to a straignt line within three or four cycles.
The robot travels along a wall of consistent construction at about six inches per second. My goal is to maintain a fixed distance, about 2 feet from the wall, with no more than a couple of inches of variation.
The process involves three controllers with a Basic Stamp as primary controller.
The steering controller is a PIC 12C509 that sends a servo pulse every 20 milliseconds (ms). A serial line from the Stamp updates it on directional changes. Otherwise it just keeps sending the last directional command to the steering servo. The servo is capable of about 120 degrees of swing, with a serial byte value of 0 to 240 representing about half a degree of swing for each bit of increment.
Ultrasonic reflection measures the distance from the wall. A PIC 12F508 sends the 24Khz pulse. It then starts a timer that increments every 50 microseconds. When the echo is received the number of time increments represents the distance from the wall. Timer overflow indicates no echo was received, an error result. Distance resolution is to about a quarter of an inch. A serial line reports the echo time to the Basic Stamp as a byte value.
The Basic Stamp controls everything in a loop. It performs the PID calculations and sends corrections to the servo controller. The fastest possible loop rate is about 50 times per second. Lower loop rates are possible. The PID sample rate would be defined by the Stamp loop speed. The differential factor would be calculated based on the current echo value compared to some recent echo value. The integral factor would be calculated by summing across a number of recent echo values held in a “first in-last out” memory stack.
My original question was addressed to someone with PID experience. Is a sample rate of 20 to 50 times per second reasonable for my process? Is there a basis to try a faster or slower rate?