- Mastering ROS for Robotics Programming(Second Edition)
- Lentin Joseph Jonathan Cacace
- 857字
- 2025-02-17 19:11:08
Setting up V-REP with ROS
Before starting to work with V-REP, we need to install it in our system and compile the ROS packages needed to establish the communication bridge between ROS and the simulation scene. V-REP is a cross-platform software, available for different operating systems, such as Windows, macOS, and Linux. It is developed by Coppelia Robotics GmbH and is distributed with both free educational and commercial licenses. Download the last version of the V-REP simulator from the Coppelia Robotics download page: http://www.coppeliarobotics.com/downloads.html, choosing the Linux version of the V-REP PRO EDU software.
In this chapter, we will refer to the V-REP version v3.4.0. You can download this version, if already available on the website, using the following command in any desired directory:
$ wget http://coppeliarobotics.com/files/V-REP_PRO_EDU_V3_4_0_Linux.tar.gz
After completing the download, extract the archive:
$ tar -zxvf V-REP_PRO_EDU_V3_4_0_Linux.tar.gz
To easily access V-REP resources, it is convenient to set the VREP_ROOT environmental variable that points to the V-REP main folder:
$ echo "export VREP_ROOT=/path/to/v_rep/folder >> ~/.bashrc"
V-REP offers the following modes to control simulated robots from external applications:
- Remote API: The V-REP remote API is composed of several functions that can be called from external applications developed in C/C++, Python, Lua, or Matlab. The remote API interacts with V-REP over the network, using socket communication. You can integrate the remote API in your C++ or Python nodes, in order to connect ROS with the simulation scene. The list of all remote APIs available in V-REP can be found on the Coppelia Robotics website: http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctions.htm. To use the remote API, you must implement both client and server sides:
- V-REP Client: The client side resides in the external application. It can be implemented in a ROS node or in a standard program written in one of the supported programming languages.
- V-REP Server: This side is implemented in V-REP scripts and allows the simulator to receive external data to interact with the simulation scene.
- RosPlugin: The V-REP RosPlugin implements a high-level abstraction that directly connects the simulated object scene with the ROS communication system. Using this plugin, you can automatically apply subscribed messages and publish topics from scene objects to get information or control simulated robots.
- RosInterface: Introduced in the latest versions of V-REP, this interface will substitute the RosPlugin in the future versions. Differently from the RosPlugin, this module duplicates the C++ API functions to allow ROS and V-REP communication.
In this book, we will discuss how to interact with V-REP using the RosPlugin. The first thing to do is to compile the ROS communication bridge. We must add two packages to our ROS workspace: vrep_common and vrep_plugin. As usual, you can clone the entire package from the following GitHub repository or obtain the package from the book's source code:
$ git clone https://github.com/jocacace/vrep_common.git $ git clone https://github.com/jocacace/vrep_plugin.git
Compile the packages with the catkin_make command. If everything goes right, the compilation will create the vrep_plugin shared library: libv_repExtRos.so. This file is located in the devel/lib/directory in the ROS workspace. To enable V-REP to use this library, we need to copy it into the main vrep folder:
$ cp devel/lib/libv_repExtRos.so $VREP_ROOT
This library allows V-REP to connect with an active instance of roscore at startup, transforming it in a ROS node linked to the framework. So, to connect V-REP with ROS, an instance of roscore must be executed before launching V-REP. To test that everything is working properly, start roscore and launch the V-REP software:
$ roscore & $VREP_ROOT/vrep.sh
During the startup, all V-REP plugins installed in the system will be loaded. We can check if the vrep_plugin is loaded, as shown in the following figure:

In addition, after starting the V-REP program, a new topic is published containing information about the simulation status. Listing the active topics, we can check that the /vrep/info topic is published. As shown in the next figure, this message provides information about the state of the simulation, if it is running or not, and information about the simulation time:

To explore vrep_plugin functionalities, we can have a look at the plugin_publisher_subscriber.ttt scene, located in the vrep_demo_pkg/scene folder. To open this scene, use the main drop-down menu and select the entry: File | Open Scene. This simulation is based on the rosTopicPublisherAndSubscriber1.ttt scene proposed in older V-REP versions.
After opening this scene, the simulation windows should appear, as in the following image:

In this scene, a robot is equipped with two cameras: one active camera acquiring images from the environment, publishing the video stream on a specific topic, and a passive camera, that only acquires the video stream from the same topic. We can press the play button on the main bar of the V-REP interface.
After that the simulation starts; this is what will happen:

In this simulation, the passive camera displays the image published from the active one, receiving vision data directly from the ROS framework. We can also visualize the video stream published by V-REP using the image_view package:
$ rosrun image_view image_view image:=/camera/image_raw