Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling Functions in an Embedded Matlab Function in Simulink

611 views
Skip to first unread message

Brendan

unread,
Jul 9, 2008, 2:32:01 AM7/9/08
to
I have created a Simulink model to test a Kalman filter
that I designed and to replicate real data input, I am
using an embedded Matlab file that calls a function within
this file called "myWait". I placed this function at the
end of my embedded Matlab file and it does not seem to have
any problems calling this function, but within this
function, it makes use of predefined
functions "timer", "start" and "wait". When I try to build
the model I get the following errors:

Undefined function or variable 'start'.
Function 'Real Time States' (#127.903.911), line 34, column
5:
"start(t)"

Undefined function or variable 'wait'.
Function 'Real Time States' (#127.917.924), line 35, column
5:
"wait(t)"

Function call failed.
Function 'Real Time States' (#127.494.512), line 14, column
5:
"myWait(GPS_Period)"

Undefined function or variable 'start'.
Function 'Real Time States' (#127.903.911), line 34, column
5:
"start(t)"

Undefined function or variable 'wait'.
Function 'Real Time States' (#127.917.924), line 35, column
5:
"wait(t)"

Function call failed.
Function 'Real Time States' (#127.608.626), line 20, column
5:
"myWait(IMU_Period)"

Errors occurred during parsing of Embedded MATLAB
function 'Real Time States'(#127)

Function 'timer' implicitly resolved in the MATLAB
workspace.
This feature is deprecated.
Please declare this function extrinsic using eml.extrinsic
('timer'), or call it using feval.
Function 'Real Time States' (#127.848.897), line 33, column
7:
"timer('timerfcn','myWait(0)','StartDelay',DeltaT)"

Function 'timer' implicitly resolved in the MATLAB
workspace.
This feature is deprecated.
Please declare this function extrinsic using eml.extrinsic
('timer'), or call it using feval.
Function 'Real Time States' (#127.848.897), line 33, column
7:
"timer('timerfcn','myWait(0)','StartDelay',DeltaT)"

Here is the code from my Embedded Matlab file:

function
[E_GPS,N_GPS,heading_IMU,speed_Hall,speed_GPS,Time_GPS,Time_
IMU] = RealTimeStates(E,N,heading,speed)
%% Adjust state values so they are input at same
frequencies as real system

% Initialise GPS,IMU and Hall-Effect Sensor timestamps
Time_GPS = 0;
Time_IMU = 0;

% Define GPS, IMU and Hall-Effect Sensor periods for data
input
GPS_Period = 0.1; % 10Hz
IMU_Period = 0.02; % Approx 50Hz

% Update GPS time stamp at 10 Hz
for i = 1:100
myWait(GPS_Period)
Time_GPS = Time_GPS + 1;
end

% Update IMU time stamp at 50 Hz
for i = 1:10/IMU_Period
myWait(IMU_Period)
Time_IMU = Time_IMU + 1;
end

E_GPS = E;
N_GPS = N;
heading_IMU = heading;
speed_Hall = speed;
speed_GPS = speed;

% Waits for the specified number of seconds
function myWait(DeltaT)
if(DeltaT>0) %end condition
t=timer('timerfcn','myWait(0)','StartDelay',DeltaT);
start(t);
wait(t);
end

Any ideas?

Brendan

unread,
Jul 10, 2008, 8:49:01 PM7/10/08
to
Can anyone help? It would be very appreciated.

"Brendan " <cheese...@hotmail.com> wrote in message
<g51m11$8bn$1...@fred.mathworks.com>...

Michael Hosea

unread,
Jul 14, 2008, 11:31:46 AM7/14/08
to
The TIMER object is not supported in Embedded MATLAB, so the constructor
function call is treated here as "extrinsic". What that means is that,
instead of generating C code for the whole thing and compiling it, the C
code that Embedded MATLAB generates will contain a mex call into MATLAB to
execute "timer('timerfcn',...)". We don't support START and WAIT, either,
and so I am not sure why these did not resolve to extrinsic calls in the
same manner here, but it probably doesn't matter because this approach is
doomed. While it is true that Embedded MATLAB-generated C code can call
into MATLAB as extrinsic (mex) calls, it is impossible for the timer object
in MATLAB to call your MyWait callback in Embedded MATLAB-generated C code,
at least in this context.

I'd try making myWait extrinsic. Just declare it

eml.extrinsic('myWait');

at the top of RealTimeStats, and move the definition of myWait into a
myWait.m in the same directory as the model or somewhere else on the MATLAB
path. That way, Embedded MATLAB will just make a mex call into MATLAB to
call myWait, supplying the deltaT parameter.
--
Mike

"Brendan " <cheese...@hotmail.com> wrote in message

news:g56alt$2c2$1...@fred.mathworks.com...

0 new messages