Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to send custom code to online robot
#1
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
import RoboDK.robodk     # Robot toolbox

RDK = RoboDK.robolink.Robolink()
RDK.setRunMode(RoboDK.robolink.RUNMODE_RUN_ROBOT)

robot = RDK.Item('UR10', RoboDK.robolink.ITEM_TYPE_ROBOT) # The currently open station has a robot named "UR10".
robot.setConnectionParams('192.168.241.116', 30001, '/', '', '') # Connect to the robot

success = robot.Connect()
status, status_msg = robot.ConnectedState()

print("Status: {0}, status msg: {1}".format(status, status_msg)) # This returned "0 Ready"

robot.RunCode('modbus_set_output_signal("v1_a", True)', True)
However, nothing happens on the robot when I do this. I have confirmed (when writing this command directly in a new script on the teach pendant) that this modbus command is correct.
  
What am I doing wrong? Should I be using RunInstruction or RunProgram instead?
  
Best regards,
David
#2
Hi David,

You should call:
robot.Connect()

This will trigger the connection (same action as the Connect button in the robot connection panel).
#3
(05-13-2019, 07:48 PM)Albert Wrote: Hi David,

You should call:
robot.Connect()

This will trigger the connection (same action as the Connect button in the robot connection panel).

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...()?
#4
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.
#5
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
#6
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)
When you connect to the robot through the 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 the Run on Robot option of a program.
   

Generate a program through the API
MakeProgram applies 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 use RunInstruction when 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 the Universal Robots or the Universal Robots URP post 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.
#7
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()
RDK.ProgramStart('david_temp01', 'C:/Users/david.murray/Desktop/RoboDK Script Testing', "Universal_Robots", robot)

robot = RDK.Item('UR10', RoboDK.robolink.ITEM_TYPE_ROBOT)

RDK.setRunMode(RoboDK.robolink.RUNMODE_MAKE_ROBOTPROG_AND_UPLOAD)


robot.RunInstruction('modbus_set_output_signal("v1_a", True)', RoboDK.robolink.INSTRUCTION_INSERT_CODE)
robot.RunInstruction('sleep(2)', RoboDK.robolink.INSTRUCTION_INSERT_CODE)
robot.RunInstruction('modbus_set_output_signal("v1_a", False)', RoboDK.robolink.INSTRUCTION_INSERT_CODE)
robot.RunInstruction('modbus_set_output_register("Rail_Cmd_Pos", 900)', RoboDK.robolink.INSTRUCTION_INSERT_CODE)

robot.Disconnect()
RDK.Finish() # Redundant?


Regards,
David
#8
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.
#9
(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
#10
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):
        # You can impose (hard code) a folder right before the program is saved. For example:
        # folder = "C:/your-programs-folder/"
        # (in this case, default settings in RoboDK are ignored)
        # ask_user will be true if the user selected "Save Program As..."

        if ask_user or not DirExists(folder):
            folder = getSaveFolder(folder,'Select a directory to save your program')
            if folder is None:
                # The user selected the Cancel button
                return

        filesave = folder + '/' + progname

        # Save the program
        with open(filesave, "w") as fid:
            for line in self.PROG:
                fid.write(line + '\n')

        # This will notify RoboDK that a file has been saved and the file may be displayed
        print('SAVED: %s\n' % filesave)

        # Remember the files you saved to upload/send to robot 
        # ProgSendRobot will define the protocol used to send the program to the robot (usually FTP)
        # (when selecting "Send Program to Robot")
        self.PROG_FILES = filesave
  




Users browsing this thread:
2 Guest(s)