Fanuc Karel(基于 Pascal)需要帮助

发布于 2024-10-16 03:06:44 字数 2838 浏览 1 评论 0原文

我的项目的任务是通过语音操纵 fanuc 机器人...问题出在机器人控制器上的 karel 中的第二个代码中...首先,在机器人通过 tcp/ip 以整数形式获取命令后,它以某种方式存储它在缓冲区中,所以下次我启动程序时,它会运行上次会话中的命令而不会磨损..这可能非常危险...所以我在卡雷尔程序 BYTES_AHEAD 中找到并尝试清除端口,但它不起作用。下一个问题是条件循环...我尝试运行多个命令,只要有循环的服务器连接重复...直到..但这也不起作用。请我需要帮助..不要知道下一步做什么...提前谢谢大家!这是我在卡雷尔的代码...

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜深人未静 2024-10-23 03:06:44

我使用这个例程来初始化缓冲区:

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

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
爱*していゐ 2024-10-23 03:06:44

您发布的代码很难阅读(缺乏缩进),有些看起来
奇数(例如,接近结尾: if (vox_str = '130') then endif

所以...这是一个更通用的回复。

尝试添加代码以在开始时初始化变量,看看问题是否存在
消失。如果是这样,则意味着代码中存在某种路径
没有设置其中一个或多个。

我:= 0;
n:= 0;
vox_str := '';
统计:= 0;
n_字节:= 0;
输入:= 0;
编程索引:= 0;

您可能还想阅读http://www.allegro.com/papers/htpp.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文