KUKA KRL in python- Printable Version +- RoboDK Forum (//www.sinclairbody.com/forum) +-- Forum: RoboDK (EN) (//www.sinclairbody.com/forum/Forum-RoboDK-EN) +--- Forum: RoboDK API (//www.sinclairbody.com/forum/Forum-RoboDK-API) +--- Thread: KUKA KRL in python (/Thread-KUKA-KRL-in-python) |
KUKA KRL in python-KatCla-12-04-2020 Dear forum users, I wonder if there is a possibility to include KUKA KRL code within my python script. With KRL i would write:BAS(#TOOL,2) to activate Tool2. Now I wonder how to activate tools with the RoboDK API? I tried to think of a workaround. I wanted to create a KUKA program within the Python script, pass the KRL command and run the program. That didn't work. Maybe I faulty interpreted the AddProgram()-function. Those are the few lines I have tried within my python script: prog = RDK.AddProgram('Set_Tool_Program') prog.RunInstruction('BAS(#TOOL,2)',INSTRUCTION_INSERT_CODE) prog.RunCode() prog.WaitFinished() Does anybody know how to incorporate the KRL "BAS(#TOOL,2)" command into my python script? Thank you in advance! RE: KUKA KRL in python-KatCla-12-11-2020 [attachment=1670 Wrote:KatCla pid='7083' dateline='1607094418']Dear forum users, Hello everyone, i could get my python script to run. To creat and run the program I used the following lines: RDK.AddProgram('Set_Tool_Program') prog=RDK.Item('Set_Tool_Program',ITEM_TYPE_PROGRAM) prog.RunInstruction('BAS(#TOOL,2)',INSTRUCTION_INSERT_CODE) cnt=prog.RunCode() prog.WaitFinished() print(cnt) Since my program includes just one command (to change the active tool), and the function RunCode() returns 1, I asume that theoretically the instruction shoud be executed successfully. But practically it is not executed, because my active tool is still the same. Now I want to ask wich kind of instructions can programs in the project tree execute? A snipped of the program in the porject tree is attached. I am glad for any help! RE: KUKA KRL in python-Albert-12-14-2020 I assume you are using the robot driver. Custom instructions are not supported using the driver with most robot controllers. However, you can customize a program calls trigger in your RoboDKSync file as explained here: //www.sinclairbody.com/forum/Thread-Program-Event-or-Function-Call-for-3D-Printing-Extruder-Control?pid=4529#pid4529 So you could link a program call such as Program(2) to BAS(#TOOL,2). RE: KUKA KRL in python-KatCla-12-18-2020 [attachment=1705 Wrote:Albert pid='7211' dateline='1607963965']I assume you are using the robot driver. Custom instructions are not supported using the driver with most robot controllers. Dear Albert, thank you very much for your reply! I am not entirely sure if I understood you correctly, but I changed the RoboDKSync file as seen in the attachement. 和我的pythonscript I tried to run the "RunCodeCustom" command, but I am not sure how to pass the program ID so that the correct CASE within the Sync file is chosen. According to your suggested thread I tried it like: robot.RunCodeCustom("Program 2",INSTRUCTION_CALL_PROGRAM) in order to enter CASE 2. That does not work. So It seems like I am programming nonsense again. Could you please help me with passing the program id, in order to choose the right CASE within the Sync file? Or to clear my misunderstandings? Thank you very much! RE: KUKA KRL in python-Albert-12-26-2020 Can you try calling RunInstruction instead of RunCodeCustom? For example:
Code:
robot.RunInstruction("Program 2",INSTRUCTION_CALL_PROGRAM)
This should enter CASE2. Keep in mind this Switch case is inside another switch case. RE: KUKA KRL in python-KatCla-01-03-2021 (12-26-2020, 03:00 PM)Albert Wrote:Can you try calling RunInstruction instead of RunCodeCustom? Hello Albert, thank you again for your reply! I will try your suggestion. Thank you! To clear misunderstandings: You have mentioned in a different thread that I can not trigger programs by name, so "Program 2" is the fixed syntax? I do not have to adapt the "Program" ? Just the following integer, depending on what case to enter? My RoboDKSync file is the default file. Do I have to adapt anything else? What do you mean by "this switch case is inside another switch case"? Do I have to set the according case (case 13 => COM_ACTION = 13) of the outer (first) switch case myself? In my understanding: The call of "RunInstruction(program_id, ...)" triggers (enters) the 13th case of the first switch case and with the program_id I choose the case of the second switch case. Isn't it like that? Thank you for your help! |