Generate ROS cpp code from m file

조회 수: 13 (최근 30일)
Tuan Hua
Tuan Hua 2018년 11월 5일
답변: Cam Salzberger 2018년 12월 10일
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