Compatibility ros2node with Coder Generation

According to the ros2node documentation, the function supports code generation with a one node per function limitation. When I try to generate code with a ros2node.m call I get an error
'The 'ros2node' class does not support code generation.'
See the image attached. I have reduced the function to the following.
function [] = detectsteaming()
node_1 = ros2node("node_1");
end
Does anyone know what might be going on?
I have checked and my Matlab version is R2021a, which I think should support this but I could be wrong. Where can one find out when particular functions gained Code Generation support? Maybe the code generation support was released in an R2022 release?
Thanks.

1 件のコメント

Michael
Michael 2022 年 5 月 17 日
On checking my documentation for R2021a, I don't see Code Generation support for this function. I am going to install R2022a right now and see if this fixes the problem.

サインインしてコメントする。

 採用された回答

Josh Chen
Josh Chen 2022 年 5 月 17 日

0 投票

Hello Michael,
You are right. Code generation support for 'ros2node' starts at R2021b.
You should be able to use this feature after updating to R2021b or R2022a.
Besides specific documentation page for functions, another place to look at new features is the release page: https://www.mathworks.com/help/ros/release-notes.html
The release page is a good place to check when certain feature starts support.
Hope this helps,
Josh

6 件のコメント

Michael
Michael 2022 年 5 月 18 日
編集済み: Michael 2022 年 5 月 18 日
This was the case. I was able to install R2022a and I no longer get that error. I am however now getting the error:
The library 'ROS 2 Node' is not supported by the current target, language or compiler.
I have attached a screen shot of the place I am stuck. I am guessing that this error is because the ros2node function needs to be compiled for C++ for code generation and it is currently compiling to C. I can't for the life of me figure out how to change this from C to C++ though. I tried following these instructions, but it appears as though this is how you change to difference C++ compilers, not how to change to C++ code generation from the default C.
Thanks in advance.
FYI: I am on macOS if it matters. I am also doing this from the Coder App, not from the command line.
Michael
Michael 2022 年 5 月 18 日
Also, I should mention that I know how to change the language in the next step of the process with the little drop-down menu. I am at the 'Check for Issues' stage. I looked through the Settings and didn't see anyway to change to C++.
Michael
Michael 2022 年 5 月 18 日
I dug a little deeper in the Coder App settings and found 'Language' under the 'Advanced' Setting. I thought that switching this to C++ would solve the problem, but it did not.
Josh Chen
Josh Chen 2022 年 5 月 18 日
Hi Michael,
Since ROS and ROS 2 are considered as special types of "hardware boards", corresponding setup need to be done to make sure it generates correct code. If you are using MATLAB Coder App, you are likely to face other new warnings/errors even after changing to C++.
The command line option, on the other hand, does all those settings for you. You may want to take a look at this example about using command line to generate code with ROS Toolbox. Since you are using ROS 2 instead of ROS, you would need to use the ROS 2 hardwareboard instead of ROS though.
If you have to use MATLAB Coder App for some reason, it would be more effeicient to reach out to MathWorks Technical Support and walk through the process step by step.
Thanks,
Josh
Michael
Michael 2022 年 5 月 19 日
@Josh Chen Thanks for all the help on this. I was able to generate & run code using the commandline interface.
Josh Chen
Josh Chen 2022 年 5 月 19 日
Awesome! Glad to see it works! Thanks for the update @Michael

サインインしてコメントする。

その他の回答 (1 件)

Michael
Michael 2022 年 5 月 20 日

1 投票

FYI for anyone in the future: A quick way to see how to use command line code generation if you are used to using the Coder App is to select 'Convert to script...' option from within the coder app. This generate a Matlab script with the correct configuration structure and arguments you defined within the app. This is a super useful tool for learning how to use the commande line code generation.

カテゴリ

ヘルプ センター および File ExchangePublishers and Subscribers についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 5 月 17 日

回答済み:

2022 年 5 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by