Control Law Simulator

The purpose of this section is to let you play with a control system and vary the P, I  and D gains and see the effect of the changes on the systems performance.  Hopefully, this will give you an intuitive feel for what the gains do and how to change them when your robot is not performing acceptably.

You have two choices at this point:

 If you are running a PC with Windows, you can download a Visual Basic version of the simulator.  This simulator provides for the two kinds of steering control systems we have used in our examples so far: a differential steering robot; and a car type steering robot.  A set of suggested instructions is provided for each simulation to guide you through a number of demonstrations.  At any time, you can set up your own tests and see what happens.

If you can't run the VB simulation on your computer, you can run it over the internet. (maybe someday, but not yet).

The simulator allows you to set up the robot in a position relative to a reference line.  Y is the starting distance from the line,  Angle is the angle of the robot's body relative to the line, and Offset is a bias put into the system to show the effect of the integrator term.   You can then insert gains for the P, I and D terms of the equations and run the simulation.  The simulation will run in real time providing three plots.  The first is of the distance from the line, the second is of the angle and the third is a picture of the robot as it maneuvers to the line.

The differential steering robot shows its steering command by the angle of the robot toward the line.   The car type steering robot shows the steering command as the angle of the front wheel. 

Download Simulator

Many thanks to Lior Elazary for implementing this simulator in Visual Basic.  If you are interested in seeing how the simulator works, or modifying it, you can download it from his website at:

Some notes on the simulations:

    Up until now, the discussion has been about some theoretical robots.   When you build a simulation, you have to decide whether to implement a real robot or one that demonstrates the theories.   The main point of my having two different types of robots to discuss is to show the difference between the Differential steering robots ability to turn independently of forward motion and the Car-type robots' need to travel forward to turn.

    If you build a real differential steering bot, which has limits on motor speed, the only time that turning will really be independent of forward motion is if the robot stops, pivots and then proceeds forward again.  Many robots are controlled and steered in this manner.  However, this technique doesn't make much use of PID type steering equations. 

    Your robot will probably be designed to drive forward at a constant speed and to make turns by slowing one wheel to turn in that direction.  In this case, the motion will look much the same as that of the car steering type robot; in that the turn occurs over time and distance.  In fact, a differential steering robot can be made to follow the same path as a car steering type.  The reverse is not true, a car steering robot can't pivot in place like a differential type.

    Since the purpose of the simulation is to show the difference between the two types,  the differential robot is simulated as the theoretical version.  That is, turns will be made instantaneously and independent of forward speed.  A differential robot can be built in real life to come pretty close to this operation just by having motors which can move much quicker than the commanded forward speed so that they have power left over to make quick turns.

    If you play with the simulator much, you may find that it shows some strange performance when very large values are used for some of the adjustable terms.  This is because the simulation makes some approximations in computing the results.   Most simple control equations are designed to work in a relatively narrow range around zero error.  The simulation works for a reasonable range; but, if the range is exceeded, you may see impossible things like the robot model pointed to the left while moving to the right.  Within the range of the sample demonstrations provided with the simulation, the performance is very similar to what you might expect with a real-world robot.

For those interested, the motion equations for the two robots follow. 

The terms are:

    SteerCmd   is the steering angle calculated by your control laws.  It is the angle of the front wheel in the car type steering robot, and the angle of the robot in the differential type.  It's in degrees

    Angle is the angle of the robot relative to the reference straight path.  Also degrees

    Speed is the rate at which the robot is proceeding forward. inches per second.

    Rate is the speed at which the robot is moving sideways relative to the path. inches per second.

    X is the distance traveled in the forward direction.  It is simplified by ignoring the cosine of the angle which actually would make X a bit shorter. Inches

    Xlast  is the value of X from the previous calculation.  It is used to figure how far the robot moved in the last interval.

    Y is the distance sideways from the reference  path. Inches

Note that the only difference between the two following sets of code is that the Differential steering version has Angle proportional to SteerCmd; and the car steering type has it as the INTEGRAL of SteerCmd.

Differential steering:

    Angle = SteerCmd                    'SteerCmd is the angle of the robot
    Rate = Speed * sin(angle/57.3)
    X = X + Speed/20                    'assumes calculated 20 times per second
    Y = Y + Rate/20

Car type steering:

    Angle = Angle + SteerCmd * (X-Xlast)
    Rate = Speed * sin(angle/57.3)
    X = X + Speed/20                    'assumes calculated 20 times per second
    Y = Y + Rate/20

  Return to the Control law menu to select the next subject