This is the program that I wrote for the movement of Fanuc robots by Karel program.
Firstly, the connection was examined without any movement of the robot (the “MOVE_G” program which is related to the teach pendant program at this step was blank, So I just wrote the position register without any movement ). The results were completely satisfactory: 7000 lines were sent and received in one minute.
For the second step, I wrote the "L @ PR [80] 250 mm/sec CNT 100" in the teach pendant inside 'MOVE_G' teach pendant program, in order to control the motion of the robot with respect to the PR [80] . The results were disappointing, and the number of lines sent and received was reduced from 7000 to less than 100 lines as soon as I wrote the above code. The test conditions were the same except that "L @ PR [80] 250 mm/sec CNT 100 " was added to the 'MOVE_G' teach pendant program. I do not know what is the reason for reducing the speed of the connection when I am activating the movement.
I wrote both Python and Karel code as below.
import socket
def client_program():
# Create a stream based socket(i.e, a TCP socket)
# operating on IPv4 addressing scheme
serverSocket = socket.socket();
# Bind and listen
serverSocket.bind(("192.168.2.5",8000));
serverSocket.listen(1);
(clientConnected, clientAddress) = serverSocket.accept();
coord_1=1040
coord_2 = -175
coord_3 = 505
coord_4 = -110
coord_5 = 49
coord_6 = -111
s = 0
counter=0
for i in range(10000):
while s < 10:
s += 1
coord_1 -= 1
coord_11=round(coord_1,2)
counter+=1
print(counter)
input_welding = f"{coord_11},{coord_2},{coord_3},{coord_4},{coord_5},{coord_6}"
print(input_welding)
clientConnected.sendall(((input_welding).encode())) # send message
data = clientConnected.recv(1024).decode() # receive response
#print(f"Received from server for coord_1={coord_1}: {data}") # show in terminal
s = 11
while s < 20:
s += 1
coord_1 += 1
coord_11=round(coord_1,2)
counter+=1
print(counter)
#input_welding =f"{coord_1}"
input_welding = f"{coord_11},{coord_2},{coord_3},{coord_4},{coord_5},{coord_6}"
print(input_welding)
clientConnected.sendall(((input_welding).encode())) # send message
data = clientConnected.recv(1024).decode() # receive response
#print(f"Received from server for coord_1={coord_1}: {data}") # show in terminal
s = 0
clientConnected.close() # close the connection
if __name__ == '__main__':
client_program()
Display More
PROGRAM kc900
%STACKSIZE = 4000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT kclop
%ENVIRONMENT REGOPE
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
VAR
--file group
file_var : FILE
--integer group
tmp_int : INTEGER
status : INTEGER
status_s : INTEGER
entry : INTEGER
int_val :INTEGER
int_regnum: REAL
int_pregnum: REAL
--sting group
tmp_str : STRING[128]
tmp_str1 : STRING[128]
x_t: STRING[20]
y_t: STRING[20]
z_t: STRING[20]
w_t: STRING[20]
p_t: STRING[20]
r_t: STRING[20]
v_s: STRING[20]
str_regnum: STRING[20]
str_pregnum: STRING[20]
--real group
rel_coord1: REAL
rel_coord2: REAL
rel_coord3: REAL
rel_coord4: REAL
rel_coord5: REAL
rel_coord6: REAL
v_r : REAL
xreal: REAL
yreal: REAL
zreal: REAL
wreal: REAL
preal: REAL
rreal : REAL
real_val : REAL
--bolean group
loop1 : BOOLEAN
real_flag : BOOLEAN
GATE : BOOLEAN
--xyz group
tmp_xyz :XYZWPR
xyz :XYZWPR
frame_value :XYZWPR
cur_pos : XYZWPR
--array group
num_find: INTEGER
num_parsed : INTEGER
chunked_str : STRING[9]
count_arr : INTEGER
append_arr : ARRAY[128] OF REAL
prog_index: INTEGER
flag_conn : BOOLEAN
tmp_str2 : STRING[128]
conf : CONFIG
BEGIN
WRITE TPERROR(CHR (128), CHR(137))
SET_FILE_ATR(file_var, ATR_READAHD)--++++++++++++++++++++++
--SET_FILE_ATR(file_var, ATR_IA)
SET_VAR(entry, '*SYSTEM*','$HOSTC_CFG[1].$SERVER_PORT',8000,status)
WRITE(' VAR status = ',status,CR)
WRITE TPERROR(CHR (128), CHR(137))
WRITE TPERROR(CHR (128), CHR(137))
loop1=TRUE
GATE= TRUE
status = 0
MSG_CONNECT('C1:',status)
IF status <> 0 THEN
MSG_DISCO('C1:',status)
MSG_CONNECT('C1:',status)
ENDIF
OPEN FILE file_var ('RW','C1:')
status_s = IO_STATUS(file_var)
IF status_s <> 0 THEN
WRITE TPERROR('ACHA BILMADIM',status,'---', CR)
--loop1=FALSE
ENDIF
WHILE loop1 = TRUE DO
tmp_str='Hi Server'
WRITE file_var(tmp_str)
status = IO_STATUS(file_var)
WRITE TPERROR(tmp_str,'---', CR)
WRITE TPERROR('written send',status,'---', CR)
WRITE TPERROR(CHR (128), CHR(137))
BYTES_AHEAD( file_var, entry,status)
IF ((UNINIT (entry)) AND (GATE)) THEN--Bytes ahead if
GATE=FALSE
MSG_DISCO('C1:',status)
WRITE TPERROR('Entry is Uninitialized', CR)
WRITE TPERROR(CHR (128), CHR(137))
ELSE
IF (NOT UNINIT (entry)) THEN--chenk intiiliaze if
IF (entry>=1) THEN --entry if
READ file_var (tmp_str1::entry)
--->>>>>>>>>>>>>>>>>>>>>>>>>>>>>
--This function bellow is for parsing with ','
count_arr=1
flag_conn=FALSE
REPEAT
num_find = INDEX(tmp_str1,',')
IF num_find <> 0 THEN
flag_conn=TRUE
num_parsed = num_find - 1
ELSE
num_parsed = STR_LEN(tmp_str1)
ENDIF
chunked_str = SUB_STR(tmp_str1,1,num_parsed)
CNV_STR_REAL(chunked_str,append_arr[count_arr])
count_arr = count_arr+ 1
tmp_str1 = SUB_STR(tmp_str1,num_find+1,STR_LEN(tmp_str1))
UNTIL num_find = 0
---------------<<<<<<<<<<<<<<<<<<<<<<<
IF flag_conn THEN --- if flag_conn
tmp_xyz.config_data.CFG_TURN_NO1 = 0
tmp_xyz.config_data.CFG_TURN_NO2 = 0
tmp_xyz.config_data.CFG_TURN_NO3 = 0
tmp_xyz.config_data.CFG_FLIP = TRUE
tmp_xyz.config_data.CFG_UP = TRUE
tmp_xyz.config_data.CFG_FRONT = TRUE
tmp_xyz.X=append_arr[1]
tmp_xyz.Y=append_arr[2]
tmp_xyz.Z=append_arr[3]
tmp_xyz.W=append_arr[4]
tmp_xyz.P=append_arr[5]
tmp_xyz.R=append_arr[6]
SET_POS_REG (80, tmp_xyz, status)
CALL_PROG('MOVE_G', prog_index)
ENDIF---flag_conn if
ENDIF --entry if
GATE=TRUE
ENDIF --check intiiliaze if
ENDIF--Bytes ahead if
ENDIF --Main if
DELAY 1
ENDWHILE
CLOSE FILE file_var
MSG_DISCO('C1:',status)
WRITE TPERROR('Error opening file',status,'---', CR)
END kc900
------------------------------------------------------------------------------------------
Display More