Blog: Programming IntelLigent Actuators (part2)
Our next task will be to show how variables can be used in place of “hard coded” values to facilitate external parameter change. Then conditional branching will be used to call subroutines via a variable change or I/O.
First variables need to to be assigned. There are two types within the “SmartMotor” control scheme: Volatile (addresses 049) which are not retained in memory and Non-Volatile (5099) which are retained after powering down a controller. They can be used to hold and change data for parameters such as position, speed, counters, timers, etc.
; MAIN APPLICATION SECTION
ABS;Sets absolute mode
X2000 ; Moves X axis 2000 steps
WAITX ; wait for move complete
Y2000; Moves Y axis 2000 steps
WAITY ; wait for move complete
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
END; end of program
Now the code adds a second XY move in which the move data is stored in a nonvolatile variable for each axis and the speed of the X axis move is based upon another nonvolatile variable. If we look at the code above, the 2000 step move is essentially an offset from the original Homing routine, while the second XY move is only defined by the value of the variables.
Sometimes in an application it becomes important to decide when and if either of these moves gets executed. We will next show how this can be accomplished with conditional branching and subroutines. We are going to put each XY move (the hard coded, offset move and the variable based move) into its own subroutine. Determining when the subroutines are “called” will be based on an “IF-THEN-ELSE” statement.
; MAIN APPLICATION SECTION ABS ;Sets absolute mode
IF DI1=1 ; looks at status of input 1
GOSUB 1 ; calls subroutine 1 ELSE
GOSUB 2 ; calls subroutine 2 ENDIF ; ends conditional branching/jumping
END : end of program
SUB 1 ; defines the subroutine
X2000 ; Moves X axis 2000 steps
WAITX ; wait for move complete
Y2000 ; Moves Y axis 2000 steps
WAITY ; wait for move complete
ENDSUB ; signals the end of the subroutines
SUB 2 ; defines the subroutine
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 ; signals the end of the subroutines
As can be seen, the program code is now divided into two separate pieces. Their execution is determined by the value of digital input 1.
Comment
Rating Bad Good