Good evening.
Trying to use serial communication between my laptop and the krc1, to control my robot.
Firstly I tested communication with hyperterminal, this is as I understand on the windows enviroment which I chose by editing the HW_F.INI file setting COM2 to enable. This worked well after some trial and error(realised I needed to force cold startup in order to let changes in .INI file take effect). Sending and receiving worked, I used a terminal on ubuntu laptop, configured the terminal with stty to work with serial com via commandline. cat /dev/ttyUSB0 for reading, this worked.
After this I wanted to control the robot, so I changed the HW_F.INI again for the COM to be visable to VxWorks OS. It worked in that I can receive data with CREAD on the KRC1 pc and move the robot with this data. Writing with CWRITE didn't result in seeing the text on my laptop however.
By using my telnet(firstly setting TESTPRINT=1 in Serial.INI) to see the traffic on the RX and TX pins I could see the correct data on both pins.
Also I dont know if the Xon/Xoff settings matter in SERIAL.INI, is default ok?
Below are the files and results I described.
If anyone has any suggestions on what to try next that would be very helpful
Thanks in advance
Kind regards,
Rik
Serial.INI:
telnet on krc1:
This is the stty setting i used in the terminal;
Sending msg manually and reading(robot reveives msg but no returning msg on laptop)
rik@rik-N56VM:~/Documents/custom_scripts$ echo 1100 -20 1500 180 9 -175 2 10 2922 > /dev/ttyUSB0
Also I tested a python script for controlling it, same result; sending worked, receiving from krc1 not.;
import serial
import time
import sys
from enum import Enum
def calculate_checksum(values):
return sum(values)
def open_serial_port():
ser = serial.Serial(
port,
baudrate,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
xonxoff=True,
timeout=0.5
)
return ser
def send_position_data(port, baudrate, positions):
ser = open_serial_port()
for position in positions:
read_str = ser.read(30)
print(f"read: {read_str.strip()}\n")
x, y, z, a, b, c, s, t, delay = position
checksum = calculate_checksum([x, y, z, a, b, c, s, t])
data_str = f"{x} {y} {z} {a} {b} {c} {s} {t} {checksum}\n"
input("Press Enter to send the next position...")
ser.write(data_str.encode('utf-8'))
print(f"Sent: {data_str.strip()}", file=sys.stdout)
read_str = ser.read(30)
print(f"read: {read_str.strip()}\n")
# time.sleep(delay)
ser.close()
if __name__ == "__main__":
port = '/dev/ttyUSB0' # Serial port to send data
baudrate = 9600 # Baud rate
delay = 2 # Time delay in seconds between sending data points
# Example positions (x, y, z, a, b, c)
positions = [
(721, -216, 1413, 180, 9, -176, 2, 10, 5),
(805, -216, 1326, 180, 9, -176, 2, 10, 5),
(805, 79, 1335, 180, 9, -176, 2, 35, 5),
(805, 79, 1413, 180, 9, -176, 2, 35, 5),
# Add more positions as needed
]
# "error msg from kuka received\n")
send_position_data(port, baudrate, positions)
Display More
output from script;
don't understand why received string is : b' '
rik@rik-N56VM:~/Documents/KukaRobot$ python3 control_robot.py
read: b''
Press Enter to send the next position...^[[A
Sent: 721 -216 1413 180 9 -176 2 10 1943
read: b''
read: b''
Press Enter to send the next position...
Sent: 805 -216 1326 180 9 -176 2 10 1940
read: b''
read: b''
Display More
program on the KRC1:
;This program waits for a valid position being received at the COM2 interface and then moves the robot to that position.
;--------- Declaration ---------
DECL INT HANDLE, I, J, CREAD_OFFSET, NUMBER
DECL CHAR NOTIFY_TEXT[5], READ_STRING[20]
DECL REAL TIMEOUT, CHECKSUM, SUMCOORD
DECL STATE_T CWRITE_STATE, CREAD_STATE
DECL MODUS_T MODUS
DECL POS PositionRobot
;---------- Initialization ---------
CHECKSUM=0
SUMCOORD=0
I=1
FOR J = 1 to 6
$VEL_AXIS[J]=15 ;x% max. speed
$ACC_AXIS[J]=40 ;x% max. acceleration
ENDFOR
;---------------------------------------
; Main program
;---------------------------------------
;------------- Open channel to COM2 -----------
COPEN(:SER_2,HANDLE) ;Open a channel to COM2 according to config in serial.ini. If XON/XOFF is used, then a XON symbol is sent by COPEN.
IF HANDLE==0 THEN ;If an error occured during opening the channel, then stop the program.
HALT
ENDIF
MODUS=#SYNC
LOOP ;endless loop
;------------- Write to COM2 -----------
CWRITE(HANDLE,CWRITE_STATE,MODUS,"hi")
CWRITE(HANDLE,CWRITE_STATE,MODUS,"start of loop %d",I) ;Send counter value to track the loop.
;------------ Read from COM2 -----------
TIMEOUT=15.0
CREAD_OFFSET=0
MODUS=#ABS
CREAD(HANDLE,CREAD_STATE,MODUS,TIMEOUT,CREAD_OFFSET,"%f %f %f %f %f %f %d %d %f",PositionRobot.X,PositionRobot.Y,PositionRobot.Z,PositionRobot.A,PositionRobot.B,PositionRobot.C,PositionRobot.S,PositionRobot.T,CHECKSUM)
;Send for example the string "2000 -800 1800 -90 90 -90 2 10 2922" to COM2. THe last value is the sum of all previous values.
IF CREAD_STATE.RET1==#CMD_TIMEOUT THEN ;If the timeout time has been exceeded, then exit the loop.
EXIT
ENDIF
PTP PositionRobot
CWRITE(HANDLE,CWRITE_STATE,MODUS,"%d", CHECKSUM)
I=I+1
CWRITE(HANDLE,CWRITE_STATE,MODUS,"end of loop") ;mark the end of the loop.
ENDLOOP
CCLOSE(HANDLE,CWRITE_STATE) ;info: a XOFF is sent after closing
END
Display More