Interpreter Mode lets you send URScript statements while your program is running. To do this, your robot program must call the blocking function interpreter_mode()
. While your robot program is in this mode, you can call any of the functions described below. For more information on Interpreter Mode for Universal Robots, please refer to the official documentation: https://www.universal-robots.com/articles/ur/programming/interpreter-mode
Once your robot program is in interpreter mode, you can play with the functions in robot.InterpreterMode
.
using UnderAutomation.UniversalRobots;class InterpreterMode{static void Main(){var robot = new UR();var param = new ConnectParameters("192.168.0.1");// Enable Interpreter Modeparam.InterpreterMode.Enable = true;// Connect to robotrobot.Connect(param);//...// append lines of URScript to execute. The robot program should execute interpreter_mode() to run this.robot.InterpreterMode.ExecuteCommand("movej([0.94, -1.3, 2.2, -2.6, -1, 4], a=1, v=1)");robot.InterpreterMode.ExecuteCommand("set_digital_out(1, True)");robot.InterpreterMode.ExecuteCommand("movej([0.94, -1.3, 2.2, -2.6, -1, 4], a=1, v=1)");// ...// Request the robot program to quit interpreter_mode() and continue the programrobot.InterpreterMode.EndInterpreter();// Disconnect from interpreter mode onlyrobot.InterpreterMode.Disconnect();}}
To enable interpreter mode, you must enable it in the connect parameters.
var param = new ConnectParameters("192.168.0.1");
// Enable Interpreter Mode
param.InterpreterMode.Enable = true;
Then, you can call ExecuteCommand()
method to append script to the robot internal buffer.
The method EndInterpreterMode()
allows to stop interpreter mode and force the robot to exit interpreter_mode()
and continue the program execution.
All script statements are stored in a buffer. You can empty this buffer with the method SkipBuffer()
.
Methods StateLastExecuted()
, StateLastInterpreted()
, StateLastCleared()
, StateLastUnexecuted()
returns informations about executing instructions.
public abstract class InterpreterModeClientBase : URServiceBase {// 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 ignoredpublic CommandResponse Abort()// 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.public CommandResponse ClearInterpreter()// Indicates that the interpreter mode client is connected and ready to send commandspublic bool Connected { get; }protected void ConnectInternal(string ip, int port)// Disconnect interpreter mode socket connectionpublic void Disconnect()// 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.public CommandResponse EndInterpreter()// Executes a command on the Interpreter Modepublic CommandResponse ExecuteCommand(string command)// IP of the robot to connect to for sending commandspublic string IP { get; }// Interpreter mode server portpublic int Port { get; set; }// 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 ignoredpublic CommandResponse SkipBuffer()// 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()public CommandResponse StateLastCleared()// Replies with the largest id of a statement that has started being executed.public CommandResponse StateLastExecuted()// Replies with the latest interpreted id, i.e. the highest number of interpreted statement so far.public CommandResponse StateLastInterpreted()// Replies with the number of non executed statements, i.e. the number of statements that would have be skipped if skipbuffer was called instead.public CommandResponse StateLastUnexecuted()}
public class CommandResponse {// Answer from the interpreter modepublic string Body { get; }// Command sent to the interpreter modepublic string Command { get; }// Command unique identifierpublic int Id { get; }// Raw line sent from the controllerpublic string RawAnswer { get; }// Response type to check if command succeedpublic CommandResponseStatus Status { get; }public override string ToString()}
public enum CommandResponseStatus {// The command compilation succeed and Interpreter mode will execute the statementAck = 0// Program is not running or the statement results in a compilation or linker errorDiscard = 1// Something went wrong when receiving responseError = -1// Answer from a state commandState = 2}
public abstract class InterpreterModeClientParametersBase {// Default Interpreter Mode server TCP portpublic const int DEFAULT_PORT = 30020// Interpreter Mode client TCP port. Default : 30020public int Port { get; set; }}
public class InterpreterModeConnectParameters : InterpreterModeClientParametersBase {// Enable Interpreter Mode client communication// Default value is falsepublic bool Enable { get; set; }}