Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Custom driver for Rokae SR3 Robot not connected Error

#1
Hello!

I have a rokae sr3 robot and there is no driver available for it.
I am writing my own driver similar to the driver suggested in the documentation (apikukaiiwa.py file).

The basic functionality works as expected - it connects, disconnects, changes statuses properly, etc.
The problem is using python for point-to-point movement - an error appears when running the script:

Code:
Traceback (most recent call last):
File “C:/Users/myuser/AppData/Local/Temp/Prog21.py", line 12, in
robot .Movel (target)
File "C:\RoboDK\Python\robodk\robolink.py”, line 6058, in Nove?
_moveX(target, self, MOVE_TYPE_JOINT, blocking)
\RaboDK\Python\robodk\robolink.py", Line 1113, in _movex
self._check_status() #will wait here
File "C:\Robo0K\Python\robodk\robolink.py", line 850, in _check_status
raise Stoppedfrror(self.LAST_STATUS MESSAGE)
robodk.robolink.Stoppedfrror: Robot not connected

Actually the connection is not lost - when trying to change the robot's position using the “move joints” button everything works as it should, also when creating a motion program using robodk's built-in features everything also works fine, after the error you can rerun the code or any action.

But when working with python code, I get this error time after time. Here is my simple code:

Code:
import robodk 
from robolink import *

RDK = Robolink()
robot = RDK.Item('Rokae_SR3')

target1 = RDK.Item('Target 1')
target2 = RDK.Item('Target 2')
target3 = RDK.Item('Target 3')

robot.MoveJ(target1)
robot.MoveJ(target2)
robot.MoveJ(target3)


I tried to track down exactly when this happens - after the first time I get the move command (in my case it's MOVJ) this error appears.
Apparently I'm missing something - maybe I'm not working with statuses correctly. Please help me.
Below is the driver code:


Code:
from robot import *
from convert_tools import *
import time
import sys
import math
ip = "192.168.0.160"
ec = {}
robot = XMateErProRobot(ip)
nDOFs_MIN = 6
DRIVER_VERSION = "RoboDK Driver for Rokae SR3 v0.1"
ROBOTCOM_UNKNOWN = -1000
ROBOTCOM_CONNECTION_PROBLEMS = -3
ROBOTCOM_DISCONNECTED = -2
ROBOTCOM_NOT_CONNECTED = -1
ROBOTCOM_READY = 0
ROBOTCOM_WORKING = 1
ROBOTCOM_WAITING = 2
STATUS = ROBOTCOM_DISCONNECTED
def print_message(message):
    print("SMS:" + message)
    sys.stdout.flush()
def UpdateStatus(set_status=None):
    global STATUS
    if set_status is not None:
        STATUS = set_status
    if STATUS == ROBOTCOM_CONNECTION_PROBLEMS:
        print_message("Connection problems")
    elif STATUS == ROBOTCOM_DISCONNECTED:
        print_message("Disconnected")
    elif STATUS == ROBOTCOM_NOT_CONNECTED:
        print_message("Not connected")
    elif STATUS == ROBOTCOM_READY:
        print_message("Ready")
    elif STATUS == ROBOTCOM_WORKING:
        print_message("Working...")
    elif STATUS == ROBOTCOM_WAITING:
        print_message("Waiting...")
    else:
        print_message("Unknown status")
def ConnectRobot():
    global robot, ec
    try:
        robot.connectToRobot(ec)
        robot.setOperateMode(rokae.OperateMode.automatic, ec)
        robot.setPowerState(True, ec)
        UpdateStatus(ROBOTCOM_READY)
        print("robot connect completed")
    except Exception as e:
        UpdateStatus(ROBOTCOM_CONNECTION_PROBLEMS)
        print(f"connection Error: {e}")
def DisconnectRobot():
    global robot, ec
    try:
        robot.stop(ec)
        robot.setPowerState(False, ec)
        robot.setOperateMode(rokae.OperateMode.manual, ec)
        robot.disconnectFromRobot(ec)
        UpdateStatus(ROBOTCOM_DISCONNECTED)
        print("robot disconnect")
    except Exception as e:
        print(f"disconnect error: {e}")
def waitRobot(robot):
    global ec
    running = True
    while running:
        time.sleep(0.1)
        st = robot.operationState(ec)
        if st == rokae.OperationState.idle.value or st == rokae.OperationState.unknown.value:
            running = False
def RunDriver():
    try:
        for line in sys.stdin:
            RunCommand(line)
    except KeyboardInterrupt:
        print("Driver stop...")
    finally:
        DisconnectRobot()
def RunCommand(linecmd):
    global robot, ec
    def line_2_values(words):
        values = []
        for word in words:
            try:
                values.append(float(word))
            except ValueError:
                pass
        return values
    def execute_movement(joints):
        UpdateStatus(ROBOTCOM_WORKING)
        try:
            ra_jnts = [math.radians(j) for j in joints]
            point_move = MoveAbsJCommand(ra_jnts, 20, 10)
            robot.moveReset(ec)
            robot.executeCommand([point_move], ec)
            robot.moveStart(ec)
            UpdateStatus(ROBOTCOM_READY)
            waitRobot(robot)
        except Exception as e:
            UpdateStatus(ROBOTCOM_CONNECTION_PROBLEMS)
            print(f"Move error: {e}")
    words = linecmd.strip().split(' ')
    values = line_2_values(words)
    if not words:
        return
    command = words[0]
    if command == "CONNECT":
        ConnectRobot()
    elif command == "DISCONNECT":
        DisconnectRobot()
    elif command == "MOVJ" and len(values) >= nDOFs_MIN:
        execute_movement(values[:nDOFs_MIN])
    elif command == "MOVabsJ" and len(values) >= nDOFs_MIN:
        execute_movement(values[:nDOFs_MIN])
    elif command == "CJNT":
        jnts = robot.jointPos(ec)
        gr_jnts = [round(math.degrees(j), 2) for j in jnts]
        print_joints(gr_jnts)
    else:
        print(f"Bad command: {linecmd}")
    UpdateStatus(ROBOTCOM_READY)
def print_joints(joints):
    print("JNTS " + " ".join(format(x, ".2f") for x in joints))
    sys.stdout.flush()
if __name__ == "__main__":
    import atexit
    atexit.register(DisconnectRobot)
    print_message(DRIVER_VERSION)
    RunDriver()
#2
Are you using the latest version of RoboDK?
Does it work if you use the robot connection menu using the user interface?

I recommend you to make the following edit to your driver:
  • Use print_debug instead of print inside your driver (see the file attached)
And call robot.Connect() from your Python code before you run MoveJ commands.

Example:
Code:
r.Connect()
r.MoveJ(target1)
r.MoveL(target2)

Let us know if it works any better. If you still have issues, it will help us if you can share the connection log.


Attached Files
.py   DriverRokae.py (Size: 4.16 KB / Downloads: 27)
#3
Thank you!
The problem was solved by reinstalling the paths for the Python interpreter
#4
Perfect! Thank you for letting us know.
  




Users browsing this thread:
1 Guest(s)