Greetings Forum. There are bits and pieces of information on the forum and I can't quite connect where my problem is.
I am trying to program 4 PTP movements using the 4 status buttons on a KRC4 controller.
I have the following .src file which runs fine as a module.
QuoteDisplay More; Created by Titch Taylor 15 Apr 2024
; Run as .src file from TP
; Basic Code compliment Panic Mode
$FLAG[15] = FALSE
$FLAG[16] = FALSE
$FLAG[17] = FALSE
$FLAG[18] = FALSE
LOOP
;FOLD +> Status Key detection
; check if status key is pressed
$FLAG[11] = is_key_pressed(14)
$FLAG[12] = is_key_pressed(15)
$FLAG[13] = is_key_pressed(16)
$FLAG[14] = is_key_pressed(17)
; detect rising edge of the button press
; by comparing current and previously saved state
$FLAG[1] = $FLAG[11] AND NOT $FLAG[15]
$FLAG[2] = $FLAG[12] AND NOT $FLAG[16]
$FLAG[3] = $FLAG[13] AND NOT $FLAG[17]
$FLAG[4] = $FLAG[14] AND NOT $FLAG[18]
; save current state of the button to check toggle
$FLAG[15] = $FLAG[11]
$FLAG[16] = $FLAG[12]
$FLAG[17] = $FLAG[13]
$FLAG[18] = $FLAG[14]
;ENDFOLD
; allow status keys to control some outputs
; but only if in T1 and drives are enables
;FOLD +> Status Key control
;IF $T1 AND $PERI_RDY AND $USER_SAF AND NOT $PRO_ACT THEN
IF $MODE_OP == #T1 THEN
; for momentary state change (toggle) use flags 1..4
IF $FLAG[1] THEN
;Pointloader and System track Home
;IF $PERI_RDY AND NOT $PRO_ACT
IF $PERI_RDY THEN
PDAT_ACT=PFast
FDAT_ACT=FTravel
BAS(#PTP_PARAMS,100)
PTP xHome
ENDIF
ENDIF
IF $FLAG[2] THEN
;P1
IF $PERI_RDY THEN
PDAT_ACT=PFast
FDAT_ACT=FTravel
BAS(#PTP_PARAMS,100)
PTP XHome1
ENDIF
ENDIF
IF $FLAG[3] THEN
;P2
IF $PERI_RDY THEN
PDAT_ACT=PFast
FDAT_ACT=FTravel
BAS(#PTP_PARAMS,100)
PTP XHome2
ENDIF
ENDIF
IF $FLAG[4] THEN
;P1
IF $PERI_RDY THEN
PDAT_ACT=PFast
FDAT_ACT=FTravel
BAS(#PTP_PARAMS,100)
PTP XHome3
ENDIF
ENDIF
;for continuous outputs use flags 11..14
; Put operations here
ENDIF
;ENDFOLD
ENDLOOP
END
I then modify it to run using the sub interpreter using the code below and get all sorts of errors - I have commented out the BAS instructions for obvious reasons.
The error when running the sub interpret is two fold.
I get a message waiting for non LoadFirstArray - which won't go away and then 'invalid command'
QuoteDisplay More; Created by Titch Taylor 15 Apr 2024
; Called from sub interpreter
; Basic Code compliment Panic Mode
;FOLD +> Status Key detection
; check if status key is pressed
$FLAG[11] = is_key_pressed(14)
$FLAG[12] = is_key_pressed(15)
$FLAG[13] = is_key_pressed(16)
$FLAG[14] = is_key_pressed(17)
; detect rising edge of the button press
; by comparing current and previously saved state
$FLAG[1] = $FLAG[11] AND NOT $FLAG[15]
$FLAG[2] = $FLAG[12] AND NOT $FLAG[16]
$FLAG[3] = $FLAG[13] AND NOT $FLAG[17]
$FLAG[4] = $FLAG[14] AND NOT $FLAG[18]
; save current state of the button to check toggle
$FLAG[15] = $FLAG[11]
$FLAG[16] = $FLAG[12]
$FLAG[17] = $FLAG[13]
$FLAG[18] = $FLAG[14]
;ENDFOLD
; allow status keys to control some outputs
; but only if in T1 and drives are enables
;FOLD +> Status Key control
;IF $T1 AND $PERI_RDY AND $USER_SAF AND NOT $PRO_ACT THEN
IF $MODE_OP == #T1 THEN
; for momentary state change (toggle) use flags 1..4
IF $FLAG[1] THEN
;Pointloader and System track Home
;IF $PERI_RDY AND NOT $PRO_ACT
IF $PERI_RDY THEN
PDAT_ACT=PMed
FDAT_ACT=FTravel
;BAS(#PTP_PARAMS,100)
PTP xHome
ENDIF
ENDIF
IF $FLAG[2] THEN
;P1
IF $PERI_RDY THEN
PDAT_ACT=PMed
FDAT_ACT=FTravel
;BAS(#PTP_PARAMS,100)
PTP XHome1
ENDIF
ENDIF
IF $FLAG[3] THEN
;P2
IF $PERI_RDY THEN
PDAT_ACT=PMed
FDAT_ACT=FTravel
;BAS(#PTP_PARAMS,100)
PTP XHome2
ENDIF
ENDIF
IF $FLAG[4] THEN
;P1
IF $PERI_RDY THEN
PDAT_ACT=PMed
FDAT_ACT=FTravel
;BAS(#PTP_PARAMS,100)
PTP XHome3
ENDIF
ENDIF
;for continuous outputs use flags 11..14
; Put operations here
ENDIF
;ENDFOLD
END
Please can someone guide me on what needs to be done?