Shop OBEX P1 Docs P2 Docs Learn Events
Robot PID Sample Rate Question — Parallax Forums

Robot PID Sample Rate Question

bobledouxbobledoux Posts: 187
edited 2005-01-27 14:25 in Learn with BlocklyProp
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?

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2005-01-26 17:34
    1. There may be very few people with PID experience with a BS2, and even fewer who realize that what they are doing to control their robot is called PID. So there may be few people to answer your question. Sorry about that.

    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 McCorisonJim McCorison Posts: 359
    edited 2005-01-26 19:49
    You might want to read the thread at http://forums.parallax.com/showthread.php?p=522858 which went into some of this, including sample code.

    Jim
  • bobledouxbobledoux Posts: 187
    edited 2005-01-27 14:25
    Thanks for the response.

    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.
Sign In or Register to comment.