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

Problem translating the robot with Python

#1
Hello,
As part of a larger project, the user interface has buttons that can be used to move the robot either by joint increments or linear increments.  The function for the joint moves seem to be working OK, but I am making some error (or errors) with the linear move function.

I stripped down the station to the bare essentials, moved the code into a Python program, and attached it.

The function makes a relative move.  Passing a list of [0,0,100] should move the robot 100mm up in Z.  It prints the current joint values and the "new" joint values to make the translation.  They seem reasonable.  But the robot does not move as expected.  Not surprisingly, it behaves the same way if the real robot is connected or if just using the simulated robot.

Any suggestions on what I am doing wrong?

Thanks for your help,
Henry


Attached Files Image(s)
   

.rdk   Just The Robot.rdk (Size: 1.46 MB / Downloads: 203)
#2
Since the active reference frame used may be different from the robot's base, I would take this into account in cases where a Cartesian position is used, for example:

Code:
    CheckResult = robot.MoveL_Test(currentJoints, ((robot.PoseFrame()).inv() * newPosition), -1)
    print(f'Result of the collision check is {CheckResult}')

Code:
# There can still be errors
    try:
        robot.MoveL((robot.PoseFrame()).inv() * newPosition)
        return True
    except:
        return False

Also, I used minstep_mm= -1, for the MoveL_Test
#3
Hello Sergei,

<edit> After reading this, I though I should email you a station instead </edit>

Your suggestions worked great.  I clearly do not understand enough about transformations.

I have spent all morning trying to track down some strange behavior - it may be related.

The help that you provided was for code used on a Python GUI (PySide2) that embeds RoboDK and uses the API.  When buttons in that GUI use the API to make a robot move (MoveL, MoveJ, etc) it works fine.  There are also scripts in the station that try to move the robot.  This morning was the first time one of those script moves (in simulation, not the real robot) would cause a collision.  This broke the script.

I tried to be clever and use the MoveL_Test method but it also stops the script.
Code:
# See if the linear move will cause a collision
currentJoints = self.Robot.Joints()
try:
CheckResult  = self.Robot.MoveL_Test(currentJoints, pose, -1)
print(f'Result of the collision check is {CheckResult}')
except:
print('The script broke')

try:
self.Robot.MoveL(pose, True)
self.log('    Finished moving the robot')
except Exception as Err:
self.currentError = 'There was a problem moving the robot (linear move)'
self.extraError = str(Err)
self.log('There was a problem making a linear move')
self.log(str(Err))
self.writeParameters()
quit(0)

The MoveL_Test does NOT throw an exception.  It does not show the print statements.  It just stops the script and the status bar says "Collision detected. Robot stopped."  I have no way to deal with the error.  For testing, I am running the script from RoboDK - but eventually it will be run from our GUI.

Why does the MoveL_Test behave as expected in our Python GUI, but not behave as expected using a script in the station?

Thanks for your insight - it has been a difficult day of writing code...
#4
The MoveL_Test and MoveL functions are different. The MoveL_Test fucntion allows you to anticipate errors you could have with MoveL without raising an exception:
  • MoveL_Test: returns if the movement is possible.
  • MoveL: throws an exception when a movement is not possible. You can still catch the error message to get an idea about what is wrong. See the attached example.
Note: the quick validate run mode allows you to check if the movement is possible without triggering the movement.

Summarizing, the MoveL function allows you to do more things if you properly use the RunMode and catch the exceptions. The following example code may help you better:

Code:
rom robolink import *
from robodk import *

RDK = Robolink()
RDK.setRunMode(RUNMODE_QUICKVALIDATE)
RDK._RAISE_EXCEPTION_ON_WARNING = True
r = RDK.Item("", ITEM_TYPE_ROBOT)

j1 = r.Joints().list()

j2 = list(j1)
j2[0] = 999

r.MoveJ(j1)

try:
    r.MoveL(transl(0,0,1e6))
    print(status)
   
except Exception as e:
    print("Problems with movement:")
    print(e)
  




Users browsing this thread:
1 Guest(s)