Generate ROS cpp code from m file

14 次查看(过去 30 天)
Tuan Hua
Tuan Hua 2018-11-5
Hi everybody, I am trying to generate ROS cpp code for testing my controller on ROS-Gazebo simulation. I used "codegen" command to generate some C code files and built them with cpp files successfully. Unfortunately, when I ran the simulation, nothing worked. Could you please give me some advice for this situation? I attached m-files with this post, "controller.m" is the outer file which calls "Fuzzy.m" and "MRAC.m". Thank you.
  1 个评论
Ryan Livingston
Ryan Livingston 2018-11-5
Can you elaborate on what you mean by "nothing worked"? Are there runtime errors? Is the behavior unexpected?
Some things to check:
  1. Generate a MEX file and run that. Do you get runtime errors? If so, those need to be addressed.
  2. Generate standalone code and enable the setting RuntimeChecks. Do you get errors running that?
  3. Are you calling the generated _initialize function prior to calling your generated code? If not, take a look at the code in codegen\lib\examples\main.c. The main function there is meant to be an example of how to invoke the generated code including calling the _initialize function.

请先登录,再进行评论。

回答(1 个)

Cam Salzberger
Cam Salzberger 2018-12-10
Hello Tuan,
I'm afraid that C/C++ code generation for ROS-related functionality is not supported with MATLAB Coder. See this page for a list of Robotics System Toolbox functionality supported by MATLAB Coder. Also, please note that you can generate ROS-compatible C++ code from Simulink models using Simulink Coder.
Nothing I saw in your three files actually relates to ROS, as far as I could tell though. I am assuming that you have other M-files that you are using for the ROS code. Otherwise, I would suggeset checking the applicable toolbox's pages for codegen-capability, or the MATLAB Coder supported functions list to make sure everything is compatible.
-Cam

类别

Help CenterFile Exchange 中查找有关 Code Generation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by