フィルターのクリア

Errors integrating Arduino C++ code into Simulink using S-Function Builder

63 ビュー (過去 30 日間)
Cameron Zorio
Cameron Zorio 2024 年 8 月 7 日 5:50
編集済み: Cameron Zorio 2024 年 8 月 15 日 3:59
Hi all,
I am currently attempting to integrate Arduino C++ code into my Simulink model using the S-Function builder. I am starting simple by essentially following this tutorial line for line to create a custom function that writes HIGH to a pin of choice on the Arduino board. I had a decent amount of success at first following the tutorial. I am able to compile functions written into C to Matlab executables, and even integrate them into my model to do things like basic things like double an input signal without any errors. However, I have issues as soon as I try to call functions from the standard Arduino library. Here is my header for the S-Function Builder:
/* Includes_BEGIN */
#include <math.h>
# ifndef MATLAB_MEX_FILE
# include <Arduino.h>
# endif
/* Includes_END */
Again, this is just following the guide I linked earlier. This S-Function also successfully builds and compiles into a Mex file, but when I try to run this model in Simulink using Monitor and Tune, I am slammed with dozens of error messages. Most the error messages however are basically identical, they either look like this:
C:/ProgramData/MATLAB/SupportPackages/R2023b/aIDE/hardware/arduino/avr/cores/arduino/Arduino.h:137:16: error: unknown type name 'uint8_t'; did you mean 'uint8_T'?
int analogRead(uint8_t pin);
^~~~~~~
uint8_T
Or like this:
C:/ProgramData/MATLAB/SupportPackages/R2023b/aIDE/hardware/arduino/avr/cores/arduino/Arduino.h:170:30: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'digital_pin_to_bit_mask_PGM'
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
^~~~~~~~~~~~~~~~~~~~~~~~~~~
At first I thought this was because I was trying to call C++ functions from a C source file. The workaround to this seems to be to rename the wrapper function file to have .cpp file extension, and insert 'extern "C"' before the two function declarations in the file. However after trying this fix, I just get this error message after running in Simulink:
Unable to find S-function module 'example_wrapper.c'. S-function modules must exist as either source files or pre-compiled object files on the MATLAB path.
This is an error I have not seen other users come into and I am a bit lost where to go from here. I have tried setting the target language to C++ in the S-Function builder instead of inherit from model, but when trying this am I hit with the dozens of same error messages as before. Is there a better way to integrate C++ and Arduino libraries into my model than the S-Function builder? Any help is much appreciated.
  2 件のコメント
Cameron Zorio
Cameron Zorio 2024 年 8 月 15 日 3:58
編集済み: Cameron Zorio 2024 年 8 月 15 日 3:59
Thank you for the response, yes I have already switched to using the System Object approach and have had much more success.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by