Author Topic: Flag true when Main Program is selected  (Read 213 times)

0 Members and 1 Guest are viewing this topic.

Offline MrNico

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 27
Flag true when Main Program is selected
« on: February 13, 2018, 05:59:35 PM »
Hello everyone,
I have a problem on a cell that I am starting, I manage the KUKA krc2 as a slave from a PLC, I should send a bit when a specific program is selected.
I think I should enter this function in the SPS, but I do not know which variable I have to use.
Do you have any ideas?
I have already tried $PRO_NAME1[], but I don't understand how I can use it.
Thanks in advance.
« Last Edit: February 13, 2018, 06:07:08 PM by MrNico »

Offline SkyeFire

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 27
  • -Receive: 778
  • Posts: 5776
Re: Flag true when Main Program is selected
« Reply #1 on: February 13, 2018, 06:21:45 PM »
$PRO_NAME1[] is a string variable that shows the name of the currently selected program in the robot interpreter.  You can simply do a string comparison on it, although you may need to use VARSTATE or STRLEN to protect against conditions where the variable is empty (when a program has been cancelled, for example).

I don't believe $PRO_NAME1[] changes as the program pointer dives into subroutines, but I could be recalling incorrectly.

Offline davidina

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 6
  • Posts: 16
Re: Flag true when Main Program is selected
« Reply #2 on: February 13, 2018, 06:43:38 PM »
If I get you right, I would suggest that you create a variable inside each subprogram, set it as soon as the program is called and reset when exiting. Since PLC is the master, you can send this specific variable status to PLC in a similar way you make handshake signals between Robot-PLC .

Offline MrNico

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 27
Re: Flag true when Main Program is selected
« Reply #3 on: February 13, 2018, 06:55:03 PM »
I tried to make a comparison with strcomp, but it does not work.
Have you ever used strcomp?
If I try to read the variable $PRO_NAME1 [] I have this result "/R1/Lavorazioni.scr"
StrComp($PRO_NAME1[], “/R1/Lavorazioni.scr”, #NOT_CASE_SENS) but strcomp is always FALSE.
Have you an idea where I'm wrong?

Offline MrNico

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 27
Re: Flag true when Main Program is selected
« Reply #4 on: February 13, 2018, 06:57:35 PM »
If I get you right, I would suggest that you create a variable inside each subprogram, set it as soon as the program is called and reset when exiting. Since PLC is the master, you can send this specific variable status to PLC in a similar way you make handshake signals between Robot-PLC .

How can I reset the variable when the program is deselected?

Offline spiral

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 6
  • Posts: 37
Re: Flag true when Main Program is selected
« Reply #5 on: February 14, 2018, 12:19:17 AM »
Just set a Flag in each programm. Then link the Flag to Output in sps.sub to PLC.

Offline panic mode

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 53
  • -Receive: 624
  • Posts: 3983
Re: Flag true when Main Program is selected
« Reply #6 on: February 14, 2018, 02:32:26 AM »
program selected and program running are two different things.
is supposed to be part of interlock for robot start?

if you need to know program running, then something like this may do:

in $CONFIG.DAT
Code: [Select]
SIGNAL PROGRAM_RUNS $OUT[1] TO $OUT[32]

in SPS.SUB loop add something like
Code: [Select]
IF $PRO_STATE1==#P_FREE THEN
  PROGRAM_RUNS=0
ENDIF



And then at the begin of each program add line such as


Code: [Select]
PROGRAM_RUNS=1 ; use different value in each program
; if you want individual bit to indicate running program, just make sure
;to only use values that are binary powers (1,2,4,8,16,32...)



1) http://www.robot-forum.com/robotforum/kuka-robot-forum/read-first/
2) if you want reply about robot, post it in forum
3) read 1 and 2

Offline MrNico

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 27
Re: Flag true when Main Program is selected
« Reply #7 on: February 14, 2018, 05:47:27 AM »
No, I need to know if a specified program is selected for give the Move Enable from plc only with this program.

Offline hermann

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 42
  • Posts: 212
Re: Flag true when Main Program is selected
« Reply #8 on: February 14, 2018, 07:34:07 AM »
In Your post You wrote ".scr" think it should be ".src", or there may be another typo.
Try to work with "StrFind" and only a part of the program name.

Offline SkyeFire

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 27
  • -Receive: 778
  • Posts: 5776
Re: Flag true when Main Program is selected
« Reply #9 on: February 14, 2018, 04:06:18 PM »
I tried to make a comparison with strcomp, but it does not work.
Have you ever used strcomp?
If I try to read the variable $PRO_NAME1 [] I have this result "/R1/Lavorazioni.scr"
StrComp($PRO_NAME1[], “/R1/Lavorazioni.scr”, #NOT_CASE_SENS) but strcomp is always FALSE.
Have you an idea where I'm wrong?

When I test $PROG_NAME1[], I do not get the "R1/" portion or the file extension, only the program name.
You could probably try using STRFIND in place of STRCOMP.

Offline MrNico

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 27
Re: Flag true when Main Program is selected
« Reply #10 on: February 14, 2018, 04:42:51 PM »
Yes, ok I solved my problem this is the results.

RicercaProgramma = StrFind(1,$PRO_NAME1[], "LAVORAZIONI", #NOT_CASE_SENS)
oProgLavorazione = RicercaProgramma == 1

where      oProgLavorazione  is my output for the PLC
               RicercaProgramma is an Integer declared in config.dat
               LAVORAZIONI is the Program to check

Obviously this is wrote in the SPS.
Thank you everyone and I hope this post can help somebody else.   :dance2:  :toothy9:
« Last Edit: February 14, 2018, 04:46:15 PM by MrNico »