'-------------- Device Params ----------------------- Params DRV.OPMODE = 2'position operation mode DRV.CMDSOURCE = 5'command source = AKD BASIC TG UNIT.PROTARY = 4'16 bit position units, 65536 counts/rev UNIT.VROTARY = 0'velocity units = rpm UNIT.ACCROTARY = 0'acceleration units = rpm/sec End Params '-------------- Define (dim) Global Variables -------- Dim homefound as integer Dim targetposition as integer Dim speed as integer 'speed of initial move to sprayposition Dim accel as integer 'acceleration for all moves Dim decel as integer 'deceleration for all moves const MC = 8000'master counts in total cycle const NPOINTS = 501'number of points in cam profile const pi = 3.1415926535 const k = 0.69314718 / 100 const w = 1 / (15 * pi) MBInfo End '-------------- Main Program ------------------------- Main DRV.SWENABLE = 0 homefound = 0 'Enable Interrupts INTR.HWLS.POSSTATE = 1 INTR.HWLS.NEGSTATE = 1 'used for homing if home input not reached first Intr.DRV.FAULTS = 1 'INTR.DISABLE = 1 INTR.DRV.HWENABLE = 1 'Set default values targetposition = 1016 'total distance, in 0.001mm speed = 254 'speed of initial move to targetposition, in mm/s accel = 1000 'mm/s^2 decel = 1000 'mm/s^2 Move.Acc = accel ' Acceleration (drive units) Move.Dec = decel ' Deceleration (drive units) While DRV.HWENABLE = 0 : Wend 'wait for hardware enable DRV.SWENABLE = 1 'enable drive 'Homing, homing uses Input 3 to start homing and Input 4 for the position capture If homefound = 0 Then 'If axis has not been homed, then ... Print "waiting for input 3" While DIN3.STATE = 0 : Wend 'wait for the start home command 'start the homing routine CAP0.MODE = 0 'standard position capture CAP0.TRIGGER = 3 'Use input 4 for position capture CAP0.EDGE = 1 'positive edge CAP0.EVENT = 0 'no pre-conditions must be met CAP0.EN = 1 'Start looking for the capture trigger MOVE.RUNSPEED = 254 'mm/s MOVE.DIR = 1 'negative direction MOVE.GOVEL 'start moving Print "waiting for input 4" While CAP0.STATE = 0 : Wend 'wait for the capture to trigger, if hits neg limit switch then run interrupt Print "captured" MOVE.RUNSPEED = 0 MOVE.GOVEL 'stop moving, zero speed While MOVE.MOVING = 1 : Wend 'wait for motion to stop MOVE.POSCOMMAND = (PL.FB - CAP0.PLFB ) 'set position to the difference between the actual position and captured position Pause (.2) MOVE.RUNSPEED = 50 'mm/s MOVE.TARGETPOS = 0 MOVE.GOABS 'move back to the captured position Pause (1) 'this is the end of the homing routine homefound = 1 'set homefound tag Print "home found" 'DRV.SWENABLE = 0 'disable the motor Print "disabled" Print "end of homing" End If Print "end if" DRV.SWENABLE = 0 'disable the motor Print "disabled" 'Generate a cam that does exponentially-damped sinusoidal 'motion and activate it. Please note that since we are computing '500 points of slave profile here several seconds will elapse 'during the calculation of the cam table. call CamCreate_2 call ActivateCam_2 'Print "wait 2 sec" 'Pause (2) While 1 = 1 : wend 'loops continuously End Main '-------------- Subroutines and Functions ------------ sub CamCreate_2'This code creates a cam whose profile is an exponentially damped sine wave. dim m, s as float dim i as integer CAM.CREATE (2, 501) for i = 0 to NPOINTS-1 m = i * (MC / (NPOINTS-1))'master position s = (1 / exp (1 * k * i)) * sin (2 * pi * w * i)'computed slave position CAM.ADDPOINT(m, 65536 * s) Print i next i end CAM.CREATE end sub sub ActivateCam_2 'DRV.SWENABLE = 0' Need to disable the drive before changing positions EXTENCODER.POSMODULO = MC' Set master modulo value CAM.MASTER = 2'Cam Master = External Encoder EXTENCODER.POSITION = 0'set Master position to 0 MOVE.POSCOMMAND = 0'set slave (AKD BASIC) position to 0 PL.MODPEN = 1'Enable slave modulo PL.MODP2 = 65536'Set slave modulo value DRV.SWENABLE = 1' Enable drive Print "Motor Enabled" Cam.Activate = 2' Start the cam Print "CAM Enabled" end sub '-------------- Interrupt Routines ------------------- Interrupt HWLS.NEGSTATE If homefound = 0 Then 'move to the positive side of the home switch While MOVE.MOVING = 1 : Wend 'wait to stop moving MOVE.DIR = 0 'positive direction MOVE.RUNSPEED = 50 'mm/s MOVE.GOVEL 'start moving While DIN4.STATE = 0 : Wend 'wait to get on the home switch While DIN4.STATE = 1 : Wend 'find positive edge of home switch Pause (0.5) MOVE.RUNSPEED = 0 MOVE.GOVEL 'stop moving, zero speed While MOVE.MOVING = 1 : Wend 'wait to stop moving CAP0.EN = 1 'Start looking for the capture trigger MOVE.DIR = 1 'negative direction MOVE.RUNSPEED = 50 'mm/s MOVE.GOVEL 'start moving ElseIf homefound = 1 Then Print "restarting" Restart End If INTR.HWLS.NEGSTATE = 1 End Interrupt Interrupt HWLS.POSSTATE Print "restarting" Restart End Interrupt Interrupt DRV.HWENABLE Print "restarting" Restart Intr.DRV.HWENABLE = 1 End Interrupt 'Interrupt disable ' Print "restarting" ' Restart ' INTR.DISABLE = 1 'End Interrupt Interrupt DRV.FAULTS Print "restarting" Restart End Interrupt