UnderAutomation
有问题吗?

[email protected]

联系我们
UnderAutomation
⌘Q
本页面仅提供英文版本。

Get started with Matlab

Load the .NET DLL of the Yaskawa SDK in Matlab with NET.addAssembly, then read the status, positions, variables and I/O of a Motoman controller from a Matlab script.

  • Requirements
  • Load the SDK
  • First program
  • From .NET to Matlab
  • Examples
  • Status
  • Position
  • Variables
  • Inputs and outputs
  • Jobs and alarms
  • Known limits
  • What to read next

This page shows how to use the Yaskawa SDK from Matlab, to read and control a Yaskawa Motoman controller from a Matlab script. Matlab loads the .NET DLL of the SDK with its .NET interface: nothing else is installed, on the PC or on the controller.

Requirements

ItemSupported
WindowsMatlab with the .NET Framework 4.6.2 or later (the default on Windows 10 and 11). Load the net48 DLL
Linux and macOSMatlab R2024b or later with the .NET runtime, selected by dotnetenv("core"). Not tested by UnderAutomation yet
ControllersYRC1000 (micro), MOTOMAN NEXT, DX100 / DX200, FS100, ERC / XRC / MRC

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

Load the SDK

  1. Download UnderAutomation.Yaskawa.zip from the latest release of Yaskawa.NET.
  2. On Windows, 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.Yaskawa.zip, copied next to this script
dll = fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll');
if ~NET.isNETSupported
error('No supported .NET Framework found on this computer');
end
% Load the SDK once per Matlab session
NET.addAssembly(dll);
% Import the namespaces you use
import UnderAutomation.Yaskawa.*
import UnderAutomation.Yaskawa.HighSpeedEServer.*
import UnderAutomation.Yaskawa.Common.*

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.

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 net8.0 folder. See dotnetenv in the Matlab documentation.

First program

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
robot = YaskawaRobot();
% IP address of the controller, default ports and timeouts
robot.Connect('192.168.0.1');
status = robot.HighSpeedEServer.GetStatusInformation();
fprintf('Servo on: %d, play mode: %d
', status.ServoOn, status.Play);
robot.Disconnect();

The connection parameters (ports, timeouts, ping) are set like in C#:

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
parameters = ConnectParameters('192.168.0.1');
parameters.PingBeforeConnect = true;
% UDP ports and timeouts of the High Speed Ethernet Server
parameters.HighSpeedEServer.DataPort = 10040;
parameters.HighSpeedEServer.FilePort = 10041;
parameters.HighSpeedEServer.DataTimeoutMilliseconds = 1500;
robot = YaskawaRobot();
robot.Connect(parameters);
robot.Disconnect();

The SDK runs for 30 days without a key. After that, register your license once per Matlab session:

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
% Register the license once, before the first connection
YaskawaRobot.RegisterLicense('YourCompanyName', 'YOUR_LICENSE_KEY');
info = YaskawaRobot.LicenseInfo;
% A readable description of the current state
disp(char(info.ToString()));
% Check the license once at startup
if ~info.IsLicensed
error(char(info.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 YaskawaRobot()YaskawaRobot(), after import UnderAutomation.Yaskawa.*
"192.168.0.1"'192.168.0.1', a char vector
GetSystemParameter(type, 29, group: 0)GetSystemParameter(type, 29, 0): no named arguments
An optional argument, like commandtypePass every argument. [] passes null
short[], int[], float[] returnedA .NET array: double(values) converts it to a Matlab vector
short[] expectedA Matlab vector of the same type: int16([10, 20])
float[] expectedsingle([1.5, 2])
ushort group of ReadIOuint16(1)
values[0]values(1): Matlab indexes .NET arrays from 1
An enumeration value, like p.DataTypechar(p.DataType) gives its name

Examples

Status

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
import UnderAutomation.Yaskawa.HighSpeedEServer.*
robot = YaskawaRobot();
robot.Connect('192.168.0.1');
status = robot.HighSpeedEServer.GetStatusInformation();
% Mode, execution and alarm, as Matlab logicals
fprintf('Play: %d, remote: %d
', status.Play, status.CommandRemote);
fprintf('Running: %d, servo on: %d
', status.Running, status.ServoOn);
fprintf('Alarm: %d, error: %d
', status.Alarming, status.ErrorOccurring);
robot.Disconnect();

Position

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
import UnderAutomation.Yaskawa.HighSpeedEServer.*
robot = YaskawaRobot();
robot.Connect('192.168.0.1');
p = robot.HighSpeedEServer.GetRobotCartesianPosition();
% Tool center point in mm, orientation in degrees
xyz = [p.X, p.Y, p.Z];
rxyz = [p.Rx, p.Ry, p.Rz];
fprintf('X=%.3f Y=%.3f Z=%.3f
', xyz);
robot.Disconnect();
NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
import UnderAutomation.Yaskawa.HighSpeedEServer.*
robot = YaskawaRobot();
robot.Connect('192.168.0.1');
joints = robot.HighSpeedEServer.GetRobotJointPosition();
% A .NET int32 array: convert it to a Matlab vector of pulses
pulses = double(joints.Axes);
disp(pulses(1:6));
robot.Disconnect();

Variables

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
import UnderAutomation.Yaskawa.HighSpeedEServer.*
robot = YaskawaRobot();
robot.Connect('192.168.0.1');
% I000 to I004: integer variables
i = double(robot.HighSpeedEServer.ReadInteger(0, 5).Value);
% Write I010 and I011: a Matlab vector of the .NET type of the method
robot.HighSpeedEServer.WriteInteger(10, int16([-100, 200]));
% R005 to R007: real variables
r = double(robot.HighSpeedEServer.ReadReal(5, 3).Value);
robot.HighSpeedEServer.WriteReal(5, single([1.5, -2.25, 3]));
robot.Disconnect();

Inputs and outputs

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
import UnderAutomation.Yaskawa.HighSpeedEServer.*
import UnderAutomation.Yaskawa.Common.*
robot = YaskawaRobot();
robot.Connect('192.168.0.1');
% 2 groups of general outputs, from group 1: signals #10010 to #10027
outputs = robot.HighSpeedEServer.ReadIO(IOType.GeneralOutput, uint16(1), 2);
% One byte per group, one bit per signal: bit 0 is #10010
bytes = uint8(outputs.Value);
out10013 = bitget(bytes(1), 4); % bitget counts from 1
robot.Disconnect();

Jobs and alarms

NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
import UnderAutomation.Yaskawa.HighSpeedEServer.*
robot = YaskawaRobot();
robot.Connect('192.168.0.1');
% Select the job by its name, without the .JBI extension, at line 0
robot.HighSpeedEServer.SelectJob('WELD01', 0);
% Starting needs the play mode, the remote mode and the servo on
robot.HighSpeedEServer.ServoCommand(OnOffCommandType.Servo, true);
robot.HighSpeedEServer.StartJob();
robot.Disconnect();
NET.addAssembly(fullfile(pwd, 'net48', 'UnderAutomation.Yaskawa.dll'));
import UnderAutomation.Yaskawa.*
import UnderAutomation.Yaskawa.HighSpeedEServer.*
robot = YaskawaRobot();
robot.Connect('192.168.0.1');
% Up to 4 alarms, the most recent first
alarms = [RobotRecentAlarm.Latest, RobotRecentAlarm.SecondLatest, ...
RobotRecentAlarm.ThirdLatest, RobotRecentAlarm.FourthLatest];
for k = 1:numel(alarms)
alarm = robot.HighSpeedEServer.GetAlarm(alarms(k));
if alarm.Code ~= 0
fprintf('%d %s at %s
', alarm.Code, char(alarm.Text), char(alarm.OccurringTime));
end
end
robot.Disconnect();

Known limits

  • Matlab has no named arguments: pass all the arguments of a .NET method, in order.
  • LoadFile and GetFile take a .NET delegate for the progress. Pass [] to skip it.
  • An exception of the SDK is a NET.NetException in Matlab. Its ExceptionObject property holds the .NET exception, with its Message.
  • 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 settings of the controller and the errors.
  • High Speed Ethernet Server overview: the functions of the SDK, one page per topic.
  • Licensing: the 30 day trial and the license key.

轻松将 Universal Robots、Fanuc、Yaskawa、ABB 或 Staubli 机器人集成到您的 .NET、Python、LabVIEW 或 Matlab 应用程序中

UnderAutomation
联系我们Legal

© All rights reserved.