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

Changing postpocessors through a python API for varying robot programs

Hi RoboDK team, 

I want to ouput multiple robot programs for a single robot movementes through a python API. 

For example, a particular block of robot movements should be exported through KR C4 whereas other block of robot movements should be exported to a Kuka.CNC program. 

to explain: 

// defined parameter: imports, robot, robot_base, path etc. 

post_processor = "KUKA_KRC4"

robot.setParam("PostProcessor", post_processor)
RDK.ProgramStart('Prog1', path,  post_processor, robot)

// movements for Prog1 

RDK.Finish()   //finish the movements for Prog1 and export a KR C4 program 
post_processor = "KUKA_CNC"
robot.setParam("PostProcessor", post_processor)
RDK.ProgramStart('Prog2', path,  post_processor, robot)

// movements for Prog2 

RDK.Finish()   //finish the movements for Prog1 and export a KUKA_CNC program 

// Further moves
This should be possible. The sample code you shared looks like you are heading in the right direction.

What issues did you have?
Hi Albert,

Thanks for the response. I tried a code similar to my sample code and realized, the program exports just the prog1 and neglects everything after the first RDK.Finish() command.

I mean, the movements of prog1 are only exported as the .src, I dont get Kuka_CNC.

I believe it should work if I create multiple functions that export particular robot program. Like Def prog1(movements_for_prog1) Def prog2(movements_for_prog1).

But I would like to have it similar to the one I described above.
Can you share your script here with a demo station, this will help us help you.

Find useful information about RoboDK and its features by visiting our Online Documentation and by watching tutorials on our Youtube Channel

Attached is a demo example. 

The station has a example program (python) that switches in between the postprocessors.

I have added some comments, the code throws a error when RDK.Finish() is called, if I comment the RDK.Finish() function in between the code the, simulation works smooth however the desired output i.e. 3 seperate robot programs are not produced instead a single robot program (KRL) is obtained. 

Please let me know! 

P.S. Please define a output path in the python program main

Pradnil S Kamble

Attached Files
.rdk   Example.rdk (Size: 1.18 MB / Downloads: 230)
You can fix the issues in your script by making these modifications:

  1. You should call RDK.Connect after RDK.Finish (workaround, for some reason the API is not recovering/reconnecting automatically)
  2. The path to the posts folder for Program start should be a valid path so you don't see a popup to save the program.
  3. The name of the post processor should exactly match the post processor file in the Posts folder, it is case sensitive.
I attached the modifications I did to your script to make it work.

    # Use the KUKA CNC post
   post_processor = "KUKA_CNC"
   robot.setParam("PostProcessor", post_processor)
   RDK.ProgramStart('Hex', r"C:/Users/UserName/Downloads/", post_processor, robot)

   # new target on active base
   base_target = park = RDK.AddTarget("Base_target", base)
   xyzabc = [0, 0, 0, 0.0, 0.0, 0.0]

   # make a hexagon there
   poseref = base_target.Pose()

   for i in range(7):
       ang = i*2*pi/6 #angle: 0, 60, 120, ...
       posei = poseref*rotz(ang)*transl(100,0,0)*rotz(-ang)

   #End KUKA CNC program

   RDK.Connect() # Important if you want to continue using the API

   # Go back home with  KRC 4
   post_processor = "KUKA_KRC4"
   robot.setParam("PostProcessor", post_processor)
   RDK.ProgramStart('Home', r"C:/Users/UserName/Downloads/", post_processor, robot)


Thanks Albert and Jeremy!
This is now resolved.

Users browsing this thread:
1 Guest(s)