For more content, please click on the above  ABB robot combat skills  to follow

You can also click  on the classics below the official account to  browse more content

Please leave a message in the background before reprinting . Everyone supports the original work and promotes the use and development of robots.

This official account provides technical support for various ABB robot applications, simulations, and graduation projects, and provides detailed background messages .

This official account sincerely hopes to cooperate with various robot training institutions and robot use units, provide technical support, and leave a detailed background message

Click to read the original text at the end of the article to get the complete python code and robot workstation code

picture

1.  Python controls the motion of ABB robot . This article introduces python to communicate with the robot through socket, send data to the robot and control the movement of the robot. 
2. When python  uses socket communication, it is necessary to write rapid code corresponding to acceptance and processing on the robot side. At the same time, it is also more troublesome for operations such as starting and stopping.
3. Robot Web Service (RWS ) provides a URL-based secondary development interface for ABB robots. For details, see Viewing and Setting Robot Variables Through Web Pages
Through R WS , the robot data and IO can be read and written conveniently, and the robot can also be reset pointer, start and pause, etc. The above operations do not require writing relevant code in R APID
4.   For example, for the robot motor  on, according to the definition in rws, the following code can be written in python
def motors_on(self):    """Turns the robot's motors on.    Operation mode has to be AUTO.    """
payload = {'ctrl-state': 'motoron'} resp = self.session.post(self.base_url + "/rw/panel/ctrlstate?action=setctrlstate", data=payload)
if resp.status_code == 204: print("Robot motors turned on") else: print("Could not turn on motors. The controller might be in manual mode")
5.   For example, to modify the robot variable value, according to the definition in rws, you can write the following code in python
def set_rapid_variable(self, var, value):    """Sets the value of any RAPID variable.    Unless the variable is of type 'num', 'value' has to be a string.    """
payload = {'value': value} resp = self.session.post(self.base_url + '/rw/rapid/symbol/data/RAPID/T_ROB1/' + var + '?action=set', data=payload) return resp

6.  Organize the above code into classes and reference them in python to control the robot

import PYRWS as RWSclass robtarget:    trans=[0,0,0]    rot = [1,0,0,0]robot = RWS.RWS(base_url='http://127.0.0.1', username='Default User', password='robotics')robot.reset_pp()robot.motors_on()robot.start_RAPID()p1 = robtarget()while True:    robot.wait_for_rapid1('state', '0')    p1.trans, p1.rot = robot.get_robot_position()    #获取当前位置    print('当前位置',p1.trans)    numbers = input('输入相对坐标x,y,z, 例如 100,20,300\n')    numbers = list(map(float, numbers.split(',')))    robot.set_robtarget_translation('ptmp', numbers)    robot.set_rapid_variable('state',1)

Click to read the original text to get the complete python code and robot workstation code