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

How to generate programs with RUNMODE_MAKE_ROBOTPROG

#1
Hello everyone. I was wondering how to modify the location where programs are saved using the API. With the GUI this is easy as the command "Generate Robot Program (as...)" either opens a VSCodium window or a file dialog which both allow me to choose the directory to save to. For the API however I can't find anything in the documentation, the only explanations given are variations of the following :

Quote:Finish()
Stops the communication with RoboDK. If setRunMode is set to RUNMODE_MAKE_ROBOTPROG for offline programming, any programs pending will be generated

Currently the program is neither saved in the default directory that is chosen when using the GUI (C:\Users\UserName\Documents\RoboDK\Programs) nor is it saved in the directory of my station file.

I tried to find the correct way to go about this by using the code provided with the ProgramStart() documentation but it simply doesn't do any saving as far as I can see (see code below). I also looked into the "Offline programming with GUI" example without any success either.
Code:
from robodk.robolink import *            # import the robolink library
RDK = Robolink()                         # connect to the RoboDK API (RoboDK starts if it has not started
RDK.AddFile(path_to_station)             # Open desired RoboDK station
robot = RDK.Item('', ITEM_TYPE_ROBOT)    # use the first available robot
RDK.ProgramStart('Test_Dir',r'C:\Users\UserName\Documents\RoboDK\Programs', "KUKA_KRC4_DAT", robot)  # specify the program name for program generation
# RDK.setRunMode(RUNMODE_MAKE_ROBOTPROG) # redundant
home = RDK.Item('Home')
poseref = home.Pose()
robot.MoveJ(home)                        # make a simulation
RDK.Finish()                             # Provokes the program generation (disconnects the API)

Can I get a minimal example of chosing an existing program inside RoboDK and saving it to a directory of choice?
#2
You should add an ending slash to the path where you'll save the programs.

Example:
Code:
RDK.ProgramStart('Test_Dir',r'C:\Users\UserName\Documents\RoboDK\Programs\', "KUKA_KRC4_DAT", robot)
Also, you can override the location where you would like to save programs in your post processor. I assume you didn't customize the post processor.
#3
Thanks for the advice. Unfortunately fixing the path string wasn't enough, although it was one of the issues and helped me during troubleshooting. A custom post processor proved unnecessary but helped as well in this regard. I ran into the initial and other problems during Debugging but managed to get it working in the end. While I couldn't pinpoint every bug exactly the main issues were the following:

  • Remote host closed an existing connection [WinError 10054]
    Seemingly happened because the python script execution was faster than RoboDK startup. Adding a delay of 2.5 seconds after opening the station helped to eliminate this. A smaller delay probably works as well.
  • RoboDK execution aborted because COM socket was not available
    Happens due to RDK.Finish() closing the connection. Reestablishing a connection with RDK.Connect() enabled me to continue using the station and connection as normal after program generation.
  • No program code generated
    The error happened more often (but not always) if no program instructions were given in between RDK.ProgramStart() and RDK.Finish(). The error disappeared completely after enabling the run mode setting that was commented out (# RDK.setRunMode(RUNMODE_MAKE_ROBOTPROG) # redundant) and moving RDK.setRunMode(RUNMODE_MAKE_ROBOTPROG) before RDK.ProgramStart(). I couldn't pinpoint the reasons exactly as reproducing the error was quite inconsistent so my best guess is that there might be timing issues with the Robolink communication where the runmode does not get set in time.
  • Program code generated under different name
    Also solved by moving RDK.setRunMode(RUNMODE_MAKE_ROBOTPROG) before RDK.ProgramStart().

I hope this might help somebody else in the future and suggest to the RoboDK team to change the example code provided in the documentation (2.1.1 Robolink - ProgramStart()).


Working example program
Code:
from robodk.robolink import *           # import the robolink library
RDK = Robolink()                        # connect to the RoboDK API (RoboDK starts if it has not started
RDK.AddFile(path_to_rdk)                # Open desired RoboDK station
time.sleep(2.5)                         # Wait for RoboDK software to start
robot = RDK.Item('', ITEM_TYPE_ROBOT)   # use the first available robot

RDK.setRunMode(RUNMODE_MAKE_ROBOTPROG)  # Set runmode to enable program generation

# Specify program name, program path, post-processor and robot (item) to be used
RDK.ProgramStart('Test_Dir', 'C:/Users/kaysnico/Documents/RoboDK/Programs/', "KUKA_KRC4_DAT", robot)

# Start of program
home = RDK.Item('Home')
robot.MoveJ(home)
# End of program

RDK.Finish()                            # Provokes the program generation (disconnects RoboDK from Python API)
time.sleep(0.01)
RDK.Connect()                           # Reestablish Python-RoboDK communication socket
#4
Thank you for your feedback.

I understand you integrated a try/except strategy to capture the errors and properly generate the code. Let us know if you need more help.
  




Users browsing this thread:
1 Guest(s)