UnderAutomation
質問ですか?

[email protected]

お問い合わせ
UnderAutomation
⌘Q
このページは英語でのみ提供されています。

Get started with Python

Install the Yaskawa SDK from PyPI and control a Motoman controller from Python 3.7 to 3.13, on Windows, Linux and macOS. Same functions as the .NET library, with Python names.

  • How it works
  • Install from PyPI
  • Install from the sources
  • First program
  • How the names are written
  • Errors
  • Differences with the .NET API
  • What to read next

This page shows how to install the Yaskawa SDK for Python and write a first program for a Yaskawa Motoman controller. The Python package has the same functions as the .NET library, with Python names.

How it works

The package UnderAutomation.Yaskawa contains the .NET library UnderAutomation.Yaskawa.dll and a Python layer that calls it through pythonnet. pythonnet runs .NET code in the Python process. Nothing is installed on the controller.

ItemSupported
Python3.7 to 3.13
pythonnet3.0.5, installed with the package
Operating systemWindows, Linux, macOS
ControllersYRC1000 (micro), MOTOMAN NEXT, DX100 / DX200, FS100, ERC / XRC / MRC
  • Windows: the DLL runs on the .NET Framework 4.x of Windows. Nothing else to install.
  • Linux and macOS: install the .NET runtime (for example .NET 8), then select it for pythonnet before you start Python. Without this, pythonnet uses Mono, its default runtime on Linux and macOS.
Bash
sudo apt-get install -y dotnet-runtime-8.0
export PYTHONNET_RUNTIME=coreclr

Always write the export: a variable set without it does not reach the Python process. The same choice can be made in code, before the first import of the package:

# Linux and macOS: use the .NET runtime instead of Mono.
# Same effect as "export PYTHONNET_RUNTIME=coreclr", before the first import of the SDK.
from pythonnet import load
load("coreclr")
from underautomation.yaskawa.yaskawa_robot import YaskawaRobot

Install from PyPI

Install the package in a virtual environment:

Bash
python -m venv .venv
# Windows
.venv\Scripts\activate
# Linux and macOS
source .venv/bin/activate
pip install UnderAutomation.Yaskawa

Package page: pypi.org/project/UnderAutomation.Yaskawa

Install from the sources

Bash
git clone https://github.com/underautomation/Yaskawa.py.git
cd Yaskawa.py
pip install -e .

The repository also holds runnable examples, one file per function, in examples/high_speed_e_server (for example hses_get_status.py, hses_read_write_io.py). Run python examples/launcher.py to choose one from a menu. The first run asks the address of the controller and saves it in examples/robot_config.json.

First program

Import YaskawaRobot and ConnectParameters, connect and read a value.

from underautomation.yaskawa.yaskawa_robot import YaskawaRobot
from underautomation.yaskawa.connect_parameters import ConnectParameters
# Without a key, the SDK runs in its 30 day trial period.
# With a license, register it once, before the first connection.
YaskawaRobot.register_license("YourCompanyName", "YOUR_LICENSE_KEY")
# The whole SDK is reachable from a single object
robot = YaskawaRobot()
robot.connect(ConnectParameters("192.168.0.1"))
# Read the position of the tool center point, in mm and degrees
p = robot.high_speed_e_server.get_robot_cartesian_position()
print(f"X={p.x} Y={p.y} Z={p.z} Rx={p.rx} Ry={p.ry} Rz={p.rz}")
robot.disconnect()
Click to see the full code

The SDK runs for 30 days without a key. After that, register_license is needed: see Licensing.

How the names are written

The Python package follows the .NET API, with Python names:

.NETPython
robot.HighSpeedEServer.GetStatusInformation()robot.high_speed_e_server.get_status_information()
parameters.HighSpeedEServer.DataPortparameters.high_speed_e_server.data_port
YaskawaRobot.RegisterLicense(...)YaskawaRobot.register_license(...)
position.X, status.ServoOnposition.x, status.servo_on
Read16BytesChar(0, 2)read16_bytes_char(0, 2)
OnOffCommandType.ServoOnOffCommandType.Servo
SwitchingCommands.ContinueSwitchingCommands.Continue_
short[], int[] returneda .NET array: index it, iterate it, or copy it with list(...)

Methods and properties become snake_case. Enumerations are Python IntEnum classes that keep the .NET value names: use .name to print the name. Each type is in a module named after it, and a method that takes a .NET array accepts a Python list:

# One module per type, named after the type in snake case
from underautomation.yaskawa.yaskawa_robot import YaskawaRobot
from underautomation.yaskawa.connect_parameters import ConnectParameters
from underautomation.yaskawa.common.io_type import IOType
from underautomation.yaskawa.high_speed_e_server.on_off_command_type import OnOffCommandType
from underautomation.yaskawa.high_speed_e_server.robot_control_group import RobotControlGroup
robot = YaskawaRobot()
robot.connect(ConnectParameters("192.168.0.1"))
# A .NET array parameter accepts a Python list
robot.high_speed_e_server.write_integer(0, [10, 20])
# Pass the arguments by position: their names keep the .NET spelling
values = robot.high_speed_e_server.read_integer(0, 2).value
print(list(values))

The arguments keep their .NET names (firstIndex, RobotControlGroup): pass them by position, or with these names.

Errors

An error raised by the SDK comes from the .NET runtime. Import the exception class from its .NET namespace, after the import of the package. Its members keep their .NET names: Message, Status, AddedStatus.

{
var robot = new YaskawaRobot();
try
{
robot.Connect("192.168.0.1");
robot.HighSpeedEServer.StartJob();
}
catch (InvalidLicenseException ex)
{
// No valid license: the trial is over, or the key is wrong
Console.WriteLine(ex.LicenseInfo);
}
catch (ConnectException ex)
{
// The UDP socket could not be opened
Console.WriteLine($"{ex.Address}: {ex.Message}");
}
catch (InvalidDataAnswerException ex)
{
// The controller refused the command, for example "Servo OFF" or "Command remote not set"
Console.WriteLine($"{ex.Message} ({ex.Status}, {ex.AddedStatus})");
}
catch (SocketException ex)
{
// No answer before the timeout
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
// For example, no answer to the ping
Console.WriteLine(ex.Message);
}
}
}
Click to see the full code

Differences with the .NET API

  • The static fields of the .NET types have the same name in Python: RobotControlGroup.DefaultRobotPulse, RobotSystemTypeData.Default, RobotPosture.Default.
  • The exceptions are the .NET exceptions (see above), not Python classes.

Version 2.2.0 of the package has these limits:

  • connect takes a ConnectParameters: robot.connect(ConnectParameters("192.168.0.1")).
  • When a .NET method has several overloads, Python has the one with the most parameters. read_io and write_io take an I/O type and a group (read_io(IOType.GeneralOutput, 1, 2)). get_position_error, get_torque, get_robot_position and get_configuration_information take a RobotControlGroup, for example RobotControlGroup.DefaultRobotPulse. get_system_information takes RobotSystemTypeData.Default.
  • To create a RobotControlGroup, use the ControlGroup enumeration of the .NET namespace: from UnderAutomation.Yaskawa.HighSpeedEServer import ControlGroup, after the import of the package.
  • load_file and get_file take no progress callback.
  • The SDK has no asynchronous methods and no events.

What to read next

  • Connect to your robot: the settings of the controller, the connection parameters, the errors.
  • High Speed Ethernet Server overview: the functions of the SDK, one page per topic. Every code sample has a Python tab.
  • Licensing: the 30 day trial and the license key.

Universal Robots、Fanuc、Yaskawa、ABB、Staubli ロボットを .NET、Python、LabVIEW、または Matlab アプリケーションに簡単に統合

UnderAutomation
お問い合わせLegal

© All rights reserved.