User Tools

Site Tools


rb5_advanced_programming

RB5 Advanced Programming

Author: <Baekseok Kim> Email: kimb52@unlv.nevada.edu
Date: Last modified on <01/20/23>
Keywords: RB5 manipulator, RB5 Programming, collaborative robot

External Script Control API

The cooperative robot RB series can be operated for various environments and purposes. It can be used in conjunction with multiple RB series or other systems. In conjunction with the vision system, movement coordinates can be changed in real time, or used as part of a user's existing system.

Users can control the robot with teaching pendant (tablet UI), but it provides a way to control the robot from any external controller for user’s convenience or operation.

The RB series receives script commands by default and executes those commands. The task of writing a motion using the teaching pendant (tablet UI) and executing the script of the file in order is a general operation method. The following method described in this document is an alternative method of receiving a command script from another external device to control a robot of the RB series.

The control syntax provided in the teaching pendant / tablet UI can be implemented by the user directly from the external control device, and the robot operation commands / IO control commands are sent according to the user’s use case.

The following document describes an example of driving a robot with the above concepts.

*API Commands

External Connection

In order to use external control, the external computer must be connected to the control box. The connection uses TCP / IP communication and the corresponding IP address can be set in the pendant. The result is displayed on the screen on control panel. Ports 5000 and 5001 open for external control. Port 5000 is a port for receiving commands, and port 5001 is a port for requesting and sending data indicating robot status. For convenience, port 5000 is called the command port and port 5001 is called the data port.

Users can send the script command described above to the command port. The command port has a filter for the first command, so if the start is not a script command as described above, such as “jointall”, “movetcp”, “mc”, “pgmode”, etc., the response is “The command is not allowed”. If the command starts with a normal command and passes the input statement to the parser, the response is “The command was executed”.

When the command “reqdata” is sent to the data port, robot status information is sent to the data port in response. The format of the data is shown below.

Header (4 Byte) Data (n Byte)
0x24 Size&0xFF (Size»8)&0xFF 0x03 Data

The format of the data is shown below. Depending on the system version, the size of the data may be different. However, the order is consistent, please refer to the table below.

reqdata format

Exercise

* Print out the RB5's current Position using script command.

* Print out the RB5's current Joint angle using script command.

* Move RB5 from joint angle(0,0,0,0,0,0) to angle(10,20,30,40,50,60), speed 30% using script command.

* Move RB5 from joint Position(0.4,0,0.4,0,0,0) to Position(0.2,0.2,0.5,0,0,0), speed 30% using script command.

Example

External Connect and Initialize with Python

This is simple code for connect External Computer with RB5 Controller.

import socket
RB5_ip = "10.0.2.7"
 
def sendCommand(cmd):
    global cmd_socket
    send_cmd=cmd.encode()
    cmd_socket.send(send_cmd)
 
def initRobot():
    sendCommand("mc jall init")
    time.sleep(1)
 
#  <ProgramMode_Real>
#  change to 'real robot' mode -- robot will move
def setRealMode():
    sendCommand("pgmode real")
    time.sleep(1)
 
# <ProgramMode_Simulation>
# change to 'simulation' mode -- robot will not move except teaching
def setSimulationMode():
    sendCommand("pgmode simulation")
    time.sleep(1)
 
if __name__ == "__main__":  
    host = RB5_ip
    data_port = 5001
    cmd_port = 5000
 
    ###### Initializing #######
    if len(sys.argv)>1:
        host = sys.argv[1]
    data_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    cmd_socket  = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        data_socket.connect((host, data_port))
        cmd_socket.connect((host, cmd_port))
 
        print("start")
 
        initRobot()
        print("init")
 
        setRealMode()
        print("set_real_mode")
 
    except KeyboardInterrupt:
        pass
    finally:
        os._exit(0) # not call close() ** workaround for native dead

Get RB5 data from Controller with Python

This is Example code for get RB5 data from RB5 Controller using Multi-thread. you can make main program to control RB5 with RB5 data.

from queue import Queue 
import threading
 
import socket
import sys
import struct
 
####### RB5 API #######
#RB5 API to control RB5 Robot, 
#This RB5 API is based on RB5 manual
 
def Rb5_decode(data):
    decode_data=[]
    for i in range(26):
        data_4byte=struct.unpack('f',data[i*4:i*4+4])[0]   
        decode_data.append(data_4byte)
    return decode_data
 
def Rb5_getdata(sock):
    bufsize = 4096
    msg='reqdata'
    sdata=msg.encode()
    sock.send(sdata)
    data = sock.recv(bufsize)
    res=Rb5_decode(data)
 
    return res
 
def get_data_thread(sock, q_in, q_out):
    print('start')
    while True:
        cmd=q_in.get()
        if cmd == 1:
            rb5_data_ = Rb5_getdata(sock)
            q_out.put(rb5_data_)
 
def sendCommand(cmd):
    global cmd_socket
    send_cmd=cmd.encode()
    cmd_socket.send(send_cmd)
 
def waitUntilMotionDone():
    usleep(10)
    # while(isMotionIdle() != True):
    #     print(isMotionIdle())
    #     usleep(10)
 
def initRobot():
    sendCommand("mc jall init")
    time.sleep(1)
 
#  <ProgramMode_Real>
#  change to 'real robot' mode -- robot will move
def setRealMode():
    sendCommand("pgmode real")
    time.sleep(1)
    # return *this;
 
# <ProgramMode_Simulation>
# change to 'simulation' mode -- robot will not move except teaching
def setSimulationMode():
    sendCommand("pgmode simulation")
    time.sleep(1)
    # return *this;
 
if __name__ == "__main__":
    q_in =Queue(1)
    q_out =Queue(2)
    global rb5_data
    global cmd_jnt
    global cmd_pose
 
    host = RB5_ip
    data_port = 5001
    cmd_port = 5000
    ###### Initializing #######
    if len(sys.argv)>1:
        host = sys.argv[1]
 
    data_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    cmd_socket  = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        data_socket.connect((host, data_port))
        cmd_socket.connect((host, cmd_port))
 
        print("start")
 
        ###### Start daemon thread to get RB5 data  #######
        t1 = threading.Thread(target=get_data_thread, args=(data_socket, q_in, q_out))
        t1.daemon = True 
        t1.start()
        print("start_tread")
 
        initRobot()
        print("init")
        setRealMode()
        print("set_real_mode")
 
        while True:
            time.sleep(step_time)
            q_in.put(1)
            rb5_data=q_out.get()
            get_robot_param()
 
        print("### End ###")
 
    except KeyboardInterrupt:
        pass
    finally:
        os._exit(0) # not call close() ** workaround for native dead

Appendix

API Commands

The following commands are actual motion commands to move the robot. Each one contains an example string that matches how a user would control the robot from an external application.

Setup command

The following commands are for initialization, termination, operation mode change, and speed change.

1) mc

Script mc jall init
Descript This command starts initialization process.
Example “mc jall init”

2) shutdown

Script shutdown
Descript This command terminates the robot operation and turns off the power.
Example “shutdown”

3) pgmode

Script pgmode mode_type
Descript This command changes the mode between real and simulation modes.

The input values for mode_type should be “real” or “simulation”.
In “real”, the robot moves when commanded.
In “simulation”, the robot does not moves but the internal reference values changes.

The default is “simulation”.
Example “pgmode real”
“pgmode simulation”

4) sdw

Script sdw default_speed spd
Descript This command set the speed of the motion for overall program.

The input value for spd is a number between 0 and 1. Smaller value means slower.
When the value is 0, the robot does not move even if a command is executed.
In this case, the reference value does not change either.

When the pendent is connected to the robot while script programming is running,
the speed can be adjusted via the pendent. Robot always follows the speed at the last command.
Example “sdw default_speed 0.5”

Operation command

The following commands are five operation commands.

1) jointall

Command Jointall
Script jointall spd, acc, joint1, joint2, joint3, joint4, joint5, joint6
Descript This command moves joints in Joint Space.

The input values for joint1 to joint6 in the command denotes base, shoulder, elbow, wrist1, wrist2 and wrist3 accordingly.
Each joint value represents the desired angle to go. The desired angle should be an absolute angle in degree.

The input values for spd and acc are used to define velocity and acceleration accordingly.
The spd and acc should be a number between 0 and 1. Smaller number represents slower.
When the input value is -1, the joint moves with the default value.

This command will be ignored if the previous command is not finished yet.
Example “jointall 0.4, 0.1, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0”

2) movetcp

Command Movetcp
Script movetcp spd, acc, x, y, z, rx, ry, rz
Descript This command moves TCP in Cartesian Space.

The input values for x, y, z are used to define the desired position to go. The values should be a number in mm.

The input values for rx, ry, rz are used to define the desired orientation to go.
It is represented as roll, pitch and yaw in Euler angle, accordingly. The values should be a number in degree.

The input values for spd and acc are used to define velocity and acceleration accordingly.
The spd and acc should be a number between 0 and 1. Smaller number represents slower.
When the input value is -1, the joint moves with the default value.

This command will be ignored if the previous command is not finished yet.
Example “movetcp 0.4, 0.1, 100.0, 100.0, 300.0, 0.0, 90.0, 0.0”

3) movecircle

Command movecircle(three points mode)
Script movecircle threepoints orientation_option spd, acc, x1, y1, z1, rx1, ry1, rz1, x2, y2, z2, rx2, ry2, rz2
Descript This command generates the circular motion of TCP using three points.
Three options determining the orientation of TCP in drawing a circle are available in orientation_option.

With ‘intended’, TCP follows the input orientation for mid-point (rx1, ry1, rz1) and end-point (rx2, ry2, rz2).
With ‘constant’, TCP keeps the current orientation during the circular motion.
With ‘radial’, the orientation of TCP changes in a way of the tangent direction to the center of the circle.

The input values for x1, y1, z1 are used to define the relative position of TCP at mid-point from the center of the circle.
It is a number in mm.

The input values for rx1, ry1, rz1 are used to define the relative orientation of TCP at mid-point
in Euler angle in respect to the center of the circle.
It is a number in degree.

The input values for x2, y2, z2 are used to define the relative position of TCP at end-point from the center of the circle.
It is a number in mm.

The input values for rx1, ry1, rz1 are used to define the relative orientation of TCP at end-point
in Euler angle in respect to the center of the circle.
It is a number in degree.

The input values for spd and acc are used to define velocity and acceleration accordingly.
The spd and acc should be a number between 0 and 1. Smaller number represents slower.
When the input value is -1, the joint moves with the default value.

This command will be ignored if the previous command is not finished yet.
Example “movecircle threepoints intended 0.4, 0.1, 100.0, 100.0, 300.0, 0.0, 90.0, 0.0, 200.0, 200.0, 200.0, 0.0, 90.0, 45.0”
“movecircle threepoints constant 0.4, 0.1, 100.0, 100.0, 300.0, 0.0, 90.0, 0.0, 200.0, 200.0, 200.0, 0.0, 90.0, 45.0”
“movecircle threepoints radial 0.4, 0.1, 100.0, 100.0, 300.0, 0.0, 90.0, 0.0, 200.0, 200.0, 200.0, 0.0, 90.0, 45.0”
Command movecircle(axis mode)
Script movecircle axis orientation_option spd, acc, rot_angle, cx, cy, cz, ax, ay, az
Descript This command generates the circular motion of TCP using axes of rotation defined.

Three options determining the orientation of TCP in drawing a circle are available in orientation_option.
With ‘intended’ or ‘constant’, TCP keeps the current orientation during the circular motion.
With ‘radial’, the orientation of TCP changes in a way of the tangent direction to the center of the circle.

The input values for cx, cy, cz are used to define the position of axes of rotation (the center position of the circle).
It is a number in mm.

The values for ax, ay, az are used to define the orientation of axes of rotation. It represents an unit vector.

The input value for rot_angle is used to define the amount of angle to rotate. It is a number in degree.

The input values for spd and acc are used to define velocity and acceleration accordingly.
The spd and acc should be a number between 0 and 1. Smaller number represents slower.
When the input value is -1, the joint moves with the default value.

This command will be ignored if the previous command is not finished yet.
Example “movecircle axis constant 0.4, 0.1, 180.0, 200.0, 200.0, 200.0, 1.0, 0.0, 0.0”
“movecircle axis radial 0.4, 0.1, 180.0, 200.0, 200.0, 200.0, 1.0, 0.0, 0.0”

4) blend_jnt

Command blend_jnt
Script blend_jnt clear_pt
Descript This command delete all desired joint values previously defined in the joint blending sequence.

This command should be used at the beginning of blend_jnt programming.
Example “blend_jnt clear_pt”
Command blend_jnt
Script blend_jnt add_pt spd, acc, joint1, joint2, joint3, joint4, joint5, joint6
Descript This command adds a desired joint value to the joint blending sequence.

The input values for joint1 to joint6 in the command denotes base, shoulder, elbow, wrist1, wrist2 and wrist3 accordingly.
Each joint value represents the desired angle to go. The desired angle should be an absolute angle in degree.

The input values for spd and acc are used to define velocity and acceleration accordingly.
The spd and acc should be a number between 0 and 1. Smaller number represents slower.
When the input value is -1, the joint moves with the default value.

The speed and acceleration of the motion are defined by spd and acc in the last command.
Example “blend_jnt add_pt 0.4, 0.1, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0”
Command blend_jnt
Script blend_jnt move_pt
Descript This command runs the joint blending motion.

Each joint follows the angles defined in the joint blending sequence.
Example “blend_jnt move_pt”

5) blend_tcp

Command blend_tcp
Script blend_tcp clear_pt
Descript This command delete all desired TCP values previously defined in the TCP blending sequence.

This command should be used at the beginning of blend_tcp programming.
Example “blend_tcp clear_pt”
Command blend_tcp
Script blend_tcp add_pt spd, acc, radius, x, y, z, rx, ry, rz
Descript This command adds a desired TCP value to the TCP blending sequence.

The input value for radius determines the smoothness of blending. The value is in mm.
Arithmetically it is the distance from the straight line between the first and third points to the second point.
Thus, when it is set to 0, the blending becomes maximized and the robot skips the second point.

The input values for x, y, z are used to define the desired position to go. The values should be a number in mm.

The input values for rx, ry, rz are used to define the desired orientation to go.
It is represented as roll, pitch and yaw in Euler angle, accordingly. The values should be a number in degree.

The input values for spd and acc are used to define velocity and acceleration accordingly.
The spd and acc should be a number between 0 and 1. Smaller number represents slower.
When the input value is -1, the joint moves with the default value.

The speed and acceleration of the motion are defined by spd and acc in the last command.
Example “blend_tcp add_pt 0.4, 0.1, 30.0, 100.0, 100.0, 300.0, 0.0, 90.0, 0.0”
Command blend_tcp
Script blend_tcp move_pt
Descript This command runs the TCP blending motion.

TCP follows the positions and orientations of TCP defined in the TCP blending sequence.
Example “blend_tcp move_pt”

I/O Control command

The following commands are commands to control the output values of the digital and analog ports of switchboards and tool flanges. There are three commands.

1) digital_out

Script digital_out d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15
Descript This command generates a signal through the digital output port.

The input values for d0 to d15 are used to activate the port.
The number should be 0 or 1. 0 and 1 mean off and on, accordingly.

-1 can be used other than 0 or 1. In this case, the port with -1 keeps the previous status.
Example “digital_out 1, 1, 1, 1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1”

2) analog_out

Script analog_out a0, a1, a2, a3
Descript This command generates a signal through the analog output port.

The input values for a0 to a3 are the output voltage of the port.
The voltage should be a number between 0 and 10.

-1 can be used other than a number. In this case, the port with -1 keeps the previous voltage.
Example “analog_out 5.0, 5.0, -1, -1”

3) tool_out

Script tool_out volt, d0, d1
Descript This command sets the voltage and corresponding digital output ports at the tool flange.

The input value for volt is used to set the voltage to generate.
The value should be 0, 12 or 24. Any number other than that will be ignored.

-1 can be used to keep the voltage previously defined.

The input values for d0 to d1 are used to activate the port.
The number should be 0 or 1. 0 and 1 mean off and on, accordingly.

-1 can be used other than 0 or 1. In this case, the port with -1 keeps the previous status.
Example “tool_out 12, 1, 0”

reqdata format

Header (4 Byte) Data (n Byte)
0x24 Size&0xFF (Size»8)&0xFF 0x03 Data

Final Words

For questions, clarifications, etc, Email: kimb52@unlv.nevada.edu

rb5_advanced_programming.txt · Last modified: 2023/02/07 14:22 by bskim