                        MD-2 Dual Stepper Motor System

                                MD2BI1S.TXT

      Basic Interpreter 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.
Switching to Quick-Basic or Visual Basic will result in much faster 
program operation.

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:

 LINE   NAME           DESCRIPTION
 ----   ----           -----------

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

 8400  MD2ON        Turns on an MD-2 controller.
       
 8600  MD2OFF       Turns off an MD-2 controller.

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

 9500  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            DESCRIPTION
     ----            -----------

    MD2HOLD         -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        The selected motor to act upon. 1,2,3,4,5 or 6.
    MD2SPEED(M)     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)  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       Completion status. O=motion completed OK,
                    K=a keypress stopped the motion, B=Bad parameter.
    MD2TARGET(M)    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 located at the beginning of the program to operate properly.
It may be necessary to change the MD2SPEED(M), and MD2MOTOR parameters
for this program to operate on your computer.


'DIM statements from MD2BI1S.BAS will be here.

1000 'MD2BI1E1.BAS - BASIC INTERPRETER LEVEL 1 EXAMPLE PROGRAM # 1
1010 'FOR THE MD-2 DUAL STEPPER MOTOR SYSTEM.
1020 'IT MAY BE NECESSARY TO ADJUST THE SPEED AND MOTOR NUMBERS FOR THIS
1030 'PROGRAM TO WORK ON YOUR COMPUTER.

1100 CLS
1110 GOSUB 8000                     'SET DEFAULTS AND FINDS PORTS.
1120 'TURN ON MD-2 FOR MOTORS 3 & 4.
1130 MD2MOTOR = 3                   'MOTOR 4 WOULD ALSO WORK HERE.
1140 GOSUB 8400                     'TURN ON MD-2.
1150 'SET MOTOR PARAMETERS THAT ARE DIFFERENT THAN DEFAULTS.
1160 MD2SPEED(3) = 50               'SET SPEED FOR MOTOR 3.
1170 MD2SPEED(4) = 100              'SET SPEED FOR MOTOR 4.
1180 'MOVE MOTORS 3 & 4 HOME.
1190 MD2MOTOR = 3                   'MOVE 3 HOME.
1200 GOSUB 8800
1210 MD2MOTOR = 4                   'MOVE 4 HOME.
1220 GOSUB 8800
1230 'MOVE MOTOR 3 275 STEPS FORWARD.
1240 MD2MOTOR = 3                   'MOTOR 3.
1250 MD2TARGET(3) = 275             '275 STEPS FORWARD.
1260 GOSUB 9500                     'MOVE THE MOTOR.
1270 PRINT "STATUS IS "; MD2STATUS  'DISPLAY STATUS.
1280 'MOVE MOTOR 4 400 STEPS FORWARD.
1290 MD2MOTOR = 4                   'MOTOR 4.
1300 MD2TARGET(4) = 400             '400 STEPS FORWARD.
1310 GOSUB 9500
1320 PRINT "STATUS IS "; MD2STATUS  'DISPLAY STATUS.
1330 'MOVE MOTOR 3 100 STEPS REVERSE.
1340 MD2MOTOR = 3                   'MOTOR 3.
1350 MD2TARGET(3) = -100            '100 STEPS REVERSE.
1360 GOSUB 9500
1370 PRINT "STATUS IS "; MD2STATUS  'DISPLAY STATUS.
1380 'DISPLAY MOTOR POSITIONS.
1390 PRINT "MOTOR 3 POSITION IS: "; MD2POSITION(3)
1400 PRINT "MOTOR 4 POSITION IS: "; MD2POSITION(4)
1410 'TURN OFF MD-2 SYSTEM.
1420 MD2MOTOR = 3                   'SELECT MOTOR AT THAT PORT.
1430 GOSUB 8600                     'TURN OFF MD-2.
1440 STOP

'MD2BI1S.BAS Subroutines start here.


USING BASIC:

The following instructions will work with most varieties of the
interpretive Basic language.  It should be used as a guildline only.
Your system may require different commands and steps.  Basic knowledge
of DOS, your computer and 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 Basic.  Example:  GWBASIC (Enter).

5   Load the subroutine library by typing   LOAD "MD2BI1S.BAS" (Enter).

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

7   Save your custom program by typing   SAVE "YOURFILE.BAS" (Enter).

8   Run your program by typing   RUN (Enter).

9   Consult your manual or on-line help for more information on the
    Basic language.

To use the example programs (MD2BI1E1.BAS, E2, E3, etc.), replace
step 6 with  MERGE "MD2BI1E1.BAS" (Enter).


END OF DOCUMENTATION:
