我的项目的任务是通过语音操作fanuc机器人...问题出现在我在机器人控制器上的karel中的第二个代码中...首先,在机器人通过tcp / ip以整数形式获取命令之后,它以某种方式将它存储在一个缓冲区中,所以下次我开始编程它从上一个会话运行命令而不用担心......这可能非常危险......所以我发现在karel程序BYTES_AHEAD并尝试清除端口,但它赢了' t work.Next问题是在条件循环...我试图运行多个命令,只要服务器连接循环REPEAT ... UNTIL ..但这也不会工作。请我帮忙..不知道下一步做什么...先谢谢大家!这是我在卡雷尔的代码...
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
答案 0 :(得分:1)
我使用此例程来初始化缓冲区:
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
答案 1 :(得分:0)
您发布的代码难以阅读(缺少缩进),有些看起来 奇数(例如,接近结尾:if(vox_str ='130'),然后是endif
所以......这是一个更通用的回复。
尝试添加代码以在开始时初始化变量并查看是否存在问题 消失。如果是这样,那意味着代码中有一些路径 没有设置其中一个或多个。
i:= 0; n:= 0; vox_str:=''; stat:= 0; n_bytes:= 0; entry:= 0; prog_index:= 0;