Blog:Programming IntelLigent Actuators (part3)
To complete this illustrative programming exercise, we will add another typical layer of complexity, called Multithreading.
This will give us the capability to run 2 independent programs simultaneously. One of those programs will be what we have created so far. The second program will be new.
Its task will be twofold: control the status of the first program and setting up motion to be able to use an analog joystick. When this joystick mode is enabled, the speed and direction will be controlled by an axis associated analog input. The joystick axis will also have the ability to latch and capture the position and/or an encoder value based on triggering an assigned input on a given axis. This function is useful in applications where one needs to be able to go back and view something, such as in microscopy, to teach/record points in a CNC routing application...
PRG 0 ; Starting point for Program 0
ABS ;Sets absolute mode
IF DI1=1 ; looks at status of input 1 GOSUB 1 ELSE
GOSUB 2 ENDIF END : end of program
SUB 1
X2000; Moves X axis 2000 steps
WAITX; wait for move complete
Y2000; Moves Y axis 2000 steps
WAITY; wait for move complete
ENDSUB
SUB 2
HSPDX=V50; sets the speed of the X axis to the value in Variable 50
XV90; Moves X axis to the position based on the value in Variable 90
YV91 ; Moves Y axis to the position based on the value in Variable 91
DO2=1 ; turns on output #2
DELAY=500 ; wait 500mS
DO2=0 ; turns off output #2
ENDSUB
PRG 1 ; Starting point for Program 1
WHILE 1=1 ; Continuous looping
IF DI2=1 ; If digital input 2 is triggered
ABORTX ; stop X axis
ABORTY ; stop Y axis
SR0=0 ; stop running Program 0
JOYNOX=1900;neg signal limit for X joystick in mV
JOYNOY=1900;neg signal limit for Y joystick in mV
JOYPOX=3130;pos signal limit for X joystick in mV
JOYPOY=3130;pos signal limit for Y joystick in mV
JOYHSX=2000;sets joystick speed for X axis(pps)
JOYHSY=2000;sets joystick speed for Y axis(pps)
JOYDELX=100;max speed change in pulses/sec
JOYDELY=100;max speed change in pulses/sec
JOYENA=3 ;enables joystick on XY axes
LTX=1 ; X axis position capture on,waiting for input trigger
LTY=1 ; Y axis position capture on,waiting for input trigger
ELSE ; If digital input 2 is not triggered
LTX=0 ; turns off X axis position capture
LTY=0 ; turns off Y axis position capture
SR0=1 ; start running Program 0
ENDIF; end of IF statements
ENDWHILE; loop back up to the WHILE statement
END; end of program
We now have two independent programs running simultaneously. Program 1 sets up the joystick if input 2 is triggered and then enables position capturing of either the step or encoder position. After moving the X and Y axes via the joystick, the operator could trigger the corresponding inputs, and capture position. The encoder or step position is retrieved via commands: LT(AXIS)P for step position or LT(AXIS)E for the encoder feedback.
As has been demonstrated, IntelLiDrives “SmartMotor” programming tools and language make it easy to accomplish both simple and fairly complex tasks.
Comment
Rating Bad Good