245
Appendix C
Programming Examples
Master Shell Program
Good programming practice requires to have a master shell program. A master shell program can be used for
most applications and will perform the following tasks:
• Set-up the MC Unit and the Servo Driver
• Control the application program tasks
• Continuously monitoring the status of the system.
Please find below an example of such a master shell program. Be sure to modify it to the specific application
and to check proper operation for all possible conditions before relying on its safety operation. This program
should be set to run at power-up at low priority (task 1).
'####################################################################
' Master shell program
' Tasks: 1. Set-up MC Unit and Servo Driver
' 2. Control application program tasks
' 3. Continuous error checking
' Inputs: IN(6) start_machine (active high)
' Start application
' IN(7) e_stop (active low)
' Emergency stop
' (IN(5)) resetting (active high)
' Reset motion error
' Main variables used:
' Program status VR(111)
' 0 Initialising system
' 1 Motion & programs stopped
' 2 Normal running
' 3 Error or emergency stop
' Execution: Run program on priority 1 (lowest priority)
'####################################################################
' Initialisation of variables
'-----------------------------------------------
GOSUB init_vars
' Initialisation of serial ports
'-----------------------------------------------
GOSUB init_serial
' Initialisation axis parameters
'-----------------------------------------------
RUN "STARTUP",3
WA(5)
' Wait until process is stopped
WAIT UNTIL PROC_STATUS PROC(3) = 0
' Set ERRORMASK parameter
'-----------------------------------------------
' Following statuses will result in Motion Error:
' (bit 2) Servo Driver Communication Error
' (bit 3) Servo Driver Alarm
' (bit 8) Following Error Limit
BASE(0)
ERRORMASK = 268
' Initialisation Servo Driver
'-----------------------------------------------
' If no communication error
IF (AXISSTATUS AND 4) = 0 THEN
' Set Servo Driver parameters
RUN "INIT_DRIVER",3
WA(5)