s-function

Waiting time in S-function

≡放荡痞女 提交于 2019-12-25 02:35:31
问题 I am trying to create a flashing procedure in Simulink using a S-function (C language) and I need to send some frames and the time between 2 consecutive frames should be lets say 200 milisconds. How can I implement this waiting time? Is there any possibility of implementing it? 回答1: If you want to update something every 200ms, put your S-Function into a subsystem which is triggered every 200s. 回答2: Below you can find the steps that I followed in the function: 1.create first frame 2.send first

Calling fmincon from Simulink

有些话、适合烂在心里 提交于 2019-12-24 09:25:41
问题 I am trying to implement a particular type of model predictive control in the Simulink-Matlab framework. To do so, my plan was to have the dynamic model in Simulink call an external Matlab S-function which in turns runs an optimization that calls a different Simulink file. Hence, the program flow would be as follows: Simulink -> Matlab ( fmincon or quadprog ) -> Simulink. As you can see, the Matlab S-function would call either fmincon or quadprog , but I would like to use fmincon for my

Share data between multiple c mex s-functions

对着背影说爱祢 提交于 2019-12-13 20:30:42
问题 I am implementing several c s-functions. They have to rely on the same pointers and variables, inedependet of the current s-function. Basically I want to instantiate all variabels and pointers in one "setup" s-function (inside mdlInitialize) and then be able to use these variables an pointers in different s-functions in their mdlOutputs function. Every s-function will be written in c. I could not find any usefull hint in the mathworks help. Do you have any idea? Thanks. 回答1: There are several

Some help writing a s-function to read data from serial port

主宰稳场 提交于 2019-12-11 19:09:40
问题 After problems I had here, I need some help to write a function with MATLAB Function block. I saw in following links that some people solved it with that block or s-function: http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/317910 http://www.physicsforums.com/showthread.php?t=595813 http://www.mathworks.de/matlabcentral/newsreader/view_thread/250266 So I tried with this: function y = fcn(u) coder.extrinsic('only3') coder.extrinsic('serial', 'fopen','fread') coder.extrinsic('set

Multi-Instance usage of S-Functions (C code) in SIMULINK

孤街浪徒 提交于 2019-12-11 09:57:33
问题 I have a legacy C function in my SIMULINK model that uses some static variables in its functions. The static variables are available globally. When I reference multiple instance of my model, I get error because my S-function is not configured for that. I am getting this error message because code generation doesn't allow this. The error message I get is the following: The S-Function block 'ECDCTRL/PULDESC/S-Function Builder' is not supported in multi-instance Normal mode because it does not

Memory block alternative that ISN'T fixed in minor time step?

爷,独闯天下 提交于 2019-12-11 04:08:21
问题 I have a model with some inputs that are fed into a CMEX S-Function via the Memory block, and the S-Function provides outputs based on these inputs, and those inputs are fed back into the S-Function. Classic algebraic loop scenario. I was using a memory block to prevent this because our solver is usually variable-time step According to the Mathworks documentation the Memory Block, and the Unit Delay block also, are fixed in minor time step in terms of their outputs. I realize that the inputs