.PROGRAM ceshi()
aaa = TRUE
DETACH ()
SELECT ROB = 1
ATTACH ()
SPEED 10 ALWAYS
WHILE aaa DO
SIGNAL 2017
EXECUTE 2 tcp_client()
DELAY 1
MOVE apos
BREAK
DELAY 2
MOVE dddd
BREAK
SIGNAL -2017
DELAY 1
EXECUTE 2 tcp_client()
END
SIGNAL 2017
EXECUTE 2 tcp_client()
; WHILE aaa DO
; IF SIG(1001) THEN
; MOVE xxpos
; BREAK
; ELSE
; MOVE yypos
; BREAK
; END
; MOVE ccpos
; BREAK
.END
、、、、、、、、、、、、、、、、
、、、、、、、、、、、、、、、、、
、、、、、、、、/、、、、、、、、
.PROGRAM main()
AUTO totalnum, numi, thick
;零件个数,零件总个数
;apos为拾取点,ahpos为拾取点上方,bpos为放置点,bhpos为放置点上方
totalnum = 12
numi = 0
thick = 5
WAIT.EVENT , 0.1
DETACH ()
SELECT ROB = 1
ATTACH ()
MOVE bhpos
BREAK
;上传的格式是,var0=
;var0=result,var1=x,var2=y,var3=alpha
WHILE numi < totalnum DO
EXECUTE 2 tcp_client()
;2018端口号传感器检测信号
IF SIG(1001) THEN
numi = numi+1
SIGNAL -2 ;传送带停止
WAIT.EVENT , 0.01
SIGNAL 2017 ;相机拍照使能打开
WAIT.EVENT , 0.01
EXECUTE 2 tcp_client() ;get the pos and result
WAIT.EVENT , 0.01
IF value[0] == 1 THEN ;如果结果是对的,那么移动到posA
WAIT.EVENT , 0.1
APPRO ahpos, 80
BREAK
MOVE apos
BREAK
SIGNAL 1 ;电磁铁打开
WAIT.EVENT , 0.5
WAIT.EVENT , 0.1
APPRO ahpos, 80
BREAK
WAIT.EVENT , 0.1
APPRO bhpos, 80
BREAK
bpos[2] = bpos[2]+numi*thick
WAIT.EVENT , 0.1
MOVE bpos
BREAK
SIGNAL -1 ;电磁铁松开
WAIT.EVENT , 0.5
WAIT.EVENT , 0.1
APPRO bhpos, 80
BREAK
SIGNAL 2 ;传送带启动
WAIT.EVENT , 0.5
END
END
END
.END
、、、、、、、/、
、
、、、、、、、、、、、/、、
.PROGRAM tcp_client()
;----------------------------------------------------------------------------
AUTO client_mode, lun, status, do_wait
AUTO $message, $echo, $read_str
; Initialize constants.
client_mode = 0
do_wait = 0
; Attach to the TCP device
ATTACH (lun, 4) “TCP”
TYPE "lun: ", lun
status = IOSTAT(lun) ;Check status of ATTACH
IF status < 0 THEN
TYPE "Error from ATTACH: ", $ERROR(status)
GOTO 100
END
FSET (lun) "/node 'cell2' /address 172 16 117 121"
; “cell2” is the name of the server connection as defined either in
; the default controller configuration or using a FSET instruction. A
; local port number is automatically establised, since the /LOCAL_PORT
; keyword is absent. The remote port number for the server must be
; known–1234 in this case. The buffer size is set to 1024 bytes.
FOPEN (lun, 0) “cell2 /REMOTE_PORT 9876 /BUFFER_SIZE 1024”
status = IOSTAT(lun) ;Check status of FOPEN
IF status < 0 THEN
TYPE "Error from FOPEN: ", $ERROR(status)
GOTO 100
END
; Loop until string is “quit”. Send the str and read the echo from the server.
repeat_loop = TRUE
WHILE repeat_loop DO
;2017信号是外部传感器的信号,接收到之后,signal -1这个口是传送带停止,
;然后后给相机M信号,相机拍照处理
WHILE SIG(2017) DO
SIGNAL -1
WAIT.EVENT 0.03
WRITE (lun) "m"
READ (lun, do_wait) $string_var
TYPE "Received string : ", $string_var
i = 0 ;Set array index
DO
$temp = $DECODE($string_var," ,",0) ;Pick off a number string
value[i] = VAL($temp) ;Convert to real value
$temp = $DECODE($string_var," ,",1) ;Discard spaces and commas
i = i+1 ;Advance the array index
UNTIL $string_var == "" ;Stop when input is empty
;传送带启动
SIGNAL -2017
WAIT.EVENT , 0.01
;机器人移动到posa位置
SET apos = TRANS(value[2],value[3],185.48,0,180,value[4])
WAIT.EVENT , 0.01
END
END
100 FCLOSE (lun)
DETACH (lun)
RETURN
.END