'-------------- Device Params ----------------------- Params DRV.OPMODE = 2 'position operation mode DRV.CMDSOURCE = 5 'command source = AKD BASIC TG UNIT.PROTARY = 3 '16 bit position units, 65536 counts/rev UNIT.VROTARY = 0 'velocity units = rpm UNIT.ACCROTARY = 0 'acceleration units = rpm/sec UNIT.PIN = 10000 UNIT.POUT = 1 PL.MODPEN = 1'Enable slave modulo PL.MODP2 = 10000'Set slave modulo value FB2.ENCRES = 8000 'set slave gearing input resolution EXTENCODER.POSMODULO = 8000 ' Set master modulo value 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 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 Move.Acc = 1000 ' Acceleration (drive units) Move.Dec = 1000 ' 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" End If CAM.CREATE (1, 21)'allocate space for cam #1, 5 points 'start the cam create block Print "creating cam profile" Cam.AddPoint(0,0) Cam.AddPoint(400,10) Cam.AddPoint(800,20) Cam.AddPoint(1200,40) Cam.AddPoint(1600,80) Cam.AddPoint(2000,160) Cam.AddPoint(2400,320) Cam.AddPoint(2800,640) Cam.AddPoint(3200,1280) Cam.AddPoint(3600,2560) Cam.AddPoint(4000,5120) Cam.AddPoint(4400,7680) Cam.AddPoint(4800,8960) Cam.AddPoint(5200,9600) Cam.AddPoint(5600,9920) Cam.AddPoint(6000,10000) Cam.AddPoint(6400,10000) Cam.AddPoint(6800,10000) Cam.AddPoint(7200,10000) Cam.AddPoint(7600,10000) Cam.AddPoint(8000,10000) End Cam.Create 'the cam create block Print "done" CAM.MASTER = 2 'Cam Master = External Encoder DRV.SWENABLE = 1 'enable the motor Print "Motor Enabled, wait 2 sec" Pause (2) 'Wait to start the cam until seeing the EEO index pulse CAP1.MODE = 0 'standard position capture CAP1.TRIGGER = 9 'Use input 4 for position capture CAP1.EDGE = 1 'positive edge CAP1.EVENT = 0 'no pre-conditions must be met CAP1.EN = 1 'Start looking for the capture trigger Print "waiting for cap1" While CAP1.STATE = 0 : Wend 'wait for the capture to trigger EXTENCODER.POSITION = 0 'set Master position to 0 MOVE.POSCOMMAND = 0 'set slave (AKD BASIC) position to 0 CAM.ACTIVATE = 1 'activate cam #1 Print "CAM Enabled" While 1 = 1 : wend 'loops continuously End Main '-------------- Subroutines and Functions ------------ '-------------- 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