Generate ROS cpp code from m file

12 Ansichten (letzte 30 Tage)
Tuan Hua
Tuan Hua am 5 Nov. 2018
Beantwortet: Cam Salzberger am 10 Dez. 2018
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 Kommentar
Ryan Livingston
Ryan Livingston am 5 Nov. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cam Salzberger
Cam Salzberger am 10 Dez. 2018
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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by