Simulink/ Real Time

Legacy support with Phidget21
dylan.thorpe

Simulink/ Real Time

Postby dylan.thorpe » Sun Oct 11, 2009 9:31 pm

Hello,

I'm working on using Phidgets to drive an experimental winching devise for a research project and I'm aiming at using Matlab/ Simulink to drive this system. So far I have successfully setup matlab scripts to open the phidgets and a simulink model to read and drive the phidgets using embedded matlab and "extrinsic" function calls to use matlab to access the phidgets.

The problem I face is I would like to impliment the system in real time and this requires the use of real time workshop for Simulink which does not allow external matlab function calls. So I believe the solution is to write a C-mex S-function to call the C routines directly. Has anyone done this before? I have tried searching the internet for information with no luck. I have little experience writing S-functions but am learning. So far I'm stuck trying to compile the c-mex file with the phidget21.h header that does nothing but pass the input through to the output. I get a long list of "error-unrecognized declaration" starting at line 168 of the header file.

Edit "In particular the mex compiler doesn't like '__declspec (dllimport)', this I guess is the first problem to overcome."

Further edit: "After doing some more investigation I believe the compiler is the problem. The default one used by the matlab function mex is Lcc -win 32. They also support Open Watcom C/C++, all the other supported compilers are beyond my means. Is there a work around to use the Lcc -win32 compiler with the existing C code? Would I have more success setting up Open Watcom and using that?"

Thanks for any help.

dylan.thorpe

Re: Simulink/ Real Time

Postby dylan.thorpe » Thu Oct 29, 2009 1:39 am

Hello again,

Having spoken to a couple of guys from MathWorks today it would appear that to use the Phidgets with Simulink's Real Time Workshop I would need the source code for the libraries as the toolbox is designed specifically to compile code for embedded systems. Is it possible to get the source code, I seem to remember reading no but maybe in the interests of research an exception can be made. Otherwise I think I will have to work with Matlab Scripts for a much less elegant solution.

I have managed to test my system with a Matlab Script and record some data which matched within about 10% the simulated response which I think is pretty good, considering the error sources.

Thanks

User avatar
Patrick
Lead Developer
Posts: 3078
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Simulink/ Real Time

Postby Patrick » Thu Oct 29, 2009 9:57 am

What OS are you using? The sourcecode is available for Linux in the downloads page. We can probably provide you with Windows sourcecode if that's what you're looking for (as a Visual Studio project) - PM me.

-Patrick

dylan.thorpe

Re: Simulink/ Real Time

Postby dylan.thorpe » Wed Feb 03, 2010 9:29 pm

I never got back to this. I abandoned trying to use genuine realtime with Matlab/ Simulink due to it being a much greater undertaking than I at first appreciated. I got around the problem instead by using approximate real time which should suffice for what I'm doing.

Basically I'm calling matlab functions 'tic' 'toc' from simulink to grab the time and then tuning my simulation step size to get the simulation time close to real time. Rough I know but the main thing for me is to have some kind of time scale against the recorded data. Given the noise in all the other measurements I think it's close enough.

Hope this helps anyone else trying to impliment simulink based control with phidgets.


Return to “Matlab”

Who is online

Users browsing this forum: No registered users and 1 guest