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-17 16:47 in Robotics
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.

Comments

  • Mark GMark G Posts: 11
    edited 2005-01-17 02:23
    Regarding aquisition of distance measurement readings... you will get a statistical improvement in measurement acccuracy by averaging a number of sonar readings. (Picture a bell curve of normal distribution) Averaging will also improve stability between consecutive results. Thereby less likely to cause a Derrivative based system upset from an individual spike in a reading. Obviously averaging will increase the processing time and thereby slow the PID loop update rate and increase the Dead time. Dead time is the time a process takes before reacting to a change. What is acceptable depends on the individual system. A second of dead time in a low speed inches per second crawler is nothing compared to a high speed system moving in MPH



    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.
  • bobledouxbobledoux Posts: 187
    edited 2005-01-17 16:47
    Thanks for the response. I thought my question faced oblivion. Let me explain in greater detail and again ask the question more specifically:

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