Simulink: type consistency errors - matlab

Using this Simulink model file as a reference, I'm trying to figure out the two following errors:
alt text http://imagebin.ca/img/dSV8YO.png
alt text http://imagebin.ca/img/OXDf0v.png
I have no idea what has gone wrong with the data type consistency/conversion problems. Do you know what the error messages mean exactly in the context of a model? It would be great to get an interpretation of the problem to solve it. Thanks in advance.

Is the block 'Inner Loop/e^(-s)' driving the block 'Inner Loop/Sum'? It looks like the 'e^(-s)' block is trying to set the Sum block to be double, but the Sum block is already set to some other data type. I'm not sure why that's happening, but here's a snippet from the help for the Sum block documentation,
Inherit: Inherit via internal rule
Simulink chooses a combination of output scaling and data type that requires the smallest amount of memory consistent with accommodating the calculated output range and maintaining the output precision of the block and with the word size of the targeted hardware implementation specified for the model. If the Device type parameter on the Hardware Implementation configuration parameters pane is set to ASIC/FPGA, Simulink software chooses the output data type without regard to hardware constraints. Otherwise, Simulink software chooses the smallest available hardware data type capable of meeting the range and precision constraints. For example, if the block multiplies an input of type int8 by a gain of int16 and ASIC/FPGA is specified as the targeted hardware type, the output data type is sfix24. If Unspecified (assume 32-bit Generic), i.e., a generic 32-bit microprocessor, is specified as the target hardware, the output data type is int32. If none of the word lengths provided by the target microprocessor can accommodate the output range, Simulink software displays an error message in the Simulation Diagnostics Viewer.
You can try forcing the output data type to be double, if that's what you really want, or you can try putting a Data Type Conversion block in front of the Sum block. One other thing that can help is to try turning on Port Data Types from the Format menu. It should show you all the propagated data types when the error happens.

Related

How to optimize a parameter in simulink using genetic algorithm (GA)?

I have a simulink model of a control system where a output is being constantly compared with the setpoint and error is being set to the controller. I use a matlab file to call this model and send disturbance. I want to optimize a parameter that affects the value of the controller gains on the basis of the error (i.e., to reduce error). How to use GA to call this simulink file and set parameter at each iteration.
I took help from this link: "https://in.mathworks.com/matlabcentral/answers/343672-how-could-i-connect-simulink-model-to-the-genetic-algorithm-toolbox"
but it is showing error:
"Exiting due to infeasibility: 1 lower range(s) exceeds the corresponding upper range."
I have exactly the same problem, but in your case, the error that appears is referred to problems of value of the design variables that exceed the upper/lower boundary level defined in the genetic algorithm.

Simulink: individual signal output from bus input (based on signal name)

I have a complex Simulink model and want to generate in a subsystem one simple error message signal out of a lot of incoming error observing signals.
These incoming signals are organised in a bus and are always 0, exept when an error occurs: then there is an edge to value.
The error message should contain an individual bit code which is defined for every error name and error value in an excel list.
How can I assign this error code to a specific error signal with rising edge? I need something like a lookup function:
for (every signal):
if signal has edge to value,
look in list to signal name
and output its error code.
My idea was to use a MATLAB function block with a bus input and a one-dimensional output. A .mat file generated before Simulation start contains a struct with the list inputs from the excel file and should be used as a parameter in the MATLAB function.
This solution seems a bit difficult though, since dynamic field referencing and interating through a structure is not supported for code generation. I cannot even get the signal name from the struct because the fieldnames function is not supported, too.
I am now wondering if there is another approach or the MATLAB function is still doable for my problem. Can I generate the code for the MATLAB function block in a PreLoadfcn? Does a S-function make sense here? Or is there even a Simulink based solution which does the Signal conversion?

Dynamically sized bus objects in Simulink

I wrote a C S function which has a variable number of states depending on one parameter, which is passed to it (I'm using computational fluid dynamics and the parameter is the number of cells). I want to output a bus object from my S function that contains a temperature profile. Problem is I don't know the length of the output when I create the bus object in Simulink (in Bus Editor). Is there a way to dynamically set the size of the bus object from the C S function?
I think you can set the DimensionsMode property to "variable" instead of "fixed" (the default). See Simulink.BusElement and Variable-Size Signal Basics in the documentation for more details. Not sure how to code this in the S-function though.

Serial communication with simulink

I'm trying to send and receive data through a serial port using simulink (matlab 7.1) and d-space. The values I want to send and receive are doubles. Unfortunately for me the send and receive blocks use uint8 values. My question is how can I convert doubles into an array of uint8 values and vice versa? Are there simulink blocks for this or should I use embedded matlab functions?
Use the aptly named Data Type Conversion block, which does just that.
EDIT following discussion in the comments
Regarding scaling, here's a snapshot of something I did a long time ago. It's using CAN rather than serial, but the principle is the same. Here, it's slightly easier in that the signals are always positive, so I don't have to worry about scaling a negative number. 65535 is the max value for a uint16, and I would do the reverse scaling on the receiving end. When converting to uint16 (or uint8 as in your case, it automatically rounds the value, and you can specify that behaviour in the block mask).
There are pack and unpack blocks in simulink, search for them in simulink library browser. You could need som additional product, not sure which.

PID filter coefficient output minimum, maximum and parameter attributes

I am trying to find more information on making a custom PID block in MATLAB. I have most of it done but there are a few parameters that I don't really understand and as such I don't know what value to give them. NOTE I am NOT asking for help tuning PID gains.
They are all inside the filter coefficient block:
When I open the block I have to set a few parameters (output min/max, data type, parameter min/max, etc.). Can someone explain to me what these mean? I can't find good resources anywhere. The only thing that I've tried which works is setting each to [] (i.e. -inf) and the input/output data types to 'Inherit: Inherit via internal rule' but then my output goes to hell. If I copy paste the blocks from the PID block there are a bunch of variables which I haven't defined anywhere so the program won't even compile.
Can someone point out some good resources for this or else explain it? Thanks!
You should get your blocks from the standard Simulink library, not from under the PID block mask. The ones under the mask have been set-up to use variables that are passed from/through the mask, which you are not doing.
The block you have circled is just a gain block (from the Math library).
You most likely won't need to make any changes to the default settings of the block other than the constant value (which needs to be the N that you want to use in the approximation of the derivative term in your controller).
To answer your specific question about what the parameters are, some of them are used to specify data types (if you don't want to use the default double precision), some are only used in code generation, some others only for other specific tasks.
All of them are described (in more, or sometimes less, detail) in the doc for the block, obtained by pressing the help button on the block's dialog.