nikola
nikola

Reputation: 1

Fanuc Karel(based on Pascal) help needed

The task of my project is manipulation of fanuc robot by voice...the problem is in my second code in karel on robot controller...first,after robot gets his command in the form of integer over tcp/ip,somehow it store it in a buffer,so next time i start program it run command from last session without worning..and that can be very dangerous...so i found in karel procedure BYTES_AHEAD and try to purge port,but it won't work.Next problem is in condition loop...i have tried to run more than one command as long there is server connection with loop REPEAT...UNTIL..but that won't work too.Please I need help..don't know what do next...thank you all in advance!Here is my code in karel...

PROGRAM nikola
%NOLOCKGROUP
%NOPAUSE = ERROR + COMMAND + TPENABLE



VAR
  i,n,tmp_int,STATUS:INTEGER
  file_var:FILE
  vox_str:STRING[128]
  stat,n_bytes,entry,prog_index:INTEGER
  FINISHED:BOOLEAN
  ----------------------VANJSKE RUTINE-------------------------
  ROUTINE OPEN_FILE_(FILE_ : FILE; TAG_ : STRING) FROM LIB_FILE
  ROUTINE CLOSE_FILE_(FILE_ : FILE; TAG_ : STRING) FROM LIB_FILE
  ROUTINE WRITE_(STRING_ : STRING) FROM LIB_FILE
  ROUTINE HANDSHAKING_(ID_ : STRING; TIP_: STRING) FROM LIB_FILE
  --------------------------------------------------------------

  BEGIN
  SET_FILE_ATR(file_var, ATR_IA)
  --set the server port BEFORE doing a CONNECT
  SET_VAR(entry, '*SYSTEM*','$HOSTS_CFG[5].$SERVER_PORT',12350,STATUS)
  stat=SET_PORT_ATR (PORT_1, ATR_READAHD,1)

  --Spajanje tag-a
  WRITE TPDISPLAY('Uspostava veze sa R2...',CR)
  CLOSE_FILE_(file_var,'S5:')
  OPEN_FILE_(file_var,'S5:')

  IF IO_STATUS(file_var)<>0--inpput,output,value have to be 0 if there is connection established
  THEN FINISHED=TRUE
  ENDIF

  REPEAT
   BYTES_AHEAD (file_var, n_bytes, STAT)--catching number of bytes ready to be read
   IF (n_bytes >= 1) THEN --if there is byres to be read
   READ file_var(vox_str::1) --read byte by byte
   stat=IO_STATUS (file_var) --status of operation
   ENDIF
   UNTIL stat <> 0 --continue until there is no bytes



 REPEAT
   FINISHED=FALSE
  --Reading Command "Robovox go up" 
   REPEAT
   BYTES_AHEAD (file_var, n_bytes, STAT)--catching number of bytes ready to be read
   IF (n_bytes >= 1) THEN --if there is byres to be read
   READ file_var(vox_str::1) --read byte by byte
   stat=IO_STATUS (file_var) --status of operation
   ENDIF
   UNTIL stat <> 0 --continue until there is no bytes
   --
   IF (n_bytes = 0) THEN --is there is no bytes
   READ file_var(vox_str::3)
    ENDIF
   IF UNINIT(vox_str) THEN
    vox_str=''
   ENDIF
   IF (vox_str='120') THEN
   CALL_PROG('NIK_UP',prog_index) 
   ENDIF

--Reading command "Robovox go down"
   REPEAT
   BYTES_AHEAD (file_var, n_bytes, STAT)--catching number of bytes ready to be read
   IF (n_bytes >= 1) THEN --if there is byres to be read
   READ file_var(vox_str::1) --read byte by byte
   stat=IO_STATUS (file_var) --status of operation
   ENDIF
   UNTIL stat <> 0 --continue until there is ni bytes
   --
   IF (n_bytes = 0) THEN --if there is no bytes
   READ file_var(vox_str::3)
   ENDIF
   IF (vox_str='130') THEN
    ENDIF
   CALL_PROG('NIK_DOWN',prog_index)
   ENDIF

 UNTIL (FINISHED=TRUE)


END nikola

Upvotes: 0

Views: 5439

Answers (2)

Emanuele
Emanuele

Reputation: 29

I use this routine for init the buffer:

ROUTINE init_buffer
BEGIN
    WRITE('init buffer',CR)
    n_bytes=0
    REPEAT
        BYTES_AHEAD (file_var, n_bytes, STATUS) --Get number of bytes ready  to be read 
        WRITE('remaining byte:',n_bytes,' STATUS ',STATUS, CR)
        IF (n_bytes >= 1) THEN --there are bytes to be read 
            IF n_bytes>128 THEN
                READ file_var(init_bufs::128) 
                STATUS=IO_STATUS (rs232) --get the status of the read operation 
            else
                READ file_var(init_bufs::n_bytes) 
                STATUS=IO_STATUS (rs232) --get the status of the read operation 
            ENDIF
        ENDIF 
    UNTIL n_bytes = 0 --continue until no more bytes are left 
END init_buffer

Upvotes: 2

Stan Sieler
Stan Sieler

Reputation: 759

The code you posted is difficult to read (lack of indentation), and some looks odd (e.g., near the end: if (vox_str = '130') then endif

So...this is a more generic reply.

Try adding code to initialize your variables at the start and see if the problem disappears. If it does, that implies there's some path through the code that wasn't setting one or more of them.

i := 0; n := 0; vox_str := ''; stat := 0; n_bytes := 0; entry := 0; prog_index := 0;

You may also want to read http://www.allegro.com/papers/htpp.html

Upvotes: 0

Related Questions