I have written a few programs that contain routines. How do I call a specific one from a program?
For now, I have moved each routine into a separate program to access them.
Is there a better way?
I have written a few programs that contain routines. How do I call a specific one from a program?
For now, I have moved each routine into a separate program to access them.
Is there a better way?
I meant on the teach pendant. I have a PROGRAM A in Karel. On the pendant when I do a CALL function, I see only Program A, not its subroutines.
There is no support for this. Not even in Karel itself (see the documentation for CALL_PROG: "cannot be used to run internal or external routines").
Technically this would be possible (as the binaries should provide all the information needed), but Fanuc hasn't made anything available that can do this.
Perhaps you could use TP arguments and use a string argument to implement some kind of jump table in your main program.
...or you could use separate Karel program, that would be called by the TP-program only to execute a routine of another Karel program, using the code provided by inusO (just 1 line of code).
Yes, good suggestion. I missed that in inusO answer.
Depending on how many routines you want to call from TP this could lead to many, many tiny programs though.
Would be nice if CALL_PROG supported this, or Fanuc introduced a calling convention between Karel and TP. That way we could call Karel routines from TP directly.
Hi, this has been working for me.
I created a MAIN.TP.
1.CALL SAFEHOME <---------We created a "safehome" macro. Inside there are "home position" and outputs to PLC.
2.LABEL[1]
3.CALL SAFEHOME <--------------Before running the routine we call safehome, just want to be safe, probably don't need it.
4.IF DO[102]=OFF JMP_LABEL[2] <----------Go to label 2 if signal 102 is off. (Yours might be different) 102 is a signal to PLC. (Push button)
5.IF DO[102]=ON CALL SIDE_A <----------If signal 102 is ON then call "Side A". Inside the "Side A" we call side A program.
6.WAIT DI[104]= OFF <------- Our PLC tells the robot to execute. we want to be sure the Di104 is Off. (Our robot sometime won't turn it off)
7.LABEL[2]
8.IF DO[103]=OFF JMP_LABEL[3] <----------Go to label 3 if signal 103 is off. (Yours might be different) 103 is a signal to PLC.
9.IF DO[103]=ON CALL SIDE_B <----------If signal 103 is ON then call "Side B". Inside the "Side B" we call side B program.
10.WAIT DI[105]=OFF <---------- we want to be sure the Di105 is Off.
11.LABEL[3]
12.[R1]=[R1]+1 <---------- Torch cleaner count
13.IF [R1]<5 JMP LBL[99] <--------If register 1 is less then 5 jump to label 99
14.WAIT 1 SECOND
15.IF [R1]=5 DI[104] AND DI[105]OFF <--------If register 1 reach 5 and 104 and 105 is OFF
16.CALL REAMER <----------Call the torch cleaning program. (Macro)
17.[R1]=0 <---------- Reset torch cleaner count
18.LBL[99]
19.JMP_LABEL[1]
END