Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Update() replies with incorrect simulation time #39

Closed
sancelot opened this issue Jan 7, 2020 · 3 comments
Closed

[Python] Update() replies with incorrect simulation time #39

sancelot opened this issue Jan 7, 2020 · 3 comments

Comments

@sancelot
Copy link
Contributor

sancelot commented Jan 7, 2020

Using the next snippet, that generates a program with different targets and speed, the update func is used to know the estimated simulation time.

Unfortunately, it replies correctly only for the first program call.
To obtain the right simulation time, I have to uncomment this code (and this not wanted in my case....):

   prog.RunProgram()
   while prog.Busy():
         time.sleep(0.1)

python program I used:

# # -*- coding: utf-8 -*-
from robolink import *    # API to communicate with RoboDK for simulation and offline/online programming
from robodk import *      # Robotics toolbox for industrial robots

#
# https://robodk.com/doc/en/PythonAPI/robodk.html#robodk.Mat
#
import time


def AddTarget(name,pos):
    item = RDK.Item(name)
    itemparent = RDK.Item("World")
    if not item.Valid():
        item = RDK.AddTarget(name, itemparent, itemrobot=0)
    #print(item)
    m = item.Pose()
    #print(m)
    #print(type(m))
    m=Mat().eye()
    #m=transl(pos[0], pos[1], pos[2])
    # xyz wpr deg
    m = m.Offset(pos[0],pos[1],pos[2],pos[3],pos[4],pos[5])
    item.setPose(m)
    




# Any interaction with RoboDK must be done through RDK:
RDK = Robolink()

# Select a robot (popup is displayed if more than one robot is available)
robot = RDK.ItemUserPick('Select a robot', ITEM_TYPE_ROBOT)
if not robot.Valid():
    raise Exception('No robot selected or available')

tool = RDK.Item('flange')
tool.AttachClosest()
tool.DetachAll()
HomeJoints=[-66.18,-17.813,-3.961,0,-86.039,66.18]
robot.setJoints(HomeJoints)

# Turn off rendering (faster)
RDK.Render(True)


HomeTarget=[445,-1008,1000,180,0,0]
ErwinHome = AddTarget("ErwinHome",HomeTarget)
home=RDK.Item("ErwinHome")
# definit la vitesse lineaire
robot.setSpeed(40,-1,-1,-1), # linear mm/sec
init = True
result =""
no=0
mode = 'L' # 'L' Lineaire / Sinon Joint MoveJ
#RDK.setSimulationSpeed(100)

for speed in [40,400,1000,2000,4000]:
 for rounding in [-1,0,10,25,50,100]:
  for dx in [10,100,500,1000,1500]:
    oldprog = RDK.Item("AutoProgram")
    if oldprog.Valid():
        oldprog.Delete()
    #robot.setPose(RDK.Item("T1").Pose())
    nomprog = 'Program_dx'+str(dx)+'_cnt_'+str(rounding)+'_speed_'+str(speed)
    prog = RDK.AddProgram("AutoProgram")
    if init:
        if mode == 'L':
            prog.MoveL(home)
        else:
            prog.MoveJ(home)
        init = False
    # Hide program instructions (optional, but faster)
    prog.ShowInstructions(True)
    prog.setSpeed(speed,speed)
    prog.setRounding(rounding)
    Home = Pose(445,-1008,1000,180,0,0)

    T1=Pose(0,-dx,0,0,0,0)
    M=Home*T1
    AddTarget("T1",Pose_2_Fanuc(M))
    t1 = RDK.Item("T1")
    if mode == 'L':
        prog.MoveL(t1)
    else:
        prog.MoveJ(t1)
    T2=Pose(dx,-dx,0,0,0,0)
    M=Home*T2
    AddTarget("T2",Pose_2_Fanuc(M))
    t2 = RDK.Item("T2")
    if mode == 'L':
        prog.MoveL(t2)
    else:
        prog.MoveJ(t2)
    T=Pose(dx,-dx,dx,0,0,0)
    M=Home*T

    AddTarget("T3",Pose_2_Fanuc(M))
    t3 = RDK.Item("T3")
    if mode == 'L':
        prog.MoveL(t3)
    else:
        prog.MoveJ(t3)

    T=Pose(dx,0,dx,0,0,0)
    M=Home*T
    AddTarget("T4",Pose_2_Fanuc(M))
    t4 = RDK.Item("T4")
    if mode == 'L':
        prog.MoveL(t4)
    else:
        prog.MoveJ(t4)

    T=Pose(0,0,dx,0,0,0)
    M=Home*T
    AddTarget("T5",Pose_2_Fanuc(M))
    t5 = RDK.Item("T5")
    if mode == 'L':
        prog.MoveL(t5)
    else:
        prog.MoveJ(t5)
    if mode == 'L':
        prog.MoveL(home)
    else:
        prog.MoveJ(home)
    check_collisions =  False
#    prog.RunProgram()
#    while prog.Busy():
#         time.sleep(0.1)
    update_result = prog.Update(check_collisions)

#    print("Valid instructions ",update_result[0])
#    print("valid_ratio ",update_result[3])
#    print("message ",update_result[4])
    s = "%6.3f" % update_result[1]
    s=s.replace('.',',') # pauvre conversion pour excel en mode french
    print(s)
    r = "dx %d speed: %d mm/s CNT:%d temps cycle %f sec.\n" % (dx,speed,rounding,update_result[1])
    #print(r)
    result +=r
#    time.sleep(30)


print("END")
print(result)

wrong results without RunProgram():

wrong_results.txt

good results with RunProgram():

good_results.txt

@RoboDK
Copy link
Owner

RoboDK commented Jan 7, 2020

It looks like there is around 10% discrepancy... This does not look normal.
Do you have the RDK file to reproduce this issue?
Can you try calling Update twice?

@sancelot
Copy link
Contributor Author

sancelot commented Jan 8, 2020

Using Update() twice does not help. rdk file is enclosed

demo_0801.zip

@RoboDK
Copy link
Owner

RoboDK commented Jan 20, 2020

I believe the main problem is that the start point is undefined. You'll get different cycle times depending on where the robot is coming from (last point where the robot was left). To avoid confusion with the API I recommend you to impose the robot position to the last known position of the robot. For example, the last point of your program if you are planning to run your program in a loop.

I also recommend you to check if the path is feasible before relying on the cycle time. I changed the TCP of your simulation to make sure the programs that you are automatically generating are feasible.

Another detail: I recommend you to make the first move of a program joint move. This will make sure the robot joints are defined as you expected for the program.

See attached RDK file.

demo_0801 v2.zip

    # Define the start point of the robot before simulating or updating the program 
    # (for example, the last target in case we run this program in a loop)
    # Indicate that this target is a Cartesian target 
    # (this recalculates the joint values of the target)
    home.setAsCartesianTarget()

    # Retrieve the calculated joints
    startjoints = home.Joints()

    # Set the robot to that location and update to retrieve estimated cycle time
    robot.setJoints(startjoints)
    update_result = prog.Update(check_collisions)

@RoboDK RoboDK closed this as completed Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants