Integral in Simulink fcn Block

7 Ansichten (letzte 30 Tage)
Björn Meyer
Björn Meyer am 10 Nov. 2022
Kommentiert: Björn Meyer am 14 Nov. 2022
Hey,
frist: I'm pretty new to Matlab / Simulink. I'm wrote an algorithm to generate a trajectory in Matlab and wanted to integrate my working Matlab code into a Simulink Project by using a Fcn Block.
Within my algorithm I have to integrate a cos / sin function. My code looks like:
ds = .1;
length = 1;
phi = 0;
R=5.5;
A=sqrt(R*length);
i=1;
int_x1=@(l) cos((l.^2/(2*A.^2)) + phi);
int_y1=@(l) sin((l.^2/(2*A.^2)) + phi);
x=zeros(1,(length / ds)+1);
y=zeros(1,(length / ds)+1);
for l=0:ds:length
x(i)=integral(int_x1,0,l);
y(i)=integral(int_y1,0,l);
i=i+1;
end
This generates x and y coords in ds steps. It builds a Clothoid for a Radius of 5.5 within a length of 1.
My Problem with Simulink is, that the integral function does not work.
"Function 'integral' not supported for code generation."
In the next step I tried to fix this by the use of:
coder.extrinsic('integral');
which leads to:
"An error occurred while running the simulation and the simulation was terminated
Caused by:
  • First input argument must be a function handle. "
Is there any possibility to numerical solving of integrals within a function block?
  2 Kommentare
Jim Riggs
Jim Riggs am 10 Nov. 2022
I'm not sure what you are trying to do in Simulink. Can you post an image of your Simulink model, and specify exactly what code is in the Fcn block?
Björn Meyer
Björn Meyer am 10 Nov. 2022
Bearbeitet: Björn Meyer am 10 Nov. 2022
Unfortunately I can't post an image of the Model. In general my part is to create a parking in / out trajectory (x,y coordinates for example).
In the actual fcn I'm getting Inputs from my model like gps coordinates of the car and where to park in / out.
In Matlab it looks like this, the trajectory is starting at X1000.9363 Y1062.6396 in a parking spot and ending in X1009.6008 Y1051.8693 on the road.
What I'm calculating in the code snippet above is the first bluish line from the start.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 10 Nov. 2022
You need to understand the difference between MATLAB and Simulink.
This Simulink block diagram will give you the curve. Set the values of "A" and "phi" in base workspace.
  5 Kommentare
Björn Meyer
Björn Meyer am 11 Nov. 2022
Thank you for your answers.
I'm still not sure if my problem can be solved by this way. Let me give you a little bit more details on my project and problem.
Right now we have two Simulink Models.
One for "offline / off-car" simulation, to evaluate problems and test new functions. This model is fed with data from a measurement recorded in the vehicle. The Simulation time is fixed to for example 30s, depending on how long the measurement record was.
The other model is used to control a car. For this, the model is calculated in C code and passed to a dSpace autobox. The model is then executed on the autobox and fed with live data from the vehicle bus system. The incoming data is manipulated and sent back to the bus.
Back to my problem:
Is it possible to use the simulink integration independent from the simulation time?
note: If I'm building a Model like you said with the parameters: start time 0.0, stop time 1, fixed step, step size .1 I'm getting the same output as within my matlab algorithm. Meaning an Integral from 0 to 1 with a step size of 0.1 between data points. But I have no idea what to do if I cannot change the start time, stop time or even a step size.
Björn Meyer
Björn Meyer am 14 Nov. 2022
Added Information:
I cannot use the "interpreted MATLAB FCN" block, because it does not allow C-Code generation.
Do you have any other ideas how I could solve my problem?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by