Skip to content

Instantly share code, notes, and snippets.

@johnwason
Last active September 3, 2025 05:40
Show Gist options
  • Select an option

  • Save johnwason/769b2216c531a34b631b9722567e3210 to your computer and use it in GitHub Desktop.

Select an option

Save johnwason/769b2216c531a34b631b9722567e3210 to your computer and use it in GitHub Desktop.
Robot Raconteur training simulator demo instructions

Robot Raconteur training simulator demo instructions

The Robot Raconteur training simulator demonstrates multiple robots and other devices running in simulation using standard, vendor-agnostic service types. The demo will also show using the teach pendant with these standard types to interact and program the robots.

See the full examples and the Getting Started Guide for more information.

Setup

The following demo files are for Python and MATLAB. Download the files before connecting to the private device access point!

Python

Download and install Python. If using Linux, install python3-pip.

Install the robotraconteur package:

python -m pip install robotraconteur

MATLAB

Install the "Robot Raconteur" add-on using the Add-on Explorer on the toolbar.

Connect to the access point

Connect to the "rr-simulator" access point using the instructions on the sign.

Run the examples!

Run the example scripts. These examples use a fixed IP address to connect, but you can also use Discovery or the Service Browser to find the connection information. (Windows firewall by default will block discovery. Disable the firewall or add an exception.)

% Example controlling standard robot using jog mode
% URL for connecting to the robot. By default connects to UR5e simulated robot.
url = 'rr+tcp://10.42.0.1:52511?service=robot';
% Connect to the robot driver
c = RobotRaconteur.ConnectService(url);
% Retrieve the current robot state and print the current command mode
robot_state = c.robot_state.PeekInValue();
disp(robot_state.command_mode);
% Change the robot command mode, first to halt, then to jog
c.command_mode = int32(0);
pause(0.1)
c.command_mode = int32(1);
% Get the starting joint positions
robot_state = c.robot_state.PeekInValue();
start_joint_pos = robot_state.joint_position;
start_time = tic;
% Move the robot in a loop
for i=1:100
t = toc(start_time);
% Generate a sin wave
c.jog_freespace(0.2 * [1, 0, 0, 0, 0, 0]' * sin(t / 5) + start_joint_pos, ones(6,1), true);
% Print the current robot_state_flags
robot_state = c.robot_state.PeekInValue();
disp(robot_state.robot_state_flags);
% Wait for the next loop iteration
pause(0.1);
end
% Disconnect the client. Client connections will be closed on Matlab exit
% but will not be automatically closed otherwise.
RobotRaconteur.DisconnectService(c);
##
# Command the robot using the jog_freespace function
#
from RobotRaconteur.Client import *
import time
import numpy as np
import sys
# URL for connecting to the robot. By default connects to UR5e simulated robot.
url = 'rr+tcp://10.42.0.1:52511?service=robot'
# Connect to the robot driver
c = RRN.ConnectService(url)
# Retrieve the current robot state and print the current command mode
print(c.robot_state.PeekInValue()[0].command_mode)
# Retrieve the constants for the com.robotraconteur.robotics.robot service definition
robot_const = RRN.GetConstants("com.robotraconteur.robotics.robot", c)
# Retrieve the "halt" and "jog" enum values
halt_mode = robot_const["RobotCommandMode"]["halt"]
jog_mode = robot_const["RobotCommandMode"]["jog"]
# Change the robot command mode, first to halt, then to jog
c.command_mode = halt_mode
time.sleep(0.1)
c.command_mode = jog_mode
# Get the starting joint positions
robot_state = c.robot_state.PeekInValue()[0]
start_joint_pos = robot_state.joint_position
t_start = time.time()
# Move the robot in an endless loop
while (True):
t = time.time() - t_start
# Generate a sin wave
c.jog_freespace(0.2 * np.array([1, 0, 0, 0, 0, 0]) * np.sin(t / 5) + start_joint_pos, np.ones((6,)), True)
# Print the current robot_state_flags
print(hex(c.robot_state.PeekInValue()[0].robot_state_flags))
# Wait for the next loop iteration
time.sleep(0.1)
% Example controlling standard robot using trajectory mode
robot_type = 'ur'; % Change to abb for ABB robot joint position
% URL for connecting to the robot. By default connects to UR5e simulated robot.
url = 'rr+tcp://10.42.0.1:52511?service=robot';
% Connect to the robot driver
c = RobotRaconteur.ConnectService(url);
% Get the robot_info data from the driver
robot_info = c.robot_info;
% Get the joint names from the robot_info data structure
joint_names = {};
for i=1:size(robot_info.joint_info)
joint_names{end+1,1} = robot_info.joint_info{i}.joint_identifier.name;
end
% Retrieve the current robot state and print the current command mode
robot_state = c.robot_state.PeekInValue();
disp(robot_state.command_mode);
% Change the robot command mode, first to halt, then to jog
c.command_mode = int32(0);
pause(0.1)
c.command_mode = int32(2);
% Get the starting joint positions
robot_state = c.robot_state.PeekInValue();
j_start = robot_state.joint_position;
% Build up JointTrajectoryWaypoint(s) to move the robot to specified joint angles
waypoints = {};
if strcmp(robot_type, 'abb')
j_end = [0, -0.1, 0.25, 0, 0, 0]';
elseif strcmp(robot_type, 'ur')
j_end = [0, -1, -1.5, 0, 0, 0]';
else
error('Invalid robot type');
end
for i=0:250
wp=struct;
wp.joint_position = (j_end - j_start) * (i / 250.0) + j_start;
wp.joint_velocity = [];
wp.position_tolerance = [];
wp.velocity_tolerance = [];
wp.interpolation_mode = int32(0);
wp.waypoint_type = int32(0);
wp.time_from_start = i / 25.0;
waypoints{end+1,1} = wp;
end
% Fill in the JointTrajectory structure
traj=RobotRaconteur.CreateStructure(c, 'com.robotraconteur.robotics.trajectory.JointTrajectory');
traj.joint_names = joint_names;
traj.waypoints = waypoints;
c.speed_ratio = 1.0;
% Execute the trajectory function to get the generator object
traj_gen = c.execute_trajectory(traj);
% Loop to monitor the motion
while true
try_next_res = traj_gen.TryNext();
res = try_next_res{1};
trajectory_status = try_next_res{2};
if ~res
break
end
robot_state = c.robot_state.PeekInValue();
disp(robot_state.robot_state_flags);
end
RobotRaconteur.DisconnectService(c);
from RobotRaconteur.Client import *
import time
import numpy as np
import sys
# URL for connecting to the robot. By default connects to UR5e simulated robot.
url = 'rr+tcp://10.42.0.1:52511?service=robot'
# Connect to the robot
c = RRN.ConnectService(url)
# Get the robot_info data from the driver
robot_info = c.robot_info
# Get the joint names from the robot_info data structure
joint_names = [j.joint_identifier.name for j in robot_info.joint_info]
# Retrieve the current robot state and print the current command mode
print(c.robot_state.PeekInValue()[0].command_mode)
# Retrieve the constants for the com.robotraconteur.robotics.robot service definition
robot_const = RRN.GetConstants("com.robotraconteur.robotics.robot", c)
# Retrieve the "halt" and "trajectory" enum values
halt_mode = robot_const["RobotCommandMode"]["halt"]
trajectory_mode = robot_const["RobotCommandMode"]["trajectory"]
# Retreive the structure type to create JointTrajectory and JointTrajectoryWaypoint objects
JointTrajectoryWaypoint = RRN.GetStructureType("com.robotraconteur.robotics.trajectory.JointTrajectoryWaypoint", c)
JointTrajectory = RRN.GetStructureType("com.robotraconteur.robotics.trajectory.JointTrajectory", c)
# Change the robot command mode, first to halt, then to trajectory mode
c.command_mode = halt_mode
time.sleep(0.1)
c.command_mode = trajectory_mode
# Connect to the robot_state wire to get real-time streaming state data
state_w = c.robot_state.Connect()
# Wait for the state_w wire to receive valid data
state_w.WaitInValueValid()
state1 = state_w.InValue
# Build up JointTrajectoryWaypoint(s) to move the robot to specified joint angles
waypoints = []
j_start = state1.joint_position
if sys.argv[1] == 'abb':
j_end = [0, -0.1, 0.25, 0, 0, 0]
elif sys.argv[1] == 'ur':
j_end = [0, -1, -1.5, 0, 0, 0]
else:
raise ValueError('Invalid robot type')
for i in range(251):
wp = JointTrajectoryWaypoint()
wp.joint_position = (j_end - j_start) * (float(i) / 250.0) + j_start
wp.time_from_start = i / 25.0
waypoints.append(wp)
# Fill in the JointTrajectory structure
traj = JointTrajectory()
traj.joint_names = joint_names
traj.waypoints = waypoints
c.speed_ratio = 1
# Execute the trajectory function to get the generator object
traj_gen = c.execute_trajectory(traj)
# Loop to monitor the motion
while (True):
t = time.time()
# Check the state
robot_state = state_w.InValue
res, gen_state = traj_gen.TryNext()
if not res:
# Break if the trajectory is complete
break
print(gen_state)
print(hex(c.robot_state.PeekInValue()[0].robot_state_flags))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment