Custom C Code question: How do set extern variables from simulink model

I have a simple C code file that has four extern variables (three inputs, one output)
main.c:
#include <math.h>
#include "main.h"
extern float A1;
extern float A2;
extern float A3;
extern float OUTPUT;
void do_something(void) {
OUTPUT = cos(A1) * sin(A2) * cos(A3);
}
main.h:
void do_something(void);
I wish to add this C code to my stateflow model and output the variable OUTPUT
This is how I currently have my custom c code setting
The 'include directories' sections only has a '.' so that every file in included (currently only main.h). And the 'source file' section is empty
My models are setup like this
I can the following error:
Capture.PNG

댓글 수: 5

I can upload the model if that makes it easier
James Tursa
James Tursa 2019년 5월 13일
편집: James Tursa 2019년 5월 13일
I am not familiar with Stateflow, but as far as the C code is concerned, where are the variables A1, A2, A3, and OUTPUT defined? Are you sure you are including/linking the file(s) where they are actually defined?
This is the problem. I don't want to define these variables using another .c file. I want to set them using stateflow. I can't find a way to tell the C compiler this, so it thinks these variables are not defined, when I actually want them defined using the A1, A2 and A3 stateflow inputs.
James Tursa
James Tursa 2019년 5월 13일
편집: James Tursa 2019년 5월 13일
"I don't want to define these variables using another .c file"
But that is specifically what the extern keyword does ... it instructs the compiler that these variables are defined in another file. All variables in your code have to be defined somewhere. You might have Stateflow specific code for setting these variables to values, but the variables still must be defined somewhere.
Okay, thank you. I suppose I will have to find a work around.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Functions에 대해 자세히 알아보기

질문:

2019년 5월 13일

댓글:

2019년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by