User Tools

Site Tools


vrep:socket-com-with-robot

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")

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

vrep/socket-com-with-robot.1584451418.txt.gz · Last modified: 2020/03/17 14:23 by admin