User Tools

Site Tools


This is an old revision of the document!

Th socket communication allows for an external program to control the robot inside V-REP. The external program is a Python script. We will use for the socket a server/client communication. The server is written in Lua inside a threaded script in V-REP. The client is written in Python, It will :

  • connect to the server
  • send commands to the robot
  • read data from the robot (sensors, status, …)
  • disconnect from the server

On the server side of the socket, we use a threaded script in Lua as we want to listen to the client's commands synchronously with the V-REP simulation loop.

We will use a simple 3 wheels robot and we load it in V-REP.

The first thing to do is to add a threaded script to a object. We can choose to add it to the MainBody object but it can be any other object in the scene :

Right-Clic on the small icon on the left of MainBody and select Add→Associated child script→Threaded. After this a blue icon showing a text file should appear on the right of MainBody :

To edit, double-clic on this icon. You can edit directely in the V-REP script window. However, if you prefer using you preferred editor, you can remove all the Lua text code in the script and just type one line :

require ("simple_control_bot")

Then you will have to create a file called simple_robot_control.lua in the directory where your scene file (here myLittleBot.ttt) is stored.

The Lua code looks like this :


The socket transfer binary data, so we need to pack the data before sending them and unpack them at the reception. For Lua we use the lpack libary]. You can either download the code and recompile **the** shared library or get it [[|already compiled here if you work on x86_64 linux computer. The file should be added in the main V-REP directory.

vrep/socket-com-with-robot.1584455120.txt.gz · Last modified: 2020/03/17 15:25 by admin