MD-2 Dual Stepper Motor System MD2QC1S.TXT Quick-C language 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. Even though this library was written and tested using Microsoft Quick-C, it is easily portable to Borland and other C languages with little or no changes. When porting, check the compiler's keywords for input and output instructions since this often differs. 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 by name. 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 CHAR 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 calling the md2move() subroutine by name. 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 md2position[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. Even though this library was written and tested using Microsoft Quick-C, it is easily portable to Borland and other C languages with little or no changes. When porting, check the compiler's keywords for input and output instructions since this often differs. It may be necessary to change the md2speed[M], and md2motor parameters for this program to operate on your computer. /* MD2QC1E1.C Level 1 Quick-C example program # 1 */ /* Include files */ #include /* For outp, inp, kbhit functions */ #include /* For example section */ #include /* For labs function */ /* Function prototypes needed by programmer */ void main(void); /* Example program main */ void md2setup(void); /* Initialize variables */ void md2on(void); /* Turn MD-2 on */ void md2off(void); /* Turn MD-2 off */ void md2home(void); /* Move motor home */ void md2move(void); /* Move motor */ /* Global motor parameters needed by programmer */ char md2status; /* Completion status */ int md2hold; /* Hold motor when done */ long md2position[7]; /* Current motor positions */ int md2motor; /* Selected motor */ int md2speed[7]; /* Motor speeds */ long md2target[7]; /* Target distance and direction */ /* Global motor parameters NOT needed by programmer */ unsigned md2mtradr12; /* Port for motors 1 & 2 */ unsigned md2mtradr34; /* Port for motors 3 & 4 */ unsigned md2mtradr56; /* Port for motors 5 & 6 */ int md2stppat[8]; /* Step pattern array */ int md2patptr[7]; /* Step pattern pointers */ /* main is just an example */ void main(void) { printf("\n\n\nmoving\n"); /* Setup */ md2setup(); /* Turn on MD-2 */ md2motor = 3; md2on(); /* Home motors */ md2motor=3; md2home(); md2motor=4; md2home(); /* Move motors */ md2motor=3; md2target[3]=400; md2move(); md2motor=4; md2target[4]=100; md2move(); md2motor=3; md2target[3]=-400; md2move(); md2motor=4; md2target[4]=-100; md2move(); /* Turn off MD-2 */ md2motor=3; md2off(); /* Print return status */ printf("return status = %c\n",md2status); } /*** Place MD2QC1S.C subroutine library here ***/ USING QUICK-C: Quick-C is a C language compiler that is very easy to use. The following sequence can be used to create a custom program using the MD2QC1S.C 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-C 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:\MD-2 (Enter) 2 Copy the files from the distribution floppy disk to the hard disk. Example from the DOS prompt: COPY A:*.* C:\MD-2 (Enter) 3 Change to the MD-2 directory. Example: CD \MD-2 (Enter) 4 Run Quick-C. Example: QC (Enter) 5 Select 'Open File' from the FILE menu. 6 Enter MD2QC1S.C for loading. 7 Enter your program main() along with the subroutine library. 8 Select 'Save As' from the FILE menu to save your custom program. 9 Run your program by selecting 'Start' from the RUN menu. 10 Consult your manual or on-line help for more information on Quick-C. END OF DOCUMENTATION: