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

Using Matlab to control real robot

#1
Hi,
I’m currently using Matlab to open up RoboDK and run a program created in RoboDK. I am wondering if it is possible to then go one step further and control the real robot doing this. By this I mean, when I run the program on Matlab that opens and runs the RoboDK program, can it instantly connect to the real robot without me needing to right hand click on the simulation robot, click connect to robot and add the required Robot IP, before then clicking connect.
Do you know if this can be done by either adding a python code which can be inserted in the program at the beginning or can the script in Matlab have something added to it for this to work?
For further information, the real robot is a Yaskawa Motoman GP8, which I can connect to using an Ethernet cable.
#2
You should be able to move the robot directly from your Matlab code. You should simply add a call to robot.Connect() to try to connect to the robot. This also changes the run mode to "RUNMODE_RUN_ROBOT" so that all robot commands are sent to the real robot. 

Make sure to configure the IP in the robot connection panel (select Connect-Connect robot).

You can find a more complete example using Python here:
https://robodk.com/doc/en/PythonAPI/exam...rogramming

You should be able to do the same using the Matlab API.
#3

.rdk   Robot on its own.rdk (Size: 1.34 MB / Downloads: 229)
.docx   Code for Controlling Robot via Matlab and RoboDK.docx (Size: 12.72 KB / Downloads: 208)
(09-13-2023, 09:31 AM)Albert Wrote: You should be able to move the robot directly from your Matlab code. You should simply add a call to robot.Connect() to try to connect to the robot. This also changes the run mode to "RUNMODE_RUN_ROBOT" so that all robot commands are sent to the real robot. 

Make sure to configure the IP in the robot connection panel (select Connect-Connect robot).

You can find a more complete example using Python here:
https://robodk.com/doc/en/PythonAPI/exam...rogramming

You should be able to do the same using the Matlab API.

Thanks Albert.
Do you mean to add "call to robot.Connect() to try to connect to the robot. This also changes the run mode to "RUNMODE_RUN_ROBOT2 so that all robot commands are sent to the real robot." to the Matlab code or do you mean add it to the RoboDK program?

I've attached both the Matlab code and the RoboDK program I want to run, if this helps you identify the place I need to put this.

Would this still prompt me to enter an IP address and click connect or will this also go in the call command?
#4
If you want to start a program you already have in your UI to run on the robot you should first set it to run on the robot:
Code:
program.setRunType(Robolink.RUNMODE_RUN_ON_ROBOT);
This is the same as right clicking the program and checking the option "Run on robot".

You can also set the IP from your code but using setConnectionParam. You can find more information here:
https://robodk.com/doc/en/PythonAPI/robo...tionParams
#5
(09-13-2023, 11:28 AM)Albert Wrote: If you want to start a program you already have in your UI to run on the robot you should first set it to run on the robot:
Code:
program.setRunType(Robolink.RUNMODE_RUN_ON_ROBOT);
This is the same as right clicking the program and checking the option "Run on robot".

You can also set the IP from your code but using setConnectionParam. You can find more information here:
https://robodk.com/doc/en/PythonAPI/robo...tionParams

Thanks Albert.

So, I would firstly need to have the "setConnectionParams(robot_ip) to run, establishing a connection between the simulation and the real robot. Then following this have the "program.setRUNTYPE(Robolink.RUNMODE_RUN_ON_ROBOT);" run telling the program to run on the robot.

Would this need to be put either in a Python code on RoboDK and put in the program as a call, or is it better ti type it directly into the Matlab code?

When doing the IP connection do I need to type the actual IP that needs to connect to in the "setconnection" command or would I be prompted to do this once the program was running?
#6
You can use Python code or Matlab directly. You can ask the user to enter the IP if you want but this needs to be implemented in your Matlab code.

Keep in mind that the function setConnectionParams requires more parameters, not only the IP. You can get the already existing parameters using ConnectionParams.
#7
(09-14-2023, 03:18 PM)Albert Wrote: You can use Python code or Matlab directly. You can ask the user to enter the IP if you want but this needs to be implemented in your Matlab code.

Keep in mind that the function setConnectionParams requires more parameters, not only the IP. You can get the already existing parameters using ConnectionParams.

Hi Albert,

To test the part which should tell the RoboDK program to Run on the Robot. I've created a Python code with this in. Then manually connected the normal way with no commands, so when the Matlab code is run, the only thing different is the command to tell the program to run on the robot without me needing to press anything. However, the following error occurs, "program.setRunType(Robolink.RUNMODE_RUN_ON_ROBOT) NameError: name 'program' is not defined.
#8
I recommend you to take a look at some examples about how to retrieve items (such as a program) from your project and operate with them:
https://robodk.com/doc/en/PythonAPI/exam...to-program
  




Users browsing this thread:
2 Guest(s)