UnderAutomation
質問ですか?

[email protected]

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

Move the robot from a PC

Move a UR cobot from a PC in C# or Python with URScript, the Interpreter Mode, registers or a program, and check the position reached.

  • Which way to choose
  • Prerequisites
  • Example
  • Units and format
  • End of the move
  • Compute a target
  • Troubleshooting
  • What to read next

This article shows how to move a Universal Robots cobot from a PC, in C# or Python: a linear move or a joint move to a target, then a check of the position reached. It compares the ways to send a move and says which one to choose.

Which way to choose

WayHowEffect on the running programWhen
URScript, Primary InterfaceScript.Send("movel(...)")It stops: the script runs insteadA move from the PC, no program on the robot
Interpreter ModeExecuteCommand("movel(...)") in a program in interpreter_mode()It continues after the movesMoves inside a program of the operator
Registers and a robot programRTDE writes the target in registers, the program reads them and movesIt runs the movesA fixed program that the PC drives
A .urp programSFTP, then Dashboard Server or REST LoadProgram, PlayIt is replacedMoves taught in PolyScope

For a quick test, URScript is the shortest way. For a cell in production, a program on the robot that reads its targets in registers keeps the control on the robot side, where the operator sees it.

Prerequisites

  • The robot is powered on, its brakes are released, and it is in remote control: see Run a program for the power on.
  • The Primary Interface is connected on port 30001 (the default).
  • The target is reachable and the path is free. Test with low speeds, and on URSim first.

Example

The program sends a linear move to a target, waits for its end, prints the distance to the target, then starts a joint move and stops it after 1 s.

using System.Globalization;
using UnderAutomation.UniversalRobots;
using UnderAutomation.UniversalRobots.Common;
class HowToMoveRobot
{
static void Main(string[] args)
{
var robot = new UR();
// Primary Interface and Dashboard Server
robot.Connect("192.168.0.1");
// Target of the tool: X, Y, Z in m, rotation vector in rad
var target = new Pose(0.4, -0.1, 0.3, 0, 3.14, 0);
// URScript numbers use a dot as decimal separator
string p = string.Format(CultureInfo.InvariantCulture,
"p[{0},{1},{2},{3},{4},{5}]", target.X, target.Y, target.Z, target.Rx, target.Ry, target.Rz);
// A linear move at 0.1 m/s. The script runs as a program:
// a program that runs on the robot stops
robot.PrimaryInterface.Script.Send($"movel({p}, a=0.5, v=0.1)");
// Wait for the start, then for the end of the move
WaitFor(() => robot.PrimaryInterface.RobotModeData.ProgramRunning, 2);
WaitFor(() => !robot.PrimaryInterface.RobotModeData.ProgramRunning, 60);
// Check the position reached
Pose reached = robot.PrimaryInterface.CartesianInfo.AsPose();
double error = Math.Sqrt(
Math.Pow(reached.X - target.X, 2) + Math.Pow(reached.Y - target.Y, 2) + Math.Pow(reached.Z - target.Z, 2));
Console.WriteLine($"Position error: {error * 1000:F1} mm");
// A move in the joint space, joint positions in rad
robot.PrimaryInterface.Script.Send("movej([0, -1.57, 1.57, -1.57, -1.57, 0], a=1.2, v=0.5)");
// To stop it before its end: a new script replaces the running one
Thread.Sleep(1000);
robot.PrimaryInterface.Script.Send("stopj(2)"); // 2 rad/s² deceleration
}
static void WaitFor(Func<bool> condition, int seconds)
{
var timeout = DateTime.Now.AddSeconds(seconds);
while (!condition())
{
if (DateTime.Now > timeout) throw new TimeoutException();
Thread.Sleep(50);
}
}
}

Units and format

The target of movel is a pose p[x, y, z, rx, ry, rz]: meters and a rotation vector in radians, in the base frame. movej takes 6 joint positions in radians. a is the acceleration (m/s² or rad/s²), v the speed (m/s or rad/s). Write the numbers with a dot: CultureInfo.InvariantCulture in C#.

End of the move

Script.Send returns when the script is sent: the robot does not answer. A script runs as a program, so RobotModeData.ProgramRunning is true during the move and false at its end.

Compute a target

To move to a pose given by a vision system in another format, convert it with Pose. To choose the joint positions of a pose, use the inverse kinematics.

Troubleshooting

  • Nothing moves: the robot is in local control, not powered, or its brakes are on. The script can also contain an error: listen to RuntimeExceptionMessageReceived.
  • The running program stops: expected with URScript sent by the Primary Interface. Use the Interpreter Mode to keep it.
  • Protective stop: the target is not reachable, or the robot hit something. See Read and reset alarms.

What to read next

  • Send URScript and Interpreter Mode.
  • Get the robot position.

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

UnderAutomation
お問い合わせLegal

© All rights reserved.