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 :
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 :
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 pack.so** shared library or get it [[https://www.ensta-bretagne.fr/zerr/filerepo/vrep/pack.so|already compiled here if you work on x86_64 linux computer. The file pack.so should be added in the main V-REP directory.