## Fail to publish to ROS from plugin

Report crashes, strange behaviour, or apparent bugs
Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

### Fail to publish to ROS from plugin

Hello,

I have been trying to publish a PointCloud2 message directly from a plugin, but I get this error when starting V-REP:
As for what I understand from the output of ldd, all my libraries are being loaded. After some trials, I found out that the problem was the line in which I published the message to ROS.

To make sure it wasn't a problem of my project, I used the "skeleton" plugin as a template and I wrote a simple example to force the same error. This time I was trying to publish just a std_msg::Float32 message and I got the same result.

Code: Select all

#include <ros/ros.h>
#include <std_msgs/Float32.h>

and edited the LUA_GETDATA_CALLBACK function to publish the data:

Code: Select all

  ros::NodeHandle n;
ros::Publisher pub;

std_msgs::Float32 output;
output.data = 1123; //just a random number
pub.publish (output); //this line makes the plugin to crash

(In my project I only create a node and a publisher when a new instance of the object is created, but I didn't want to create a new class to keep the code simple).

I leave a link the whole skeleton plugin showing the issue: https://www.dropbox.com/s/4fha13x7xgopw ... ar.gz?dl=0

Regards

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

### Re: Fail to publish to ROS from plugin

Hello again,

I think I am kind of mixing the behaviour of nodes and plugins... Nodes need to be initialized through ros::init() and communications must be handled by ros::spin() or ros::spinOnce() in the main() function. Since plugins don't have a main function, I am not sure I can just create a publisher and publish.

I thought we were not meant to use RosInterface plugin in plugins (since the RosInterface API only specifies LUA usage, but now I remembered that in this post it has been suggested to use the RosInterface plugin in another plugin, is this correct?

If so, then what library is needed to have access to the RosInterface API?

Regards

coppelia
Posts: 8206
Joined: 14 Dec 2012, 00:25

### Re: Fail to publish to ROS from plugin

Hello,

you are probably mixing up several things.
V-REP comes with 2 ROS plugins by default:
• the RosInterface: this interface is the newest and best interface. Use this one whenever possible. From this interface you interact with ROS via script commands (i.e. in Lua).
• the RosPlugin: this interface is an older interface. Avoid using this one. From this interface too, you interact with ROS via script commands (i.e. in Lua).
As you can see, both interfaces allow interaction with ROS only via scripting.This is of course the recommended way of doing since you gain extrem felxibility.

Now if you want to directly write ROS code in C/C++, then you need to create a V-REP plugin for that. You mention the skeleton plugin, which outlines what is needed. Can you compile that unmodified plugin?

Cheers

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

### Re: Fail to publish to ROS from plugin

Hello,

I have been using the RosInterface plugin to publish messages to ROS so far, but in order to speed up my simulation I wanted to directly publish to ROS from my plugin.

I have already successfully created some plugins in V-REP that retrieve some value to a child script. The unmodified skeleton plugin doesn't exactly compile, because my compiler doesn't recognize the _stricmp function (must have been created in visual studio, I think). I am not sure if it could just be replaced it with strcmp, in any case, I just removed those example message callbacks since they shouldn't affect to the plugin. I could correctly load it in V-REP, even though I didn't try it.

My question is: regarding RosInterface only allows interaction with ROS via scripting, how can I publish from my plugin using ROS code?

In the example I gave at the beginning I created a ros publisher, advertised the topic and tried to publish just like any other ROS node I have made.

The only difference is that plugins don't have a main function in which initialize the node and handle the ROS spin. I think the ROS spin could be handled in a message callback in each simulation step, for example, but do I have to initialize the node from my plugin? Furthermore, if I carry out all my interactions with ROS via a plugin, do I still need to load the RosInterface (or RosPlugin) plugin to create the V-REP node?

Regards

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

### Re: Fail to publish to ROS from plugin

Looking at the RosInterface plugin I've seen that it "tricks" the plugin to simulate a main function by creating a node this way:

Code: Select all

int argc = 0;
char *argv[] = {};
ros::init(argc, argv, "skeleton_node");
Still having the same error, tho.

fferri
Posts: 681
Joined: 09 Sep 2013, 19:28

### Re: Fail to publish to ROS from plugin

Code: Select all

ldd pluginName.so
Also tell us how do you start V-REP.

You should start V-REP in a terminal after loading the ROS initialization scripts, e.g.

Code: Select all

source /opt/ros/.../setup.bash

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

### Re: Fail to publish to ROS from plugin

Ok, I think there has been a misunderstanding. The skeleton plugin I mentioned is the v_repExtPluginSkeleton plugin (inside V-REP/programming). I used it as a template to try to publish a simple message to ROS.

But now, I have realised that there exists the vrep_plugin_skeleton plugin (inside V-REP/programming/ros_packages), which I think it's the one coppelia mentioned:
coppelia wrote:You mention the skeleton plugin, which outlines what is needed. Can you compile that unmodified plugin?
This plugin indeed outlines how to handle ros communication and I think this is the one I should have started with. I can successfully load this unmodified plugin and the node is correctly created.

Now I tried to use the ros_server_skeleton.h file in my plugin to handle the node initialization and publishers but I get the same error. As long as I include the .h file in my project, it fails. I have added the .h and .cpp to the makefile.

Can I be getting this dependencies error because I am not compiling the plugin as a ROS package (i.e: with catkin build)? I am writing and compiling the plugin with Qt Creator (without using the Qt framework) as I have been doing so far to write V-REP plugins that do not interact with ROS. All ros-related V-REP plugins I've seen are ros packages compiled with catkin build, is this mandatory is the plugin uses ros code?

Answering fferri, the output of "ldd libv_repExtPluginSkeleton.so" is:
linux-vdso.so.1 => (0x00007ffddb9af000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fee59bec000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fee599d5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fee59610000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fee5930a000)
/lib64/ld-linux-x86-64.so.2 (0x000055c1f225f000)
The way I sart V-REP is by executing:

Code: Select all

$cd V-REP_PRO_EDU_V3_3_1_64_Linux/$ ./vrep.sh

My ROS environment is works fine and script initialization is automatically done through the ~/.bashrc file.

This is my current skeleton plugin: https://www.dropbox.com/s/4fha13x7xgopw ... ar.gz?dl=0
It only attempts to initialize the ros node by calling the initialize() function in ros_server_skeleton.h during the start routine.

Regards,

fferri
Posts: 681
Joined: 09 Sep 2013, 19:28

### Re: Fail to publish to ROS from plugin

Billie1123 wrote: Now I tried to use the ros_server_skeleton.h file in my plugin to handle the node initialization and publishers but I get the same error. As long as I include the .h file in my project, it fails. I have added the .h and .cpp to the makefile.

Can I be getting this dependencies error because I am not compiling the plugin as a ROS package (i.e: with catkin build)? I am writing and compiling the plugin with Qt Creator (without using the Qt framework) as I have been doing so far to write V-REP plugins that do not interact with ROS. All ros-related V-REP plugins I've seen are ros packages compiled with catkin build, is this mandatory is the plugin uses ros code?
Yes. That's very likely.
ROS nodes, as well as the V-REP RosInterface plugin, must be compiled with catkin, because it does some more magic than just running cmake.
QtCreator also just calls cmake, so probably it is missing some of this magic too.

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

### Re: Fail to publish to ROS from plugin

Ok, I'll just convert the plugin to a ros package and compile it with catkin build to get the full magic :D

That will surely work. Thanks!

Regards

Billie1123
Posts: 62
Joined: 08 Jun 2016, 22:47

### Re: Fail to publish to ROS from plugin

There is still one thing I do not understand.
If two plugins create two different nodes, only one will be displayed. For example, take the RosPlugin (initializes the "vrep" node) and the RosInterface (initializes the "vrep_ros_interface" node) plugins. If both of them are loaded at the same time, only the "vrep" node will appear, and all subscribers and publishers created by RosInterface will appear to be handled by the "vrep" node.

I do not get why it seems like if the line:

Code: Select all

 ros::init(argc, argv, "vrep_ros_interface");

Is there some kind of remapping that I'm missing? If so, where?

Regards