37 #ifndef HYB_MODEL_SOURCE 49 #define HYB_MODEL_SOURCE "model.c" 51 #include HYB_MODEL_SOURCE 70 #define MATLAB_SYSTEM_IDENTIFICATION 74 #define inline __inline 91 mexErrMsgIdAndTxt(
"LIBHYBRID:Model:MallocError",
92 "Allocation error in the discretization");
95 mexErrMsgIdAndTxt(
"LIBHYBRID:Model:NullPointer",
96 "Null pointer passed to the integrator");
99 mexErrMsgIdAndTxt(
"LIBHYBRID:Model:tLimit",
100 "Reached time horizon for hybrid model");
103 mexErrMsgIdAndTxt(
"LIBHYBRID:Model:jLimit",
104 "Reached jump horizon for hybrid model");
107 mexErrMsgIdAndTxt(
"LIBHYBRID:Model:InvalidSet",
108 "Invalid set conditions provided");
111 mexErrMsgIdAndTxt(
"LIBHYBRID:Model:GenericError",
112 "An unknown error was raised");
130 int nrhs,
const mxArray *prhs[]) {
132 double *x, *u, **p, *xp, *y, *sim_time;
137 mexErrMsgIdAndTxt(
"LIBHYBRID:Model:InvalidSyntax",
138 "At least 4 inputs expected (t, u, x, p).");
144 nx = mxGetNumberOfElements(prhs[1]);
145 nu = mxGetNumberOfElements(prhs[2]);
147 if (nx != options.x_size) {
148 mexErrMsgIdAndTxt(
"LIBHYBRID:Model:InvalidSyntax",
149 "The dimension of input 2 should be %d", options.x_size);
153 sim_time = mxGetPr(prhs[0]);
154 x = mxGetPr(prhs[1]);
155 u = mxGetPr(prhs[2]);
157 p = mxCalloc(np,
sizeof(
double*));
158 for (i = 0; i < np; i++)
159 p[i] = mxGetPr(prhs[3+i]);
162 plhs[0] = mxCreateDoubleMatrix(nx, 1, mxREAL);
163 plhs[1] = mxCreateDoubleMatrix(options.y_size, 1, mxREAL);
164 xp = mxGetPr(plhs[0]);
165 y = mxGetPr(plhs[1]);
167 #ifdef MATLAB_SYSTEM_IDENTIFICATION
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Entry point for MATLAB Api.
hyb_errorcode hyb_main_loop(hyb_opts *opts, hyb_float *y, hyb_float *xp, hyb_float tau, const hyb_float *x, const hyb_float *u, const hyb_float **p)
Hybrid system main loop.
hyb_bool
libhybrid boolean type is actually an enum
void error_message(hyb_errorcode c)
handler for errors from hyb_main_loop function