Skip to content
Sync a real Universal Robots robot with one in the V-REP robotics simulator.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

V-REP UR Connect

This Lua code is meant to synchronize the state of a Universal Robots UR3, UR5, or UR10 in the V-REP robot simulator with a real robot.

Given the IP address of the robot this code will load a control program onto the robot's control system and then accept a connection back from the robot which is subsequently used to stream joint targets to the robot and receive the joint states from the robot.

Inside V-REP the script should be called from a threaded child script, like so:

local ur_connect = require('ur_connect')

function sysCall_threadmain()
  -- The scene contains a UR5 robot model named 'UR5'
  local robot = ur_connect.Robot(sim.getObjectHandle('UR5'), theRobotsIPAddress)

  -- Connecting causes the script to load the control program onto the robot system and accept
  -- a connection back from the robot for control

  while sim.getSimulationState() ~= sim.simulation_advancing_abouttostop do
    -- Servoing updates the joint targets for the real robot, causing it to move
    -- This should ideally be called very quickly (>100 Hz) at regular intervals, and match the
    -- tuning parameters in the servoj call of the robot control script

  -- Cleans up the network resources


The ur_connect directory is the Lua module for connecting V-REP to a UR robot. Lua modules are installed in V-REP by putting them in the same directory as the main application binary. On macOS that's /Applications/V-REP_version_and_stuff/ Copy the ur_connect directory there.

The module uses the BitOp library so that will need to be installed too. Make sure to compile it for Lua 5.1 because that's the version of Lua used by V-REP. To compile BitOp do the following (on macOS):

  1. Install Homebrew.
  2. Install Lua 5.1 with brew install lua@5.1.
  3. Download and unzip.
  4. Compile with: a. gcc -I/usr/local/include/lua5.1 -dynamiclib -single_module -undefined dynamic_lookup -o bit.o bit.c b. gcc -shared -fPIC -I/usr/local/include/lua5.1 -llua5.1 -o bit.o
  5. Copy the resulting to the aforementioned V-REP directory.


Generate by running make docs. LDoc must be installed.

Run tests with make test.

You can’t perform that action at this time.