Failed to create a ROS2 publisher

Hello everyone,
I am trying to follow this example to create custom ROS2 messages: openExample('ros/ROS2CustomMessagesExample')
I ran the code in steps and it is successfully able to create a custom message using the command ros2genmsg.
After this, when I run the part of the code to create a ROS2 publisher, it gives me an error as seen in the image below
I have installed python 3.7 and the cmake version is 3.10.2. Any help is appreciated. Thank you for your time.
Regards,
Abhishek

Answers (1)

Hi Abhishek,
You will not encounter this issue if use MATLAB R2020b or later. As a workaround, this can be resolved by specifying the LD_LIBRARY_PATH before creating the node:
setenv LD_LIBRARY_PATH <matlabroot>/extern/bin/glnxa64:<matlabroot>/sys/os/glnxa64
It should work fine after doing the above step and should be able to create publisher and subscriber. If you still see the same error, try doing this worksround:
Create a publisher on a default topic :
pub = ros2publisher(node,"/paramete_events")
Then create your publisher:
pub = ros2publisher(node,"/example_topic")
This should work, Hope this helps!
-Hari

6 Comments

Hello Hari,
Thank you for your response.
I am using custom messages and building them in Matlab using the toolbox - ROS Toolbox interface for ROS custom messages. This toolbox is not availiable in R2020b or later, so I am stuck with R2020a. (Please let me know if there is an alternative to this.)
The setenv method didn't work but the second one did.
I need to subscribe to a topic in simulink and I am getting the same error there. I have sucessfully built the custom messages in Matlab (autoware_auto_msgs) but when I build a ROS2 subscriber in simulink I am getting the same poco exception error as show in the image. Any workaround to solve this in Simulink?
Thank you for your time.
Regards,
Abhishek
Hello Abhishek,
Based on Hari's suggestion working for you, it is likely that there is another library on your path that is conflicting with MATLAB's ROS 2 libraries. This is the link to the bug report.
Hari's suggestion was to ensure that the libraries you are using are set to the head of the path (LD_LIBRARY_PATH on Linux), but if you are using custom messages, those libraries will be in a different location. The best solution in R2020a is probably to find the problematic libraries on your path and remove them before running any ROS 2 commands in Linux. Any ROS or ROS 2 "bin" or "lib" directories are the most likely culprit, but there are others.
However, to clarify your issue with R2020b, the custom message support package is no longer supported for R2020b because that functionality has been included with ROS Toolbox. Just like with "ros2genmsg", you do not need to install a support package to use "rosgenmsg" in R2020b+. You will, just like for ROS 2, need Python 2.7, CMake, and a compiler to generate the custom messages. Note that's Python 2.7 for ROS 1, and 3.7 for ROS 2. See the release notes for more information.
-Cam
I have these custom messages that I am using stored in a catkin_ws. The path for this msg folder is - /home/bhagwat/catkin_ws/src/autoware_auto_msgs/msg.
Can you tell me how I should set the LD_LIBRARY_PATH to point these messages? I have tried including this folder in the path but I think I am doing this in the wrong way.
Regards,
Abhishek Bhagwat
I believe that the issue is not that you don't have the custom message libraries on the path, it's that your path has other libraries on it that are conflicting with libraries that MATLAB's ROS is using. Start up a terminal outside of MATLAB, print your LD_LIBRARY_PATH, and see if there is any directory on it that looks potentially problematic. Then try setting LD_LIBRARY_PATH for that session to be nearly empty (just keep /usr/bin or the usual system binary directories) and start MATLAB from that terminal. Then the only libraries that should be on the path are MATLAB's and some basic system ones.
-Cam
Hello,
Thank you for replying. So I tried the following things and its still throwing the same error
  1. From Ubuntu terminal used - export LD_LIBRARY_PATH=/usr/bin to set the LD_LIBRARY_PATH to /usr/bin and then started MATLAB from the same terminal. Ran simulink it showed the same error.
  2. Also used setenv to set the LD_LIBRARY_PATH in MATLAB to /usr/bin.
  3. I was running MATLAB as root (sudo -i). Tried the non root way and my custom messages didn't appear in ros2 msg list (I had installed them starting Matlab as root). I installed them again properly and the simulink file still gave me the same error.
Is there any way I can schedule a zoom call to get this resolved. It would help me greatly.
Regards,
Abhishek Bhagwat
You are always welcome to contact Technical Support to get direct assistance. It can certainly help in instances where the issue seems to be specific to your system's setup.
-Cam

Sign in to comment.

Categories

Products

Release

R2020a

Asked:

on 16 Jan 2021

Commented:

on 12 Feb 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!