%%%
  VERSION: 1
  LANGUAGE: ENGLISH
%%%
MODULE XX_BASE (SYSMODULE, NOSTEPIN)
 
 !*******************************************************************
 ! 
 ! Frame module for the Discrete Application
 !
 ! ----------------
 ! $Revision: 1.1 $ 
 ! ----------------
 ! Copyright (c) ABB Robotics Products AB 1996.  All rights reserved
 !
 ! Module name ..........: XX_BASE - Application base definitions
 !
 ! Application name .....: XX
 ! Application number ...: 1
 !
 ! Number of processes ..: 2
 ! Name of process 1 ....: XX_PROCESS1
 ! Name of process 2 ....: XX_PROCESS2
 !
 ! Name of shell routine : XXML 
 !
 
 !*******************************************************************
 !
 ! XXML - Application shell routine
 !
 ! DESCRIPTION:
 !   Moves the manipulator to a discrete target position and executes
 !   the two initiated processes at the same time.
 !
 PROC XXML(robtarget ToPoint,
 	    speeddata Speed
	    \switch P1
	    \switch P2
	    \switch P3
	    \switch P4,
	    PERS tooldata Tool
	    \PERS wobjdata WObj
	    \switch InPos)
   
   ! Activate the application
   DaActApp XX_app_desc;
   
   ! Check the current running processes, if any kill them
   IF (DaNofActProc() > 0) THEN
     ! Deactivate all current running processes
     DaDeactAllProc;
   ENDIF

   ! Activate the requested process/processes
   IF Present (P1) THEN
     ! Activate the requested process
     DaActProc XX_prc_desc{1};
   ENDIF
   IF Present (P2) THEN
     ! Activate the requested process
     DaActProc XX_prc_desc{2};
   ENDIF
   IF Present (P3) THEN
     ! Activate the requested process
     !DaActProc XX_prc_desc{3};
   ENDIF
   IF Present (P4) THEN
     ! Activate the requested process
     !DaActProc XX_prc_desc{4};
   ENDIF
   
   IF NOT((Present (P1)) OR (Present (P2)) OR (Present (P3)) OR (Present (P4))) THEN
     TPWrite "Error: You must activate a process!";
     Stop;
   ENDIF
     
   ! Move to the work position and start the processes
     DaProcML ToPoint, Speed, Tool \WObj?WObj \InPos?InPos;

  BACKWARD
   ! Perform backward actions
    MoveL ToPoint, Speed, FINE, Tool \WObj?WObj;
  
 ENDPROC
 
 
 !*******************************************************************
 !
 ! DaCalcEvtXX - Discrete application calculate events for the 
 !		 application XX.
 !
 ! DESCRIPTION:
 !   RAPID user hook, calculates the event times of the process(es).
 !   This routine will be called from the DaProcML instruction to setup
 !   the process dependend trigg actions with the times defined in
 !   tool data.
 !
 PROC DaCalcEvtXX(VAR dadescprc ProcDesc,
                   num ProcNo,
		   VAR num EventTimes{*})
		   
   FOR i FROM 1 TO XX_NO_OF_PROC DO
     IF (ProcNo = XX_prc_no{i}) THEN
       EventTimes{1} := XX_tool_data{i}.time_event1;
       EventTimes{2} := XX_tool_data{i}.time_event2;
       EventTimes{3} := XX_tool_data{i}.time_event3;
     ENDIF
   ENDFOR
  
ENDPROC
 
 
 !*******************************************************************
 !
 ! XXShPowerOn - Application XX power on shelf routine
 !
 ! DESCRIPTION:
 !   Execute the application specific power on actions.
 !   Here You initialize the application and processes.
 !    
 !
 PROC XXShPowerOn()

   !Install the application XX
   DaNewApp XX_app_desc, XX_app_name;
   
   ! Install all processes within the application XX
   FOR i FROM 1 TO XX_NO_OF_PROC DO
     DaNewProc XX_prc_desc{i}, XX_app_desc, XX_prc_name{i}, XX_prc_no{i};
   ENDFOR
   
   ! Define the process data
   FOR j FROM 1 TO XX_NO_OF_PROC DO
     DaDefProcData XX_prc_desc{j}, XX_prc_data{j}, XX_tool_data{j}, XX_int_data{j};
   ENDFOR

   ! Define the user data
   !FOR k FROM 1 TO XX_NO_OF_PROC DO
   
   !ENDFOR
   
   ! Define the external signals for 
   DaDefExtSig XX_prc_desc{1}, doStart1, diReady1, goProgNo1;
   DaDefExtSig XX_prc_desc{2}, doStart2, diReady2, goProgNo2;
      
   ! Define the process signals
   DaDefProcSig XX_prc_desc{1}, doInProgress1, doProcFault1, doExtFault1;
   DaDefProcSig XX_prc_desc{2}, doInProgress2, doProcFault2, doExtFault2;
    
 ENDPROC
 
 
 !*******************************************************************
 !
 ! XXShStart - Application XX start shelf routine
 !
 ! DESCRIPTION:
 !   Execute the application specific start actions. 
 !    
 !
 PROC XXShStart()
    
 ENDPROC
 
 
 !*******************************************************************
 !
 ! XXShReStart - Application XX restart shelf routine
 !
 ! DESCRIPTION:
 !   Execute the application specific restart actions. 
 !    
 !
 PROC XXShReStart()
    
 ENDPROC
 
 
 !*******************************************************************
 !
 ! XXShStop - Application XX stop shelf routine
 !
 ! DESCRIPTION:
 !   Execute the application specific stop actions. 
 !    
 !
 PROC XXShStop()

 ENDPROC
 
 
 !*******************************************************************
 !
 ! XXShQStop - Application XX quick stop shelf routine
 !
 ! DESCRIPTION:
 !   Execute the application specific quick stop actions. 
 !    
 !
 PROC XXShQStop()

 ENDPROC
 
ENDMODULE
