Call mex function in simulink/ s-function ?

조회 수: 8 (최근 30일)
Hocine YAKOUBI
Hocine YAKOUBI 2018년 1월 25일
댓글: Pierre LEPERCQ 2018년 5월 4일
Hello,
I have a SBG system (inertial navigation system) that we can not use with Matlab.
I created a mexw64 file that allows me to acquire the data of the sbg in real time. To do this I call the Function: [id, temps, ekf, imu, gyro, temp]=ellipseClientSMMatlab in Matlab, tell now everything is working.
I want to use those streaming data id, temps, ekf, imu, gyro, temp in Simulink, how can I do that? I tried to use S_Function Builder, in the Library I put my mex file: ellipseClientSMMatlab.mexw64, and I put in the outputs id, temps, ekf, imu, gyro, temp. I build, No error and I have three files, ellipseClientSMMatla.c, ellipseClientSMMatla_wrapper.c, ellipseClientSMMatlab.tlc.
I excute that in Simulink, but nothing in the outputs id, temps, ekf, imu, gyro, temp. In Matlab when I try to call my function, [id, temps, ekf, imu, gyro, temp]=ellipseClientSMMatlab. It gives me error. “MEX level2 S-function "ellipseClientSMMatlab" must be called with at least 4 right hand arguments”
Can someone help ? thank you so much PS : Sorry for my english dont write well.

답변 (1개)

Nick Sarnie
Nick Sarnie 2018년 2월 1일
Hi Hocine,
It sounds like you used MATLAB Coder to generate a MEX for the MATLAB Function. If you want to use it in an S-Function, I recommend creating a DLL with MATLAB Coder instead. To do this, you can use the "-config:dll" option to the "codegen" command. Lets use an example MATLAB function named 'dlldemo', which takes two double input arguments:
>> codegen -config:dll dlldemo.m -args {1,2}
From here, you can go into the codegen/dll/dlldemo folder and copy the dlldemo.lib and dlldemo.dll file to your Simulink model directory.
Finally, add 'dlldemo.lib' and 'dlldemo.dll' to the Library tab of S-Function Builder under 'Library/Object/Source files', and call 'dlldemo' in the S-Function code.
  댓글 수: 3
yakoubi Hocine
yakoubi Hocine 2018년 2월 4일
편집: yakoubi Hocine 2018년 2월 4일
Hi Nick, Thank you again for your help.
I have the solution for my proble.
I used Matlab Function Block and coder.extrinsic('ellipseClientSMMatlab') to resolve the problem.
This is the all program :
function [id, ekf,temps,imu, gyro, temp]=sbg
id=[0];
temps=[0];
ekf=[0,0,0];
imu=[0,0,0];
gyro=[0,0,0];
temp=[0];
coder.extrinsic('ellipseClientSMMatlab');
[id, temps, ekf, imu, gyro, temp]=ellipseClientSMMatlab;
end
It's working. Thank you
Pierre LEPERCQ
Pierre LEPERCQ 2018년 5월 4일
Hey Hocine!
I have a problem to get data from my SBG captor in Simulink. It looks like you found a solution to get them in real time... Can you tell me how have you done to create your ellipseClientSMMatlab.mexw64 and what you wrote in?
It would hep me a lot
Thanks!
PS : Sorry for my english, is not well too ^^'

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

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by