How to Run a ROS2 Node Executable Generated by Coder?
32 views (last 30 days)
I have a simple function that publishes to a ROS2 topic and I need this publisher to run as a separate process outside of Matlab. Right now I also have a little function that subscribes to that topic to receive the messages to test if the publisher is running. I used Coder to 'build and run' the publisher per this tutorial. When I run my subscriber function, it received and plots the published data correctly confirming the process for the publisher is running.
My question is this: How do can I run the publisher executable without Matlab now that I have it built? After running codegen, I get the file structure shown in the attached image. I tried running the ros2publisherexample executable via the terminal as I have done in the past with coder generated executables by calling ros2publisherexample but I get the following output in the terminal window:
libc++abi: terminating with uncaught exception of type rclcpp::exceptions::RCLError: failed to initialize rcl init options: failed to find shared library 'rmw_fastrtps_cpp', at /System/Volumes/Data/mathworks/devel/bat/B3p2/build/3p/derived/maci64/ros2/src/ros2/rmw_implementation/rmw_implementation/src/functions.cpp:75, at /System/Volumes/Data/mathworks/devel/bat/B3p2/build/3p/derived/maci64/ros2/src/ros2/rcl/rcl/src/rcl/init_options.c:61
All of the examples I see on the Matlab documentation use 'build and run' in coder config (cfg.Hardware.BuildAction) and don't show how to run the exectuable as a standalone.
Jagadeesh Konakalla on 20 May 2022
Edited: Jagadeesh Konakalla on 20 May 2022
The short answer is that you cannot run executable as a standalone from the terminal. You always need a ROS environment ( kind of shell script that you usually run in ROS ) to run the ROS node. This environment is created and used by MATLAB when you created an executable with the Build and Run option and Deploy To is set to Locla Host.
Here is what you can try without MATLAB Installation
• Install ROS 2 Foxy on native mac machine
• Go to ROS2 colcon workspace
• Copy src folder generated from the MATLAB.
• Do colcon_make
• Then launch the node.
Hope this helps. Let me know if you have any questions.