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.
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.
| Item | Supported |
|---|---|
| Python | 3.7 to 3.13 |
| pythonnet | 3.0.5, installed with the package |
| Operating system | Windows, Linux, macOS |
| Controllers | YRC1000 (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.
sudo apt-get install -y dotnet-runtime-8.0export 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 loadload("coreclr")from underautomation.yaskawa.yaskawa_robot import YaskawaRobot
Install from PyPI
Install the package in a virtual environment:
python -m venv .venv# Windows.venv\Scripts\activate# Linux and macOSsource .venv/bin/activatepip install UnderAutomation.Yaskawa
Package page: pypi.org/project/UnderAutomation.Yaskawa
Install from the sources
git clone https://github.com/underautomation/Yaskawa.py.gitcd Yaskawa.pypip 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 YaskawaRobotfrom 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 objectrobot = YaskawaRobot()robot.connect(ConnectParameters("192.168.0.1"))# Read the position of the tool center point, in mm and degreesp = 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()
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:
| .NET | Python |
|---|---|
robot.HighSpeedEServer.GetStatusInformation() | robot.high_speed_e_server.get_status_information() |
parameters.HighSpeedEServer.DataPort | parameters.high_speed_e_server.data_port |
YaskawaRobot.RegisterLicense(...) | YaskawaRobot.register_license(...) |
position.X, status.ServoOn | position.x, status.servo_on |
Read16BytesChar(0, 2) | read16_bytes_char(0, 2) |
OnOffCommandType.Servo | OnOffCommandType.Servo |
SwitchingCommands.Continue | SwitchingCommands.Continue_ |
short[], int[] returned | a .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 casefrom underautomation.yaskawa.yaskawa_robot import YaskawaRobotfrom underautomation.yaskawa.connect_parameters import ConnectParametersfrom underautomation.yaskawa.common.io_type import IOTypefrom underautomation.yaskawa.high_speed_e_server.on_off_command_type import OnOffCommandTypefrom underautomation.yaskawa.high_speed_e_server.robot_control_group import RobotControlGrouprobot = YaskawaRobot()robot.connect(ConnectParameters("192.168.0.1"))# A .NET array parameter accepts a Python listrobot.high_speed_e_server.write_integer(0, [10, 20])# Pass the arguments by position: their names keep the .NET spellingvalues = robot.high_speed_e_server.read_integer(0, 2).valueprint(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 wrongConsole.WriteLine(ex.LicenseInfo);}catch (ConnectException ex){// The UDP socket could not be openedConsole.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 timeoutConsole.WriteLine(ex.Message);}catch (Exception ex){// For example, no answer to the pingConsole.WriteLine(ex.Message);}}}
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:
connecttakes aConnectParameters:robot.connect(ConnectParameters("192.168.0.1")).- When a .NET method has several overloads, Python has the one with the most parameters.
read_ioandwrite_iotake an I/O type and a group (read_io(IOType.GeneralOutput, 1, 2)).get_position_error,get_torque,get_robot_positionandget_configuration_informationtake aRobotControlGroup, for exampleRobotControlGroup.DefaultRobotPulse.get_system_informationtakesRobotSystemTypeData.Default. - To create a
RobotControlGroup, use theControlGroupenumeration of the .NET namespace:from UnderAutomation.Yaskawa.HighSpeedEServer import ControlGroup, after the import of the package. load_fileandget_filetake 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.