                        MD-2 Dual Stepper Motor System

                                MD2QB1S.TXT

        Quick-Basic Level 1 Motion Control Subroutines Documentation

                     Copyright (c) 1993 Arrick Robotics



FILE NAMES:

File names describe their contents.
Here are SOME of the posibilities:

    MD2QB1S.BAS   <----  .BAS = Basic source code.
    |  | ||              .TXT = (Text) documentation file.
    |  | ||              .BI  = Basic include file.
    |  | ||              .EXE = Executable program.
    |  | ||              .MAK = Make file.
    |  | ||              .FRM = Form.
    |  | ||              .INI = Configuration & parameters.
    |  | ||
    |  | | ------------- S=Subroutine Library.
    |  | |               E1=Example program #1, etc.
    |  | |               F1=Form #1, etc.
    |  | |               T=Programming tools.
    |  | |
    |  |  ----------- 1 = Level 1 subroutine library.
    |  |              2 = Level 2 subroutine library, etc.
    |  |
    |   --------- QB = Quick Basic.
    |             QI = Q Basic Interpreter.
    |             VD = Visual Basic for DOS.
    |             VW = Visual Basic for Windows.
    |             BI = Basic Interpreter with line #'s.
    |             QC = Quick C.
    |
     -------- MD2 = MD-2 Dual Stepper Motor System.


See the MD-2 manual for other information on hardware and software.


LEVEL 1 SUBROUTINE LIBRARY OVERVIEW:

Different levels of motion control subroutines are available to provide
different levels of sophistication, features and performance.
The level 1 subroutines offer the most basic features needed to move
the motors of the MD-2 system.  There are not any fancy features
such as ramping, linear interpolation, multi-motor moves, or units
conversion.  The library includes all the subroutines necessary to
control up to 6 motors.  All motor parameters are global variables. The
programmer simply sets the desired parameters such as speed, direction
and distance and calls the subroutine.  The library is very easy to use
and can be easily connected to other subroutine libraries such as those
provided with data aqusition systems.  The level 1 subroutines are not
put in SUB's for multi-module program to reduce confusion, they are
easily put in this form by the progammer if needed.

These subroutines have the following features:

    Complete control of all motion parameters - speed, direction, etc.
    Control up to 6 motors on one computer.
    Single motor moves only.
    Only constant speed moves, no ramping.
    Relative moves only, (step count & direction).
    Motor homing using switches.
                                      

THE MD-2 SYSTEM:

The MD-2 dual stepper motor system is a complete dual axis motion
control system that connects to any IBM style personal computer.  The
system comes complete with 2 motors, cables, drive electronics, software
and documentation.  Simply connect the MD-2 to a printer port and load the
software.  These motors can be used to control a wide range of items
including robotic arms, telescopes, cameras and lazers.  The operator and
programmer have complete control over the speed, direction and other
parameters of the motors.  Sophisticated motion control programs can be
created to accomplish almost any job.


PARALLEL PRINTER PORTS:

The MD-2 dual stepper motor system connects to the parallel printer
port of any IBM style personal computer using a standard printer
cable.  There can be as many as 3 parallel printer ports on a single
computer.  Since each port can be attached to an MD-2, a total of
6 motors can be controlled with a single computer.  Each port has
its own address.  The three possible addresses are 3BC, 378 and 278.
When adding a new printer port, make sure that no two ports have the
same address.  The MD-2 software refers to the motors connected to the
MD-2 which is connected to port 3BC as 1 & 2, port 378 as 3 & 4, and
port 278 as 5 & 6.  Your system may only have one or two ports.  Since
the motor numbers are determined by which port they are connected to,
your system may have motors 3 & 4 or 5 & 6 but not 1 & 2.  You may wish
to keep your 3BC port connected to your printer so it can be refered to
as LPT1: or PRN: in which case your MD-2 motors would be 3 & 4 or 5 & 6.
Parallel printer port cards are very inexpensive and are normally
available at local computer stores or by mail-order.


SUBROUTINE DESCRIPTION:

The level 1 subroutine source code file contains several subroutines
that can be used by the programmer to control the MD-2 system.  All
motor parameters are in the form of global variables.  To use, the
programmer simply sets the motor parameter variables to the desired
settings and calls the subroutine using a GOSUB statement.

The subroutines are listed below:

    NAME            DESCRIPTION
    ----            -----------

    MD2SETUP        Used at the beginning of a program to initialize
                    motor parameters to their default values.
                    Use this subroutine before any other.

    MD2ON           Turns on an MD-2 controller.

    MD2OFF          Turns off an MD-2 controller.

    MD2HOME         Moves a motor to the Home position by watching the
                    home switch.  Current position is set to zero.

    MD2MOVE         Moves a motor using the selected motor parameters.


MOTOR PARAMETERS AND VARIABLES:

Motor parameters are global variables.  Each one begins with the
letters 'MD2' to minimize naming conflicts.

    NAME            TYPE    DESCRIPTION
    ----            ----    -----------

    MD2HOLD         INTEGER -1=Leaves the motor energized after a move
                            to cause the motor to hold its position.
                            0 causes the motor to turn off after a move
                            which conserves power and reduces heat.
    MD2MOTOR        INTEGER The selected motor to act upon. 1,2,3,4,5 or 6.
    MD2SPEED(M)     INTEGER Delay count between steps. 0=fast, 32766=slow.
                            Actual motor speed depends on the computer.
                            M is the motor number 1,2,3,4,5 or 6.
    MD2POSITION(M)  LONG    Current motor position for each motor (M=motor #)
                            relative to home in steps. Negative are reverse
                            from home and positive are forward from home.
                            M is the motor number 1,2,3,4,5 or 6.
    MD2STATUS       STRING  Completion status. O=motion completed OK,
                            K=a keypress stopped the motion, B=Bad parameter.
    MD2TARGET(M)    LONG    The number of steps to move.  Positive numbers
                            are forward, negative numbers are reverse.
                            M is the motor number 1,2,3,4,5 or 6.


HOMING MOTORS:

Each motor on the MD-2 system has a home switch associated with it.
At the beginning of a program, the software does not accuratly know
the positions of the motors.  Homing causes the motor to seek the
home switch to establish the home position (position zero).  All
moves are relative to this home position.  The programmer or operator
can, at any time, home the motors to insure accurate positioning.
This is not necessary in most situations where the home function is
only used at the beginning of a program once.  The MD2HOME subroutine
moves the motor reverse (clockwise as viewed from the front of the
motor) until the home switch is activated, then forward until the switch
is deactivated. This sequence has the effect of preloading the
mechanical system in the forward direction which will increase the
accuracy of systems which have backlash or belt stretch.
A new home position can be established by homing the motor normally,
moving to the desired location, then setting the MD2POSITION(M)
parameter to zero.  All motions thereafter will be relative to
this new home position.  This can be used to duplicate motion
sequences for step and repeat operations without modifications
to the fundamental program.  During home moves, the motor will move
at a constant speed. The home switches may also be used for general
purpose inputs by reading them with input statements.


MOVING MOTORS:

A motor is moved by setting the motor parameters and using a GOSUB
statement to the MD2MOVE subroutine.  The MD2MOTOR parameter determines
which motor is to be moved (1,2,3,4,5 or 6). The MD2TARGET(M) parameter
determines how many steps the motor will move and the direction.
Positive numbers will move forward and negative numbers will move
reverse.  The motor will move at a constant speed determined by the
MD2SPEED(M) parameter.  See the section on motor speeds for more
information.  The MD2POSTION(M) parameter will be set to the motor's
position relative to home in steps.  A motor move can be stoped
by pressing any key on the keyboard.  The home switches are ignored.
The motor may be left energized or de-energized depending on the
value of the MD2HOLD parameter.  If MD2HOLD=0 then the motor will
be de-energized, if -1 then power will be left on the motor which
results in holding torque and motor heat.


MOTOR SPEEDS:

Motor speeds are given in delay counter values.  This number is the
delay time between steps which determines the motor speed.
A small number will move the motor fast, a large number will move the
motor slower.  Speed values depend greatly on the computer's speed.
Fast computers will require higher speed values in order to achieve
the same speed as slower computers with smaller numbers.  This means
that a motion control program may act differently on different computers.
The operator needs to have the option of changing the speed values
for optimum operation on a particular computer.
Finding the correct speed values requires experimentation.  If the
speed value is to small (fast), the motor may just vibrate without
moving.  This condition does not harm the motor or driver.  Increase
the speed value (slower) until the motor begins to move without
missing steps or vibrating, then increase the value another 30% or
so to give a margin of error.
If a motor ever misses steps, then the MD2POSITION(M) variable will
not accurately represent its current position.  Select motor speeds
that are slow enough to prevent missed steps causing this condition.
Homing the motors can be used to resyncronize the system.


PROGRAMMING EXAMPLE:

Controlling the MD-2 stepper motor system is simply a matter of setting
the desired motor parameters via global variables and calling the
appropriate subroutine.  The following example program shows how to use
the subs and parameters.  The DIM statements in the subroutine library
must be moved to the beginning of the program as required by Quick-Basic.
It may be necessary to change the MD2SPEED(M), and MD2MOTOR parameters
for this program to operate on your computer.


START:

    'MOVE DIM STATEMENTS FROM SUBROUTINES TO HERE...
    DIM . . . .
    DIM . . . .

    'YOUR CUSTOM PROGRAM BEGINS HERE...

    CLS
    GOSUB MD2SETUP          'SET DEFAULTS AND FINDS PORTS.

    'TURN ON MD-2 FOR MOTORS 3 & 4.
    MD2MOTOR = 3            'MOTOR 4 WOULD ALSO WORK HERE.
    GOSUB MD2ON             'TURN ON MD-2.

    'SET MOTOR PARAMETERS THAT ARE DIFFERENT THAN DEFAULTS.
    MD2SPEED(3) = 2500      'SET SPEED FOR MOTOR 3.
    MD2SPEED(4) = 1000      'SET SPEED FOR MOTOR 4.

    'MOVE MOTORS 3 & 4 HOME.
    MD2MOTOR = 3            'MOVE 3 HOME.
    GOSUB MD2HOME
    MD2MOTOR = 4            'MOVE 4 HOME.
    GOSUB MD2HOME

    'MOVE MOTOR 3 275 STEPS FORWARD.
    MD2MOTOR = 3            'MOTOR 3.
    MD2TARGET(3) = 275      '275 STEPS FORWARD.
    GOSUB MD2MOVE           'MOVE THE MOTOR.
    PRINT "STATUS IS ";MD2STATUS        'DISPLAY STATUS.

    'MOVE MOTOR 4 400 STEPS FORWARD.
    MD2MOTOR = 4            'MOTOR 4.
    MD2TARGET(4) = 400      '400 STEPS FORWARD.
    GOSUB MD2MOVE
    PRINT "STATUS IS ";MD2STATUS        'DISPLAY STATUS.

    'MOVE MOTOR 3 100 STEPS REVERSE.
    MD2MOTOR = 3            'MOTOR 4.
    MD2TARGET(3) = -100     '100 STEPS REVERSE.
    GOSUB MD2MOVE
    PRINT "STATUS IS ";MD2STATUS        'DISPLAY STATUS.

    'DISPLAY MOTOR POSITIONS.
    PRINT "MOTOR 3 POSITION IS: ";MD2POSITION(3)
    PRINT "MOTOR 4 POSITION IS: ";MD2POSITION(4)

    'TURN OFF MD-2 SYSTEM.
    MD2MOTOR = 3            'SELECT MOTOR AT THAT PORT.
    GOSUB MD2OFF            'TURN OFF MD-2.

    END

    'YOUR CUSTOM PROGRAM ENDS HERE.

    'MD-2 SUBROUTINES START HERE . . .


USING QUICK-BASIC:

Quick-Basic is a Basic language compiler that is very easy to use.
The following sequence can be used to create a custom program using
the MD2QB1S.BAS library.  It should be used as a guildline only.
Your system may require different commands and steps.  Basic knowledge
of DOS, your computer and Quick-Basic is required to accomplish this.

1   Make a directory on the hard disk to contain the MD-2 files
    and programs.  Example from the DOS prompt:  MD C:\MD2 (Enter)

2   Copy the files from the distribution floppy disk to the hard
    disk.  Example from the DOS prompt:  COPY A:*.* C:\MD2 (Enter)

3   Change to the MD-2 directory.  Example:  CD \MD2 (Enter)

4   Run Quick-Basic.  Example:  QB (Enter)

5   Select 'Open File' from the FILE menu.

6   Enter MD2QB1S.BAS for loading.

7   Move the DIM statements to the very beginning of the program
    as required by Quick-Basic.

8   Enter your program between the DIM statements and the subroutines.

9   Select 'Save As' from the FILE menu to save your custom program.

10  Run your program by selecting 'Start' from the RUN menu.

11  Consult your manual or on-line help for more information on
    Quick-Basic.


END OF DOCUMENTATION:

