Robot PID Sample Rate Question
bobledoux
Posts: 187
I'm repeating this question here because I'm not getting responses in the Robotics forum. It also deals with industrial processes that might be more appropriate here.
I have a robot:
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?
I have a robot:
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?
Comments
2. If you do your calc 50 times a second, that's every 20 mSec. 20 mSec is a long-ish time for a BS2, so that shouldn't be a problem. Traveling 6 inches/second, you'll do a calc every 0.12 inch.· The concern here is that your system have enough time for its reactions to generate meaningfull error terms·for your corrections.· (I had to edit this to correct it·from earlier -- my math was WAY off before. :-(· ).· So yes, this seems like a realistic value to use.· The distance traveled in 20 mSec can build up enough error term to make your PID algorithm produce useful results.
3. For follow on people: It sounds like he's using a single driven wheel, with a servo-driven steering wheel to adjust the robot's direction. This is different from the two driven wheel, proportional steering the BOEBot uses.
4. I just noticed that 'memory stack' line there. Be aware the BS2 has only 26 bytes of memory, total. You may need to be frugal with your stack, unless you do your summing in the 12C509 and send a single Integral term to the BS2.
Post Edited (allanlane5) : 1/26/2005 5:51:50 PM GMT
Jim
You are correct about the robot. It is tricycle, with a single front drive wheel and two rear steering wheels. To provide consistency of directional control I felt this design was superior to differential wheel drive. Its much like the Arrick Arobot.