Unable to send custom code to online robot- 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: Unable to send custom code to online robot (/Thread-Unable-to-send-custom-code-to-online-robot) |
Unable to send custom code to online robot-davidmurray-05-13-2019 Hello, I'm trying to activate a tool through modbus on a UR10 robot. Eventually, programming will be done offline, but right now I'd like to do it online through the RoboDK Python API. Here is my code:
Code:
import RoboDK.robolink # RoboDK API
What am I doing wrong? Should I be using RunInstruction or RunProgram instead? Best regards, David RE: Unable to send custom code to online robot-Albert-05-13-2019 Hi David, You should call: robot.Connect() This will trigger the connection (same action as the Connect button in the robot connection panel). RE: Unable to send custom code to online robot-davidmurray-05-13-2019 (05-13-2019, 07:48 PM)Albert Wrote:Hi David, Hi Albert, This line is already present in my code. Any other ideas? Side question: When is it better to make a program (like using MakeProgram) vs. just running RDK.function_here() or robot.Move...()? RE: Unable to send custom code to online robot-Albert-05-14-2019 What return value do you get after you trigger Connect? You should get the flag ROBOTCOM_READY=0 if everything went well. Some robot drivers take a few seconds the first time you try to connect. A more robust option would be to use ConnectSafe(). This will try to connect to the robot multiple times (4 times by default), waiting for the status flag to be ready. RE: Unable to send custom code to online robot-davidmurray-05-14-2019 Yes, I do get ROBOTCOM_READY=0. I'll try another way: First generating a SCRIPT file, uploading it through FTP and then running it. What would be the best way to do this using the RoboDK API? I'm having a little trouble figuring out the difference between run mode, run type, program.MakeProgram, program.RunCode. Could you please give me some indications as to how to achieve the 3 steps above? Best regards, David RE: Unable to send custom code to online robot-Albert-05-14-2019 Can you provide a sample project that can reproduce this connection this issue? We can better help you fix it. It is important to understand the difference between the following: Run Mode (API) 当你连接到机器人通过API (call Connect) you are automatically changing the "run mode" (setRunMode) to move the real robot, not the simulated robot. This applies to the RoboDK API and moving the robots from your code. This is useful if you want to move the robot directly using the API (using MoveJ or MoveL commands from Python or C# code for example). You can change the run mode to just simulate the robot program, validate it or generate the program using the same code. Important: Run mode applies to all the commands of the API. Run type (Program) Run type (setRunType) is different and only applicable to programs generated using the GUI and you can only set it to Run on Robot or simulate. This is exactly the same as if you checked/unchecked theRun on Robotoption of a program. Generate a program through the API MakeProgramapplies to programs created using the GUI or python macros that include robot movements. This call is the same as right clicking a program and selecting "Generate Program": You can pass a flag to upload the program to the robot controller. For example:
Code:
program.MakeProgram(path_file, RUNMODE_MAKE_ROBOTPROG_AND_UPLOAD)
Include customized code in a program You should useRunInstructionwhen you want to include a program call, customized code, comment in another program (program visible in the GUI). For example, if you want to add a new line of code in your program you can use:
Code:
program.RunInstruction('Output any code you want;', INSTRUCTION_INSERT_CODE)
Important regarding file transfer with UR robot (SFTP): You can automatically transfer URP or script files to the robot when you right click a program and select "Send program to robot". This behavior can be customized in the post processor (set the variable UPLOAD_SFTP = True). I recommend you to use theUniversal Robotsor theUniversal Robots URPpost processor. By default, the RoboDK post processor for UR will run the program automatically when you select the option to send the program to the robot (this is an exception for UR since it is a collaborative robot and easier to run programs on the fly from a PC). Changing the UPLOAD_SFTP flag to true will upload the URP program via SFTP. This requires installing the pysftp package. RE: Unable to send custom code to online robot-davidmurray-05-14-2019 Hi Albert, Thanks for this information, it is incredibly useful. I think this information (exactly as you wrote it) should be in the docs. If it's already there then perhaps it's too difficult to find. One other question: How can I specify the output directory and file name of the generated program when using RUNMODE_MAKE_ROBOTPROG_AND_START? Right now the program is written on the Desktop, but I'd like to change that with the API if possible. Here is my code:
Code:
RDK = RoboDK.robolink.Robolink()
Regards, David RE: Unable to send custom code to online robot-Albert-05-20-2019 I noticed that you are already specifying a folder to save your project. However, you may have to add the '/' (slash) character at the end of your path for it to work. This can also be controlled/hard coded in the post processor. RE: Unable to send custom code to online robot-davidmurray-05-23-2019 (05-20-2019, 06:59 PM)Albert Wrote:I noticed that you are already specifying a folder to save your project. However, you may have to add the '/' (slash) character at the end of your path for it to work. This can also be controlled/hard coded in the post processor. Hi Albert, I tried this, but it still does not work. I couldn't find it hardcoded in the post processor. The only way that I was able to change it was through the RoboDK preferences window. Is this a bug? Thanks, David RE: Unable to send custom code to online robot-Albert-05-27-2019 Hi David, All post processors have the ProgSave function defined. This is called during the post processing stage, at the end of program generation and right before saving. This function receives the preferred path defined in RoboDK options menu. Most post processors have a definition that looks like this (you can change the folder to save your program as shown in the first comment):
Code:
def ProgSave(self, folder, progname, ask_user=False, show_result=False):
|