SIMULATION
Figure 1: An image of a real
stepper motor adds realism
to the elevator simulation.
physical construction of a mechanical system. In most cases,
though, students would learn much more if they could
forego construction and concentrate their efforts on
learning to control the motor, interrogating the sensors, and
developing an appropriate system-level algorithm.
One possible solution is to give each student a pre-built
system so they can begin experimentation immediately.
As you might expect, though, constructing, maintaining,
and storing the necessary equipment usually prevents this
from happening.
It was this type of educational problem that originally
inspired the robot simulator in RobotBASIC. The simulator
allows programmers to concentrate on algorithm
development instead of physical construction. Fortunately,
RobotBASIC’s simulation capabilities extend well beyond
robotic applications. Double-buffered video output (for
flicker-free animation), bitmap manipulation, an easy-to-use
3D graphics engine, matrix math, extensive mathematical
functions, and many other features make it easy
for even a mid-level programmer to develop
professional looking simulations.
Let’s examine one option for simulating an
elevator project controlled by a stepper motor.
The output from the program is shown in
Figure 1. Notice that an actual picture of a
stepper motor has been integrated into the
graphic display. A 3D pointer allows the still
image to move in a realistic manner and
seemingly control a 2D elevator (the motor
drives a spool that winds and unwinds a cable
attached to the elevator).
You can control the simulated stepper
motor by sending it binary codes (1000, 0100,
0010, and 0001) in the proper sequence
through an interface subroutine. The floor and
elevator buttons, along with the limit switch at
the bottom of the shaft, allow a complete
elevator algorithm to be developed without any
physical construction. Programming the system
is surprisingly realistic because the programmer
is forced to control the simulated motor in
the same manner as a real motor. Standard
stepping was used in this example program
but it could easily be modified to handle half-stepping or full-torque drive.
Once you accept the idea of creating simulations for a
virtual laboratory, the options are endless. Figure 2 shows
a simulation of a DC motor suitable for teaching the
fundamentals of speed control. The motor reacts as
expected when the associated mass and friction parameters
are changed. The programmer controls the motor by
specifying the duty cycle to be applied just as they would
with a real world motor controller.
Figure 3 shows another possibility. Two pointers are
attached to two potentiometers which — in the simulation
— are attached to eight-bit A/D converters. A DC gearhead
motor (controlled by direction and duty cycle parameters)
drives the rear potentiometer. The front potentiometer
pointer can be moved with the mouse.
In the demo program, the motor is simply turned on
at a low speed with the proper direction. It is immediately
obvious to the student or programmer that the motor is not
moving fast enough to keep up with the manually moved
pointer. If the program
is changed to increase
the speed, they see
that the motor does,
in fact, move quicker
but the increased
speed causes it to
regularly overshoot its
destination. In only a
few minutes, the
need for a more
sophisticated control
algorithm becomes
apparent, thus
Figure 2: The ability to alter
the mass and friction of the
pulley makes developing an
algorithm for speed control
more relevant.
48 SERVO 06.2009