MATLAB: How to overwrite doubles with singles with Real-Time Workshop

simulink coder

I have a requirement to build a model to work on a processor using only single float data types.
I have achieved most of this through using data replacement in the RTW options:
ReducedDouble_T = Simulink.AliasType;
ReducedDouble_T.HeaderFile = 'AtSourceLib.h';
In AtSourceLib.h:
typedef float ReducedDouble_T;
However, this causes problems when using RTW solvers:
static void rt_ertODEUpdateContinuousStates(RTWSolverInfo *si )
{
time_T t = rtsiGetT(si);
time_T tnew = rtsiGetSolverStopTime(si);
time_T h = rtsiGetStepSize(si);
ReducedDouble_T *x = rtsiGetContStates(si); // This is a real_T pointer
ODE3_IntgData *id = (ODE3_IntgData *)rtsiGetSolverData(si);
ReducedDouble_T *y = id->y;
ReducedDouble_T *f0 = id->f[0];
ReducedDouble_T *f1 = id->f[1];
ReducedDouble_T *f2 = id->f[2];
ReducedDouble_T hB[3];
int_T i;
int_T nXc = 1;
rtsiSetSimTimeStep(si,MINOR_TIME_STEP);
/* Save the state values at time t in y, we'll use x as ynew. */
(void) memcpy(y,x,
nXc*sizeof(ReducedDouble_T)); // Only copying half the data

Best Answer

Because Simulink does not support the integration of non-double types, it cannot remap RTWSolverInfo. However, you can change the types used by rtw_solver.h. You can copy it from $MATLABROOT\simulink\include to the build directory, where
$MATLABROOT is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB Command Prompt.