UnderAutomation
질문이요?

[email protected]

문의하기
UnderAutomation
⌘Q
이 페이지는 영어로만 제공됩니다.

Get started with Matlab

Load UnderAutomation.Robotics in Matlab with NET.addAssembly: Matlab versions and operating systems, a first script on a Fanuc then a Yaskawa controller, the license key of each brand, from .NET to Matlab, known limits.

  • Requirements
  • Load the library
  • On Windows
  • On Linux and macOS
  • First program
  • Connect and read the identity of the controller
  • The same code for another brand
  • Brand and address from a configuration file
  • License
  • From .NET to Matlab
  • Examples
  • Read the position
  • Check a method before you call it
  • Known limits
  • What to read next

This page shows how to use UnderAutomation.Robotics from Matlab, to read and control a Fanuc, Yaskawa, Universal Robots, ABB or Stäubli controller from a Matlab script with one API. Matlab loads the .NET DLL of the library with its .NET interface: nothing else is installed on the PC, no software of the robot maker and no driver.

Requirements

ItemSupported
WindowsMatlab with the .NET Framework 4.6.2 or later (the default on Windows 10 and 11). Load the net48 DLL. Not tested by UnderAutomation with this library yet
Linux and macOSMatlab R2024b or later with the .NET runtime, selected by dotnetenv("core"), and the netstandard2.1 DLL. Not tested by UnderAutomation with this library yet
ControllersFanuc, Yaskawa, Universal Robots, ABB and Stäubli: see Connect to your robot

Matlab documents its .NET interface in Call .NET from MATLAB.

Load the library

On Windows

  1. Download UnderAutomation.Robotics.zip from the latest release of Robotics.NET.
  2. Unblock the zip before you extract it: right click, Properties, check Unblock.
  3. Copy its net48 folder next to your script.
  4. Load the DLL with NET.addAssembly, then import the namespaces you use.
% The net48 folder of UnderAutomation.Robotics.zip, copied next to this script
dll = fullfile(pwd, 'net48', 'UnderAutomation.Robotics.dll');
if ~NET.isNETSupported
error('No supported .NET Framework found on this computer');
end
% Load the library once per Matlab session
NET.addAssembly(dll);
% The common API, then the namespace of each brand you connect
import UnderAutomation.Robotics.Controllers.*
import UnderAutomation.Fanuc.*

NET.addAssembly needs an absolute path: fullfile(pwd, ...) builds one that works on every operating system. Matlab cannot unload a .NET assembly: restart Matlab to load a new version of the DLL.

Do not load a brand DLL (UnderAutomation.Fanuc.dll...) in the same Matlab session: Robotics contains the same types. See Migrate from a brand SDK.

On Linux and macOS

Matlab R2024b and later can use the .NET runtime instead of the .NET Framework. Set the environment variable DOTNET_ROOT to the folder of the .NET runtime, call dotnetenv("core") before NET.addAssembly, and load the DLL of the netstandard2.1 folder. See dotnetenv in the Matlab documentation.

First program

Connect and read the identity of the controller

Create a RobotController, connect it with the connection parameters of the brand and read a value.

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Robotics.dll'));
import UnderAutomation.Robotics.Controllers.*
% No key is needed during the 30 day trial.
% After the trial, register the license key of each brand once, before the first connection.
% UnderAutomation.Fanuc.FanucRobot.RegisterLicense('YourCompanyName', 'YOUR_FANUC_LICENSE_KEY');
% The brand comes from the type of the parameters: here a Fanuc controller
robot = RobotController();
robot.Connect(UnderAutomation.Fanuc.ConnectionParameters('192.168.0.1'));
% Identity of the controller
info = robot.Info.Read();
fprintf('%s %s, software %s\n', char(info.BrandName), char(info.Model), char(info.SoftwareVersion));
robot.Disconnect();

The brand comes from the class of the connection parameters. Here, UnderAutomation.Fanuc.ConnectionParameters connects to a Fanuc controller. The other classes are in the table of Get started with .NET.

The same code for another brand

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Robotics.dll'));
import UnderAutomation.Robotics.Controllers.*
% A cell with a Fanuc and a Yaskawa controller: only the connection parameters change
cellParameters = { ...
UnderAutomation.Fanuc.ConnectionParameters('192.168.0.1'), ...
UnderAutomation.Yaskawa.ConnectParameters('192.168.0.2')};
for i = 1:numel(cellParameters)
% The same code for both brands
robot = RobotController();
robot.Connect(cellParameters{i});
info = robot.Info.Read();
fprintf('%s %s, software %s\n', char(info.BrandName), char(info.Model), char(info.SoftwareVersion));
robot.Disconnect();
end

Brand and address from a configuration file

RobotConnectionParameters.Create creates the connection parameters from the name of the brand and the address. Its third argument is the routing text, optional in C#: Matlab passes it.

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Robotics.dll'));
import UnderAutomation.Robotics.Controllers.*
% Brand and address from a configuration file: fanuc, yaskawa, universalrobots, abb or staubli
brand = 'yaskawa';
address = '192.168.0.2';
% The third argument is the routing text: '' for no setting
robot = RobotController();
robot.Connect(RobotConnectionParameters.Create(brand, address, ''));
% The same code for each brand: Info.Read has a route on the five brands
info = robot.Info.Read();
disp(char(info.Model));
robot.Disconnect();

License

Each brand runs for 30 days without a key, from the first use of the library. After the trial, register the license key of each brand you connect, once per Matlab session, before the first connection. Robotics has no license of its own: see Licensing.

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Robotics.dll'));
import UnderAutomation.Fanuc.*
import UnderAutomation.Yaskawa.*
% One key per brand, registered once per Matlab session, before the first connection
FanucRobot.RegisterLicense('YourCompanyName', 'YOUR_FANUC_LICENSE_KEY');
YaskawaRobot.RegisterLicense('YourCompanyName', 'YOUR_YASKAWA_LICENSE_KEY');
% Each brand has its own license state
fanucInfo = FanucRobot.LicenseInfo;
yaskawaInfo = YaskawaRobot.LicenseInfo;
disp(char(fanucInfo.ToString()));
disp(char(yaskawaInfo.ToString()));
% Check the brands of your cell once at startup
if ~fanucInfo.IsLicensed
error(char(fanucInfo.ToString()));
end

From .NET to Matlab

The names of the classes, methods and properties are the .NET names of the other pages. The C# samples of the documentation translate line by line, with these rules:

.NETMatlab
new RobotController()RobotController(), after import UnderAutomation.Robotics.Controllers.*
new ConnectionParameters("192.168.0.1")UnderAutomation.Fanuc.ConnectionParameters('192.168.0.1'), with the full name
"192.168.0.1"'192.168.0.1', a char vector
An optional argument, like groupPass every argument: robot.Motion.ReadPose(int32(1))
An int argumentint32(1)
values[0]values(1): Matlab indexes .NET arrays from 1
A double[] result, like JointValues.Valuesdouble(values) converts it to a Matlab vector
A string resultchar(result) gives a Matlab char vector
An enumeration value, like StateFeature.ReadStateFeature.Read, after import UnderAutomation.Robotics.Controllers.*
catch (FeatureNotSupportedException ex)catch e, then e.ExceptionObject gives the .NET exception
try { } finally { }try ... catch, then the cleanup in both branches

Examples

Read the position

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Robotics.dll'));
import UnderAutomation.Robotics.Controllers.*
robot = RobotController();
robot.Connect(RobotConnectionParameters.Create('fanuc', '192.168.0.1', ''));
% Motion group 1: Matlab passes every argument, also the optional ones
position = robot.Motion.ReadPose(int32(1));
pose = position.Pose;
fprintf('X %.3f, Y %.3f, Z %.3f\n', pose.X, pose.Y, pose.Z);
% Values is a .NET array: double() converts it to a Matlab vector
joints = robot.Motion.ReadJoints(int32(1));
disp(double(joints.Values));
robot.Disconnect();

ReadJoints is not available on every brand: see Motion.

Check a method before you call it

A method that the brand does not have throws FeatureNotSupportedException. IsAvailable returns false before the call. See Errors.

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Robotics.dll'));
import UnderAutomation.Robotics.Controllers.*
robot = RobotController();
robot.Connect(RobotConnectionParameters.Create('staubli', '192.168.0.254', ''));
% False when the brand has no route for the method, or no protocol of the route answered
if robot.State.IsAvailable(StateFeature.Read)
state = robot.State.Read();
disp(char(state.Mode.ToString()));
end
try
robot.State.Read();
catch e
% ExceptionObject is the .NET exception, for example a FeatureNotSupportedException
if isa(e, 'NET.NetException')
disp(char(e.ExceptionObject.Message));
else
rethrow(e);
end
end
robot.Disconnect();

Known limits

  • Matlab has no named arguments and no optional arguments: pass all the arguments of a .NET method, in order.
  • An exception of the library is a NET.NetException in Matlab. Its ExceptionObject property holds the .NET exception (RobotControllerException, FeatureNotSupportedException...), with its Message and its properties.
  • The methods with a progress callback, like ReadBytesWithProgress of robot.File, need a .NET delegate. Prefer the methods without a callback, like ReadBytes.
  • RobotController has no event. The objects of the brand SDKs, given by robot.Native, have some: a .NET event needs addlistener, and its handler runs on a thread of the library. Prefer to read the values in a loop.
  • Matlab keeps the DLL loaded until it closes.

See also the Matlab pages on the limits of .NET arrays, .NET methods and .NET enumerations.

What to read next

  • Connect to your robot: the connection parameters of each brand and the settings of the controllers.
  • Work without a robot: the simulators of the robot makers.
  • Common API: the services of RobotController.
  • Routing: which protocol each method uses on each brand.
  • Licensing: the trial and the license key of each brand.