DECLARE SUB sxmoving () DECLARE SUB sxformatv (num!, num$) DECLARE SUB sxformata (num!, num$) DECLARE SUB sxformat (num!, num$) DECLARE SUB sxerr () DECLARE SUB rs232in (msg$) DECLARE SUB rs232out (msg$) '**************************************************************************** 'This module contains subroutines to control a Compumotor stepping motor 'with an SX indexer/drive with RS232 interface. ' 'Zachary Wolf '12/16/97 '**************************************************************************** 'Module level parameters COMMON SHARED /sxdrive/ sxrs232addrP$, ccwsoftlimitP$, cwsoftlimitP$, limitdecelP$, accelP$, decelP$, velP$ 'Semi-permanent parameters CONST nstepsperrevP& = 25000 'motor steps CONST sxrs232openparP$ = "COM2:9600,N,8,1,ASC,RS,CD0,CS0,DS0" SUB sxerr '**************************************************************************** 'This subroutine reports any errors from the SX indexer. ' 'Zachary Wolf '1/6/98 '**************************************************************************** END SUB SUB sxformata (num!, num$) '*************************************************************************** 'This subroutine formats numbers for the SX drive. ' 'Input: ' num!, number to format ' 'Output: ' num$, formatted number in a string ' 'Zachary Wolf '1/14/98 '*************************************************************************** 'Open a temporary file to write to filenum% = FREEFILE OPEN "temp.tmp" FOR OUTPUT AS #filenum% 'Output the number PRINT #filenum%, USING "####.##"; num! 'Close the file CLOSE filenum% 'Open the temporary file to read filenum% = FREEFILE OPEN "temp.tmp" FOR INPUT AS #filenum% 'Input the number into a string INPUT #filenum%, strnum$ 'Close the file CLOSE filenum% 'Delete the temporary file SHELL "del temp.tmp" 'Return the number in a string num$ = LTRIM$(RTRIM$(strnum$)) END SUB SUB sxformatv (num!, num$) '*************************************************************************** 'This subroutine formats numbers for the SX drive. ' 'Input: ' num!, number to format ' 'Output: ' num$, formatted number in a string ' 'Zachary Wolf '1/14/98 '*************************************************************************** 'Open a temporary file to write to filenum% = FREEFILE OPEN "temp.tmp" FOR OUTPUT AS #filenum% 'Output the number PRINT #filenum%, USING "##.#####"; num! 'Close the file CLOSE filenum% 'Open the temporary file to read filenum% = FREEFILE OPEN "temp.tmp" FOR INPUT AS #filenum% 'Input the number into a string INPUT #filenum%, strnum$ 'Close the file CLOSE filenum% 'Delete the temporary file SHELL "del temp.tmp" 'Return the number in a string num$ = LTRIM$(RTRIM$(strnum$)) END SUB SUB sxgetencpos (dlines&) '**************************************************************************** 'This subroutine reports the encoder position in encoder lines from zero. 'Positive dlines& corresponds to CW rotations. Negative dlines& corresponds 'to CCW rotations. ' 'Output: ' dlines&, encoder position in lines from zero (+ CW, - CCW) ' 'Zachary Wolf '12/18/97 '**************************************************************************** END SUB SUB sxgetinputs (inputs$) '**************************************************************************** 'This subroutine gets the state of the inputs to the SX indexer. ' 'Output: ' inputs$, state of the inputes to the SX indexer ' 'Zachary Wolf '12/16/97 '**************************************************************************** END SUB SUB sxgetmotpos (d!) '**************************************************************************** 'This subroutine reports the motor position d! in revolutions from zero. 'Positive d! corresponds to CW rotations. Negative d! corresponds to 'CCW rotations. ' 'Output: ' d!, motor position in revolutions from zero (+ CW, - CCW) ' 'Zachary Wolf '12/16/97 '**************************************************************************** END SUB SUB sxgohome '**************************************************************************** 'This subroutine has the SX motor go the the home position. ' 'Zachary Wolf '12/17/97 '**************************************************************************** 'Go home CALL rs232out(sxrs232addrP$ + "GH") END SUB SUB sxinit '**************************************************************************** 'This subroutine initializes the Compumotor SX indexer/drive. ' 'Zachary Wolf '12/15/97 '**************************************************************************** 'Message PRINT PRINT "Resetting SX indexer/drive;;;" END SUB SUB sxmoveabs (d!) '**************************************************************************** 'This subroutine has the motor turn to position d! revolutions from zero. 'Positive d! is in the clockwise direction. Negative d! is in the 'counterclockwise direction. ' 'Input: ' d!, number of revolutions to turn to (+ CW, - CCW) ' 'Zachary Wolf '12/16/97 '**************************************************************************** END SUB SUB sxmoverel (d!) '**************************************************************************** 'This subroutine has the motor turn d! revolutions. Positive d! gives 'clockwise rotation. Negative d! gives counterclockwise rotation. ' 'Input: ' d!, number of revolutions to turn (+ CW, - CCW) ' 'Zachary Wolf '12/16/97 '**************************************************************************** END SUB SUB sxmoving '**************************************************************************** 'This subroutine delays program execution until a move is over. ' 'Zachary Wolf '1/14/98 '**************************************************************************** END SUB SUB sxsetaddr (rs232addr$) '**************************************************************************** 'This subroutine sets the RS232 address the SX drive sends commands to. ' 'Input: ' rs232addr$, indexer address (1 to 16) ' 'Zachary Wolf '1/15/98 '**************************************************************************** 'Set the parameters sxrs232addrP$ = rs232addr$ END SUB SUB sxsetpar (rs232addr$, ccwsoftlimit!, cwsoftlimit!, limitdecel!, accel!, decel!, vel!) '**************************************************************************** 'This subroutine sets parameters for the SXDRIVE module. ' 'Input: ' rs232addr$, indexer address (1 to 16) ' ccwsoftlimit!, CCW software motion limit (rev) ' cwsoftlimit!, CW software motion limit (rev) ' limitdecel!, deceleration when a limit is reached (rps^2) ' accel!, acceleration (rps^2) ' decel!, deceleration (rps^2) ' vel!, velocity (rps) ' 'Zachary Wolf '12/15/97 '**************************************************************************** 'Set the parameters sxrs232addrP$ = rs232addr$ ccwsoftlimitP$ = LTRIM$(STR$(FIX(ccwsoftlimit! * nstepsperrevP&))) cwsoftlimitP$ = LTRIM$(STR$(FIX(cwsoftlimit! * nstepsperrevP&))) IF limitdecel! > 0! THEN CALL sxformata(limitdecel!, limitdecel$) limitdecelP$ = limitdecel$ ELSE PRINT "SXSETPAR: problem with limitdecel!" END IF IF accel! > 0! THEN CALL sxformata(accel!, accel$) accelP$ = accel$ ELSE PRINT "SXSETPAR: problem with accel!" END IF IF decel! > 0! THEN CALL sxformata(decel!, decel$) decelP$ = decel$ ELSE PRINT "SXSETPAR: problem with decel!" END IF IF vel! > 0! THEN CALL sxformatv(vel!, vel$) velP$ = vel$ ELSE PRINT "SXSETPAR: problem with vel!" END IF END SUB SUB sxzero '**************************************************************************** 'This subroutine zeros the motor step counter and the absolute encoder 'position counter. ' 'Zachary Wolf '12/17/97 '**************************************************************************** END SUB