I have Matlab code that includes a ROS2 node/publisher. I want to publish custom messages. This works when I run it natively in Matlab after running ros2genmsg. I now want to deploy me code to a remote Linux machine. This worked before I added the custom ROS2 message type, but now it appears that CMake can't find my custom message definitions (see below). How to do provide this to coder/CMake? The message output below suggests that I need to provide something to CMAKE_MODULE_PATH, should I do that as a environmental variable on my system like
$export CMAKE_MODULE_PATH="$CMAKE_MODULE_PATH:<path_to_my_custom_message_directory>"
or do I need to set it in MATLAB somehow?
Here are the commands I ran in the Matlab terminal to run coder.
(Note that I have omitted my IP, username and password. )
>> cfg = coder.config('exe');
cfg.Hardware = coder.hardware('Robot Operating System 2 (ROS 2)');
cfg.Hardware.BuildAction = 'Build and run';
cfg.Hardware.RemoteDeviceAddress = '[OMITTED]';
cfg.Hardware.RemoteDeviceUsername = '[OMITTED]';
cfg.Hardware.RemoteDevicePassword = '[OMITTED]';
cfg.Hardware.DeployTo = 'Remote Device';
cfg.Hardware.ROS2Folder = '/opt/ros/galactic';
cfg.Hardware.ROS2Workspace = '~/detector_ws2';
cfg.HardwareImplementation.ProdHWDeviceType = 'Intel->x86-64 (Linux 64)';
codegen detectstreaming -args {} -config cfg
Here is the result
Connecting to ROS 2 device at '134.114.64.127'.
Using ROS 2 workspace '~/detector_ws2' to build ROS 2 node.
---
Transferring generated code for 'detectstreaming' to ROS device.
Starting build for ROS node.
---
ROS 2 project directory: /home/dasl/detector_ws2/src
Starting >>> detectstreaming
--- stderr: detectstreaming
CMake Error at CMakeLists.txt:19 (find_package):
By not providing "Finduavrt_interfaces.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"uavrt_interfaces", but CMake did not find one.
Could not find a package configuration file provided by "uavrt_interfaces"
with any of the following names:
uavrt_interfacesConfig.cmake
uavrt_interfaces-config.cmake
Add the installation prefix of "uavrt_interfaces" to CMAKE_PREFIX_PATH or
set "uavrt_interfaces_DIR" to a directory containing one of the above
files. If "uavrt_interfaces" provides a separate development package or
SDK, be sure it has been installed.
make: *** [Makefile:959: cmake_check_build_system] Error 1
---
Failed <<< detectstreaming [0.83s, exited with code 2]
Summary: 0 packages finished [1.12s]
1 package failed: detectstreaming
1 package had stderr output: detectstreaming
??? The following error occurred during deployment to your hardware board:
Build unsuccessful for model 'detectstreaming'. Check the build log in the diagnostics viewer
for error messages.
Code generation failed: View Error Report

 채택된 답변

Jagadeesh Konakalla
Jagadeesh Konakalla 2022년 6월 24일

0 개 추천

Hi Michael,
You have build the custom messages using ros2genmsg are visible only by MATLAB on your host machine. You need to build custom messages uavrt_interfaces in ~/detector_ws2.
You can follow the following tutorial to create custom messages in ROS2.
Once you build the custom messages on target machine, you can try the above procedure. It should work.
This limitation is captured in the following page under limitations section.
Thanks,
Jagadeesh K

댓글 수: 8

Michael
Michael 2022년 6월 24일
Thanks a lot. Yesterday I was able to get the custom messages working as a package with my detector_ws2 workspace. I understand now that I have to generate the messages as a separate package within the workspace. Then when I run colcon build, it builds that custom message package along with my package associated the code that does all my computation.
For debugging purposes though I am also trying to get custom messages built on the Linux machine using ros2genmsg. Running the custom messages as a standalone node and within Matlab is helpful for my debugging. When I run ros2genmsg I get the following (see below). I originally had Python3.8 installed on this machine, but saw somewhere that 3.9 was required for ros2genmsg. Here is what get when I run the command.
>> ros2genmsg('~/uavrt_src/uavrt_interfaces')
Identifying message files in folder '/home/dasl/uavrt_src/uavrt_interfaces'..Done.
Adding required Python packages to virtual environment..Done.
Error using ros.ros2.internal.createOrGetLocalPython
chmod: cannot access
'/home/dasl/.matlab/R2022a/ros2/glnxa64/venv/bin/activate': No such file or
directory
Error in ros2genmsg (line 84)
ros.ros2.internal.createOrGetLocalPython(); %ensure python is available
Also, as you can see my Matlab Python Environment is set to 3.9.
PythonEnvironment with properties:
Version: "3.9"
Executable: "/usr/bin/python3"
Library: ""
Home: "/usr"
Status: NotLoaded
ExecutionMode: InProcess
I can see that there is no library listed, which doesn't seem good. I set this using >>pyenv('Version','/usr/bin/python3') and I got that executable path by checking it in Python3.9:
dasl@dasl-Precision-T5610:~$ python3
Python 3.9.13 (main, May 23 2022, 22:01:06)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/usr/bin/python3'
Any idea how to overcome this error so that I can use ros2genmsg on my Linux machine? FYI, this work well on my Mac.
Thanks,
Michael
Hi Michael,
Yes, it is not good that lib is not listed in Pyenv output.
Can you try to run the following command to create the virtual environement ? Then try the ros2genmsg.
ros.ros2.internal.createOrGetLocalPython(true)
If the above is not working, can you please reinstall the Python 3.9 and do pyenv and recreate the virtual environemnt before running ros2genmsg.
Let me know if these works or not.
Jagadeesh K.
Michael
Michael 2022년 6월 27일
편집: Michael 2022년 6월 27일
I ran >> ros.ros2.internal.createOrGetLocalPython(true) but got the result:
Removing previous version of Python virtual environment..Done.
Creating a Python virtual environment..Done.
Error using ros.ros2.internal.createOrGetLocalPython
Could not create Python virtual environment: The virtual environment was not created
successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt install python3.8-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/dasl/.matlab/R2022a/ros2/glnxa64/venv/bin/python3.8', '-Im',
'ensurepip', '--upgrade', '--default-pip']
. Verify there is sufficient space on disk and retry the command.
Per the error message I ran $sudo apt install python3.8-venv in terminal. I then rand the createOrGetLocalPython(true) again and got the following:
>> ros.ros2.internal.createOrGetLocalPython(true)
Removing previous version of Python virtual environment..Done.
Creating a Python virtual environment...Done.
Adding required Python packages to virtual environment....Done.
Error using ros.ros2.internal.createOrGetLocalPython
Could not install the required Python packages. System error message: Looking in links:
/home/dasl/Documents/MATLAB/sys/ros2/share/python
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/argcomplete-1.12.3-py2.py3-none-any.whl
Processing /home/dasl/Documents/MATLAB/sys/ros2/share/python/flake8-3.9.2-py2.py3-none-any.whl
Processing /home/dasl/Documents/MATLAB/sys/ros2/share/python/flake8-blind-except-0.2.0.tar.gz
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/flake8_class_newline-1.6.0-py3-none-any.whl
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/flake8_comprehensions-3.5.0-py3-none-any.whl
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/flake8_docstrings-1.6.0-py2.py3-none-any.whl
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/flake8_import_order-0.18.1-py2.py3-none-any.whl
Processing /home/dasl/Documents/MATLAB/sys/ros2/share/python/flake8-quotes-3.2.0.tar.gz
Processing /home/dasl/Documents/MATLAB/sys/ros2/share/python/pytest-6.2.4-py3-none-any.whl
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/pytest_cov-2.12.1-py2.py3-none-any.whl
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/pytest_repeat-0.9.1-py2.py3-none-any.whl
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/pytest_rerunfailures-9.1.1-py3-none-any.whl
Processing
/home/dasl/Documents/MATLAB/sys/ros2/share/python/colcon_common_extensions-0.2.1-py3-none-any.whl
Processing /home/dasl/Documents/MATLAB/sys/ros2/share/python/lark-parser-0.11.3.tar.gz [31mERROR: Could not find a version that satisfies the requirement numpy (from versions:none) [0m [31mERROR: No matching distribution found for numpy [0m
. Use pyenv function to set the path to the Python executable and retry the command.
I can try reinstalling Python 3.9 next. On my original install I had followed these instructions (https://phoenixnap.com/kb/upgrade-python) that include steps (6-9) to change the symlinks from 3.8 to 3.9. I originally did those steps but then changed them back to 3.8 because I am doing other work on this machine that requires 3.8. I am not sure that would cause any issues within Matlab but thought I'd mention it. Do these instructions (steps 1-3) look sufficient for the install for Matlab? Is there more I should do? I can do the reinstall as soon as I hear back from you.
Thanks.
Michael
Michael 2022년 6월 27일
I noticed when I ran >> pyenv('Version',/usr/bin/python3.8) the library path was listed as "libpython3.8.so.1.0" (see below). I thought that I'd could try to manually set the path after running pyenv('Version','/usr/bin/python3.9') but when I did a search for libpython3.9.so.1.0 on me system, it came up empty.
>> pyenv('Version','/usr/bin/python3.9')
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/usr/bin/python3.9"
Library: ""
Home: "/usr"
Status: NotLoaded
ExecutionMode: InProcess
>> pyenv('Version','/usr/bin/python3.8')
ans =
PythonEnvironment with properties:
Version: "3.8"
Executable: "/usr/bin/python3.8"
Library: "libpython3.8.so.1.0"
Home: "/usr"
Status: NotLoaded
ExecutionMode: InProcess
Hi Michale,
Here are system requirements for ROS Toolbox. The version R2022a requires 3.9 version of Python. Let us not use Python 3.8. The R2022a ROS toolbox tested with Python 3.9 version.
Can you please try reinstalling Python 39 on your machine ?
Hi Michael,
Can you try installing python 3.9 as follows on your linux machine:
>> sudo apt install python3.9 python3.9-venv python3.9-dev
In MATLAB command windows, set the Pyenv to /usr/bin/python3.9 in MATLAB. You can see that Library is detected now.
Now in you run the following command before running the ros2genmsg.
>> ros.ros2.internal.createOrGetLocalPython(true)
>> ros2genmsg(gendir)
Let me know if it works for you or not.
Thanks,
Jagadeesh K.
Michael
Michael 2022년 6월 28일
That did it. @Jagadeesh Konakalla tell your boss I said you deserve a pay raise. Without your help on this and other issues you've helped me with I'd never have been able to overcome these ROS2/Coder nuances. Thank you so much!
Can you comment on how issues like this get bubbled up to the folks at Mathworks that do documentation? It seems like if a regular install of Python3.9 is insufficient, then it should be documented. Did I miss it somewhere?
Again, that you so much!
Hi Michael,
I happy to know that your problem is resolved.
The challenge here is that ROS is open source. The backend of ROS Toolbox uses the ROS API's. As per my understanding, the ROS 2 is maturing. We have seen different kind of install/setup issues with different OS platforms such as windows/mac/linux platforms. It is challening for us to test on different variants and versions of linux distributions.
But, I agree that in this case, documentation can capture the required python package installation steps.I will pass this information to my developement team. You should see the updated documentation for the future releases of MATLAB.
Thanks,
Jagadeesh K

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Nupur
Nupur 2023년 11월 22일

0 개 추천

Hello @Jagadeesh Konakalla @Michael I am trying to subscribe from Matlab to the topic which is inside the container. The topic has 'ackermann_msgs/AckermannDrive' message type.
I installed this ros2 message type on my host PC and gave the path through ros2genmsg inside the Matlab. I then try to subscribe to the topic from container however, it is not subscribing to the topic.
I did check the 'ros2 topic list' on my host terminal and i could see my topic there but not in matlab.
I am new to this feild, please help me out if I am missing here something.
Host Machine: Ubuntu 22.04
Matlab/Simulink 2022b: Host Machine (Subscriber node)
ROS2 : Container (Publisher node)

댓글 수: 2

Hi Nupur,
Can you please ensure that ROS_DOMAIN_ID environement variable is same on Docker container and Host mahcine MATLAB ?
Thanks,
Jagadeesh K.
Nupur
Nupur 2023년 11월 24일
Hello Jagadeesh,
Yes i made sure that the ROS_DOMAIN_ID is same however, Matlab not been able to see the topic. In my host terminal i can see my topic from container.
I also did try to communicate from my Host terminal to the Matlab and it does work but with the container, matlab is not been able to see the topic.
Please guide me through this.
Thank you.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with ROS Toolbox에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 6월 23일

댓글:

2023년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by