【睿尔曼-RealMan】睿尔曼超轻量仿人机械臂--医疗工作站运行Demo(Python)

Brion 2024-04-24

一、Python语言开发环境

1.Win10系统下使用

        开发环境

        系统:win10

        IDE:PyCharm

        Python版本:python 3.11.2

     由于机械臂相关软件版本不定期更新,如果你使用的软件接口或协议与本文有出入,请联系官方技术人员及时更新。

 2.项目创建

      创建python文件,可以通过多种方式,本文中以Pycharm为示例。详述从项目创建到实际运行控制机械臂。

       创建Python项目。打开Pycharm软件,在右上角’File-->New Project’。打开新建项目界面,在界面中可选择项目路径及项目名称、Python版本等信息。最后点击界面右下角‘Create’按钮。

 

3.写入Python程序

      本文基于医疗工作站运行过程开发demo。将以下程序写入Python程序中即可。代码如下:


import socket
import time
import json

client1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 左臂
Lift = '192.168.1.18'

# 右臂
Right = '192.168.1.19'

# 打开控制器RS485
controller_modbus1 = '{"command":"set_modbus_mode","port":0,"baudrate":115200,"timeout":2}\r\n'

# 夹爪2初始化
gripper2_init = '{"command":"write_registers","port":0,"address":1000,"num":1,"data":[0,0],"device":9}\r\n'

# 夹爪2上使能
gripper2_activate = '{"command":"write_registers","port":0,"address":1000,"num":1,"data":[0,1],"device":9}\r\n'

# 夹爪2全速张开
gripper2_open = '{"command":"write_registers","port":0,"address":1000,"num":3,"data":[0, 9, 0, 0,255, 255],"device":9}\r\n'

# 夹爪2全速闭合
gripper2_close = '{"command":"write_registers","port":0,"address":1000,"num":1,"data":[4,11],"device":9}\r\n'

# 打开末端RS485
controller_modbus3 = '{"command":"set_modbus_mode","port":1,"baudrate":115200,"timeout ":2}\r\n'

# 夹爪1初始化
gripper1_init = '{"command":"write_registers","port":1,"address":1000,"num":2,"data":[0, 0, 0 ,0],"device":9}\r\n'

# 夹爪1上使能
gripper1_activate = '{"command":"write_registers","port":1,"address":1000,"num":2,"data":[0,1,0,1],"device":9}\r\n'

# 夹爪1旋转使能
gripper1_activate1 = '{"command":"write_registers","port":1,"address":1004,"num":4,"data":[1,104,1,128,1,104,2,2],"device":9} \r\n'

# 夹爪1正转2圈
gripper1_turn1 = '{"command":"write_registers","port":1,"address":1004,"num":4,"data":[1,104,32,32,2,104,0,2],"device":9}\r\n'

# 夹爪1反转3圈
gripper1_turn2 = '{"command":"write_registers","port":1,"address":1004,"num":4,"data":[1,104,32,32,-3,104,0,2],"device":9}\r\n'

# 夹爪1全速张开
gripper1_open = '{"command":"write_registers","port":1,"address":1000,"num":1,"data":[1,11],"device":9} \r\n'

# 夹爪1半速闭合
gripper1_close = '{"command":"write_registers","port":1,"address":1000,"num":1,"data":[2,11],"device":9}\r\n'

# 灵巧手拇指抬起
dexterous_hands_up = '{"command":"set_hand_seq","seq_num":1}\r\n'

# 灵巧手拇指按下
dexterous_hands_down = '{"command":"set_hand_seq","seq_num":2}\r\n'

# 右臂初始点位(低速)
right_robot_first = '{"command":"movej","joint":[90000,-90000,90000,-90000,90000,-30000],"v":5,"r":0,"trajectory_connect":0}\r\n'

# 右臂初始点位(高速)
right_robot_first_50 = '{"command":"movej","joint":[90000,-90000,90000,-90000,90000,-30000],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 左臂初始点位(低速)
lift_robot_first = '{"command":"movej","joint":[0,30000,-120000,0,90000,0],"v":5,"r":0,"trajectory_connect":0}\r\n'

# 左臂初始点位(高速)
lift_robot_first_50 = '{"command":"movej","joint":[0,30000,-120000,0,90000,0],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 左臂夹取预备点
lift_robot_clamping_up = '{"command":"movej","joint":[689,23747,-137732,24724,86936,-67],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 左臂夹取点
lift_robot_clamping_down = '{"command":"movej","joint":[671,20176,-140953,31515,86934,-87],"v":5,"r":0,"trajectory_connect":0}\r\n'

# 左臂夹取抬起点2
lift_robot_clamping_down2 = '{"command":"movej","joint":[692,24377,-135531,21888,86933,-68],"v":5,"r":0,"trajectory_connect":0}\r\n'

# 左臂夹取抬起点3
lift_robot_clamping_down3 = '{"command":"movej","joint":[685,27501,-127202,10439,86932,-70],"v":5,"r":0,"trajectory_connect":0}\r\n'

# 左臂放回抬起点3
lift_robot_clamping_down3_1 = '{"command":"movej","joint":[692,24794,-136119,22056,86934,-63],"v":1,"r":0,"trajectory_connect":0}\r\n'

# 左臂夹取抬起点4
lift_robot_clamping_down4 = '{"command":"movej","joint":[690,27714,-128872,11896,86940,-96],"v":5,"r":0,"trajectory_connect":0}\r\n'

# 左臂扫码点
lift_Scan_the_code = '{"command":"movej","joint":[-46458,38633,-129434,855,87540,-63],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 左臂开盖预备点1
lift_Open_the_lid_up_1 = '{"command":"movej","joint":[-29259,86,-98931,8309,87449,-498],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 左臂开盖预备点2
lift_Open_the_lid_up_2 = '{"command":"movej","joint":[-29264,-3738,-109940,23142,87449,-504],"v":5,"r":0,"trajectory_connect":0}\r\n'

# 左臂开盖抬起点
lift_Open_the_lid_raise = '{"command":"movej","joint":[-29264,-3738,-109940,23142,87449,-504],"v":1,"r":0,"trajectory_connect":0}\r\n'

# 左臂关盖抬起点
lift_Open_the_lid_raise_50 = '{"command":"movej","joint":[-29264,-3738,-109940,23142,87449,-504],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 左臂开盖点
lift_Open_the_lid = '{"command":"movej","joint":[-29267,-7683,-115002,32150,87448,-506],"v":5,"r":0,"trajectory_connect":0}\r\n'

# 左臂关盖点
lift_Open_the_lid_2 = '{"command":"movej","joint":[-29267,-7683,-115002,32150,87448,-506],"v":4,"r":0,"trajectory_connect":0}\r\n'

# 右臂吸取预备点
right_learn_up = '{"command":"movej","joint":[96317,-90006,88564,-117973,89829,-30086],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 右臂吸取点
right_learn_down = '{"command":"movej","joint":[96304,-117306,108029,-117726,86164,-37017],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 右臂注入过度点
right_inject_excessive = '{"command":"movej","joint":[102384,-99187,99769,-64241,89869,-30038],"v":50,"r":0,"trajectory_connect":0}\r\n'

# 右臂注入点
right_inject_target = '{"command":"movej","joint":[129148,-99191,103572,-95559,92741,-30526],"v":50,"r":0,"trajectory_connect":0}\r\n'


def Robot_instruct(lr, instruct):
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = lr
    port = 8080
    client.connect((host, port))
    print('Robot_right_connect--OK')
    control = instruct
    client.send(control.encode('utf-8'))
    time.sleep(0.5)
    result = client.recv(1024).decode()
    print(result)
    client.close()


if __name__ == "__main__":
    while True:
        # 右臂外部设备测试
        Robot_instruct(Right, controller_modbus1)
        Robot_instruct(Right, gripper2_init)
        Robot_instruct(Right, gripper2_activate)
        time.sleep(2)
        Robot_instruct(Right, gripper2_open)
        time.sleep(1)
        Robot_instruct(Right, dexterous_hands_down)
        time.sleep(1)
        Robot_instruct(Right, dexterous_hands_up)
        Robot_instruct(Right, right_robot_first)

        # 左臂外部设备测试
        Robot_instruct(Lift, controller_modbus3)
        Robot_instruct(Lift, gripper1_init)
        Robot_instruct(Lift, gripper1_activate)
        Robot_instruct(Lift, gripper1_activate1)
        time.sleep(2)
        Robot_instruct(Lift, gripper1_open)
        Robot_instruct(Lift, lift_robot_first)

# ---------------------------------------------------------------------------------------------------------------------

        # 左臂夹取
        Robot_instruct(Lift, gripper1_open)
        time.sleep(1)
        Robot_instruct(Lift, lift_robot_clamping_up)
        Robot_instruct(Lift, lift_robot_clamping_down)
        time.sleep(0.5)
        Robot_instruct(Lift, gripper1_close)
        time.sleep(0.5)
        Robot_instruct(Lift, lift_robot_clamping_down2)
        Robot_instruct(Lift, lift_robot_clamping_down3)
        # Robot_instruct(Lift, lift_robot_clamping_down4)
        Robot_instruct(Lift, lift_robot_first)
        Robot_instruct(Lift, lift_Scan_the_code)
        Robot_instruct(Lift, gripper1_turn1)
        time.sleep(4)
        Robot_instruct(Lift, lift_Open_the_lid_up_1)
        Robot_instruct(Lift, lift_Open_the_lid_up_2)
        Robot_instruct(Lift, lift_Open_the_lid)
        time.sleep(0.5)
        Robot_instruct(Right, gripper2_close)
        time.sleep(0.5)
        Robot_instruct(Lift, gripper1_open)
        time.sleep(0.5)
        Robot_instruct(Lift, gripper1_close)
        time.sleep(0.5)
        Robot_instruct(Lift, gripper1_turn2)
        time.sleep(2)
        Robot_instruct(Lift, gripper1_turn2)
        time.sleep(1)
        Robot_instruct(Lift, gripper1_turn2)
        Robot_instruct(Lift, lift_Open_the_lid_raise)
        Robot_instruct(Lift, lift_Open_the_lid_up_1)
        Robot_instruct(Lift, lift_robot_first_50)
        time.sleep(1)

        # 右臂滴液
        Robot_instruct(Right, right_robot_first)
        Robot_instruct(Right, right_learn_up)
        time.sleep(0.5)
        Robot_instruct(Right, dexterous_hands_down)
        time.sleep(0.5)
        Robot_instruct(Right, right_learn_down)
        time.sleep(0.5)
        Robot_instruct(Right, dexterous_hands_up)
        time.sleep(0.5)
        Robot_instruct(Right, right_learn_up)
        Robot_instruct(Right, right_robot_first_50)
        Robot_instruct(Right, right_inject_excessive)
        Robot_instruct(Right, right_inject_target)
        time.sleep(0.5)
        Robot_instruct(Right, dexterous_hands_down)
        time.sleep(0.5)
        Robot_instruct(Right, dexterous_hands_up)
        time.sleep(0.5)
        Robot_instruct(Right, right_inject_excessive)
        Robot_instruct(Right, right_robot_first_50)
        time.sleep(1)

        # 左臂取回
        Robot_instruct(Lift, lift_Open_the_lid_up_1)
        Robot_instruct(Lift, lift_Open_the_lid_raise_50)
        time.sleep(0.5)
        Robot_instruct(Lift, gripper1_turn1)
        Robot_instruct(Lift, lift_Open_the_lid_2)
        Robot_instruct(Lift, gripper1_turn1)
        time.sleep(2.5)
        Robot_instruct(Lift, gripper1_close)
        time.sleep(1)
        Robot_instruct(Right, gripper2_open)
        Robot_instruct(Lift, lift_Open_the_lid_up_2)
        Robot_instruct(Lift, lift_Open_the_lid_up_1)
        time.sleep(0.5)
        Robot_instruct(Lift, lift_robot_first_50)
        Robot_instruct(Lift, lift_robot_clamping_down4)
        Robot_instruct(Lift, lift_robot_clamping_down3_1)
        Robot_instruct(Lift, gripper1_open)
        Robot_instruct(Lift, lift_robot_first_50)
        time.sleep(5)

4.运行实例

运行结果展示:

详情见附件

 

附件下载

0 条评论

关于作者

Brion

这家伙很懒,什么也没写!

选择发帖板块
选择发帖板块