UnderAutomation
有问题吗?

[email protected]

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

Interpreter Mode

Send URScript statements to a running UR program in interpreter_mode(), follow their execution, skip or clear the buffer, end the mode.

  • How it works
  • Prerequisites
  • Example
  • Commands
  • Try it in the demo application
  • Reference
  • What to read next

The Interpreter Mode of a Universal Robots cobot runs URScript statements sent by your application while a robot program is running. Unlike the URScript of the Primary Interface, it does not stop the program: the statements run in the program, and the program continues after them. This page shows how to send statements and follow their execution.

How it works

  1. The robot program calls the URScript function interpreter_mode(). The program waits there.
  2. The SDK sends statements. The robot adds them to a buffer and runs them in order.
  3. The SDK ends the interpreter mode: the robot program continues after interpreter_mode().

Interpreter mode in PolyScope

See Interpreter mode by Universal Robots, and the PolyScope versions that support it.

Prerequisites

  • The service Interpreter Mode Socket is enabled on the robot: see Prepare the robot.
  • A program that calls interpreter_mode() is running.

Example

Interpreter Mode is disabled by default: set InterpreterMode.Enable in ConnectParameters.

static void Main(string[] args)
{
var robot = new UR();
var parameters = new ConnectParameters("192.168.0.1");
// Interpreter Mode is disabled by default
parameters.InterpreterMode.Enable = true;
robot.Connect(parameters);
// The robot program must be in interpreter_mode()
CommandResponse response = robot.InterpreterMode.ExecuteCommand("movej([0.94, -1.31, 2.21, -2.65, -1.08, 4.81], a=1, v=0.5)");
if (response.Status != CommandResponseStatus.Ack)
Console.WriteLine(response.RawAnswer);
robot.InterpreterMode.ExecuteCommand("set_standard_digital_out(1, True)");
// Id of the last statement executed by the robot
CommandResponse lastExecuted = robot.InterpreterMode.StateLastExecuted();
// Remove the statements not executed yet
robot.InterpreterMode.SkipBuffer();
// Leave interpreter_mode(): the robot program continues
robot.InterpreterMode.EndInterpreter();
// Close Interpreter Mode only
robot.InterpreterMode.Disconnect();
}
}
Click to see the full code

Commands

MethodRole
ExecuteCommand(script)Add a statement to the buffer. Ack when the robot accepts it, Discard when it does not compile or no program runs
StateLastExecuted()Largest id of a statement that has started
StateLastInterpreted()Largest id of a statement interpreted
StateLastCleared()Id of the last statement cleared, by the end or by ClearInterpreter()
StateLastUnexecuted()Number of statements not executed yet
SkipBuffer()Skip the statements not executed yet, after the one that runs
ClearInterpreter()Clear the statements, functions and threads interpreted so far
Abort()Stop the movej or movel that runs, with a controlled stop
EndInterpreter()Leave interpreter_mode(): the robot program continues

Each method returns a CommandResponse: its Status, its Id and the raw answer of the robot.

The buffer of the robot has a limited size. For a long sequence, follow StateLastExecuted() and call ClearInterpreter() from time to time.

Try it in the demo application

Everything on this page can be tried without writing code, in the Interpreter mode page of the demo application.

Interpreter mode page of the Universal Robots SDK demo application

The demo application is open source. The C# source of this page is InterpreterModeControl.cs.

Reference

Class
InterpreterModeClientBaseinherits URServiceBase
C#Python

Base class for the Interpreter Mode client, providing TCP communication and built-in interpreter commands.

MemberTypeDescription
InterpreterModeClientBase()
Constructor
Connected
Property
read only
bool
Indicates that the interpreter mode client is connected and ready to send commands
IP
Property
read only
string
IP of the robot to connect to for sending commands
Port
Property
int
Interpreter mode server port
Abort()
Method
CommandResponse
The interpreter mode offers a mechanism to abort limited number of script functions, even if they are called from the main program. Currently only movej and movel can be aborted. Aborting a movement will result in a controlled stop if no blend radius is defined. If a blend radius is defined then a blend with the next movement will be initiated right away if not already in an initial blend, otherwise the command is ignored. Return value should be ignored
ClearInterpreter()
Method
CommandResponse
Clears all interpreted statements, objects, functions, threads, etc. generated in the current interpreter mode.Threads started in current interpreter session will be stopped, and deleted. Variables defined outside of the current interpreter mode will not be affected by a call to thisfunction. Only statements interpreted before the clear_interpreter() function will be cleared. Statements sent after clear_interpreter() will be queued. When cleaning is done, any statements queued are interpreted and responded to. Note that commands such as abort, skipbuffer and state commands are executed as soon as they are received.
ConnectInternal(string, int)
Method
void
Connects to the interpreter mode server at the specified IP and port.
  • ip : Robot IP address.
  • port : Interpreter mode port number.
Disconnect()
Method
void
Disconnect interpreter mode socket connection
EndInterpreter()
Method
CommandResponse
Ends the interpreter mode, and causes the interpreter_mode() function to return. This function can be compiled into the program by sending it to the interpreter socket(30020) as any other statement, or can be called from anywhere else in the program. By default everything interpreted will be cleared when ending, though the state of the robot, the modifications to local variables from the enclosing scope, and the global variables will remain affected by any changes made.The interpreter thread will be idle after this call.
ExecuteCommand(string)
Method
CommandResponse
Executes a command on the Interpreter Mode
  • command : URScript statement to execute
SkipBuffer()
Method
CommandResponse
The interpreter mode furthermore supports the opportunity to skip already sent but not executed statements.The interpreter thread will then(after finishing the currently executing statement) skip all received but not executed statements. After the skip, the interpreter thread will idle until new statements are received.skipbuffer will only skip already received statements, new statements can therefore be send right away. Return value should be ignored
StateLastCleared()
Method
CommandResponse
Replies with the id for the latest statement to be cleared from the interpreter mode. This clear can happen when ending interpreter mode, or by calls to clear_interpreter()
StateLastExecuted()
Method
CommandResponse
Replies with the largest id of a statement that has started being executed.
StateLastInterpreted()
Method
CommandResponse
Replies with the latest interpreted id, i.e. the highest number of interpreted statement so far.
StateLastUnexecuted()
Method
CommandResponse
Replies with the number of non executed statements, i.e. the number of statements that would have be skipped if skipbuffer was called instead.
Class
CommandResponse
C#Python

Response to an Interpreter Mode command

MemberTypeDescription
Body
Property
read only
string
Answer from the interpreter mode
Command
Property
read only
string
Command sent to the interpreter mode
Id
Property
read only
int
Command unique identifier
RawAnswer
Property
read only
string
Raw line sent from the controller
Status
Property
read only
CommandResponseStatus
Response type to check if command succeed
Equals(object)
Method
bool
GetHashCode()
Method
int
ToString()
Method
string
Enum
CommandResponseStatus
C#Python

Type of response of an Interpreter Mode command

NameValueDescription
Ack
0
The command compilation succeed and Interpreter mode will execute the statement
Discard
1
Program is not running or the statement results in a compilation or linker error
Error
-1
Something went wrong when receiving response
State
2
Answer from a state command
Class
InterpreterModeConnectParametersinherits InterpreterModeClientParametersBase
C#Python

Setup Interpreter Mode Client

MemberTypeDescription
Enable
Property
bool
Enable Interpreter Mode client communication Default value is false

What to read next

  • Send URScript: run URScript without a running program.
  • Move the robot from a PC: which way to choose for a move.

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

UnderAutomation
联系我们Legal

© All rights reserved.