48 #define S_FUNCTION_NAME qpOASES_e_QProblemB 49 #define S_FUNCTION_LEVEL 2 57 #define SAMPLINGTIME -1 58 #define NCONTROLINPUTS 2 60 #define HESSIANTYPE HST_UNKNOWN 64 static void mdlInitializeSizes (SimStruct *S) 69 ssSetNumContStates(
S, 0);
70 ssSetNumDiscStates(
S, 0);
73 ssSetNumSFcnParams(
S, 1);
74 if ( ssGetNumSFcnParams(
S) != ssGetSFcnParamsCount(
S) )
78 if ( !ssSetNumInputPorts(
S, 3) )
82 if ( !ssSetNumOutputPorts(
S, 4) )
86 ssSetInputPortVectorDimension(
S, 0, DYNAMICALLY_SIZED);
87 ssSetInputPortVectorDimension(
S, 1, DYNAMICALLY_SIZED);
88 ssSetInputPortVectorDimension(
S, 2, DYNAMICALLY_SIZED);
91 ssSetOutputPortVectorDimension(
S, 0, nU );
92 ssSetOutputPortVectorDimension(
S, 1, 1 );
93 ssSetOutputPortVectorDimension(
S, 2, 1 );
94 ssSetOutputPortVectorDimension(
S, 3, 1 );
97 ssSetInputPortDirectFeedThrough(
S, 0, 1);
98 ssSetInputPortDirectFeedThrough(
S, 1, 1);
99 ssSetInputPortDirectFeedThrough(
S, 2, 1);
102 ssSetNumSampleTimes(
S, 1);
117 #if defined(MATLAB_MEX_FILE) 119 #define MDL_SET_INPUT_PORT_DIMENSION_INFO 120 #define MDL_SET_OUTPUT_PORT_DIMENSION_INFO 122 static void mdlSetInputPortDimensionInfo(SimStruct *
S, int_T port,
const DimsInfo_T *dimsInfo)
124 if ( !ssSetInputPortDimensionInfo(S, port, dimsInfo) )
128 static void mdlSetOutputPortDimensionInfo(SimStruct *S, int_T port,
const DimsInfo_T *dimsInfo)
130 if ( !ssSetOutputPortDimensionInfo(S, port, dimsInfo) )
140 ssSetOffsetTime(S, 0, 0.0);
149 int size_g, size_lb, size_ub;
150 int size_H, nRows_H, nCols_H;
159 const mxArray* in_H = ssGetSFcnParam(S, 0);
161 if ( mxIsEmpty(in_H) == 1 )
165 #ifndef __SUPPRESSANYOUTPUT__ 166 mexErrMsgTxt(
"ERROR (qpOASES): Hessian can only be empty if type is set to HST_ZERO or HST_IDENTITY!" );
177 nRows_H = (int)mxGetM(in_H);
178 nCols_H = (int)mxGetN(in_H);
179 size_H = nRows_H * nCols_H;
182 size_g = ssGetInputPortWidth(S, 0);
183 size_lb = ssGetInputPortWidth(S, 1);
184 size_ub = ssGetInputPortWidth(S, 2);
192 #ifndef __SUPPRESSANYOUTPUT__ 193 mexErrMsgTxt(
"ERROR (qpOASES): Maximum number of iterations must not be negative!" );
200 #ifndef __SUPPRESSANYOUTPUT__ 201 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch!" );
206 if ( ( size_H != nV*nV ) && ( size_H != 0 ) )
208 #ifndef __SUPPRESSANYOUTPUT__ 209 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch in H!" );
214 if ( nRows_H != nCols_H )
216 #ifndef __SUPPRESSANYOUTPUT__ 217 mexErrMsgTxt(
"ERROR (qpOASES): Hessian matrix must be square matrix!" );
222 if ( ( nU < 1 ) || ( nU > nV ) )
224 #ifndef __SUPPRESSANYOUTPUT__ 225 mexErrMsgTxt(
"ERROR (qpOASES): Invalid number of control inputs!" );
230 if ( ( size_lb != nV ) && ( size_lb != 0 ) )
232 #ifndef __SUPPRESSANYOUTPUT__ 233 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch in lb!" );
238 if ( ( size_ub != nV ) && ( size_ub != 0 ) )
240 #ifndef __SUPPRESSANYOUTPUT__ 241 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch in ub!" );
255 #ifdef __SUPPRESSANYOUTPUT__ 259 ssGetPWork(S)[0] = (
void*)(&problem);
263 ssGetPWork(S)[1] = (
void *) calloc( size_H,
sizeof(
real_t) );
265 ssGetPWork(S)[1] = 0;
267 ssGetPWork(S)[2] = (
void *) calloc( size_g,
sizeof(
real_t) );
270 ssGetPWork(S)[3] = (
void *) calloc( size_lb,
sizeof(
real_t) );
272 ssGetPWork(S)[3] = 0;
275 ssGetPWork(S)[4] = (
void *) calloc( size_ub,
sizeof(
real_t) );
277 ssGetPWork(S)[4] = 0;
292 InputRealPtrsType in_g, in_lb, in_ub;
299 real_T *out_uOpt, *out_objVal, *out_status, *out_nWSR;
305 const mxArray* in_H = ssGetSFcnParam(S, 0);
306 in_g = ssGetInputPortRealSignalPtrs(S, 0);
307 in_lb = ssGetInputPortRealSignalPtrs(S, 1);
308 in_ub = ssGetInputPortRealSignalPtrs(S, 2);
311 problem = (
QProblemB*)(ssGetPWork(S)[0]);
313 H = (
real_t*)(ssGetPWork(S)[1]);
314 g = (
real_t*)(ssGetPWork(S)[2]);
315 lb = (
real_t*)(ssGetPWork(S)[3]);
316 ub = (
real_t*)(ssGetPWork(S)[4]);
320 nV = ssGetInputPortWidth(S, 1);
325 for ( i=0; i<nV*nV; ++i )
326 H[i] = (mxGetPr(in_H))[i];
329 for ( i=0; i<nV; ++i )
334 for ( i=0; i<nV; ++i )
340 for ( i=0; i<nV; ++i )
370 out_uOpt = ssGetOutputPortRealSignal(S, 0);
371 out_objVal = ssGetOutputPortRealSignal(S, 1);
372 out_status = ssGetOutputPortRealSignal(S, 2);
373 out_nWSR = ssGetOutputPortRealSignal(S, 3);
375 for ( i=0; i<nU; ++i )
376 out_uOpt[i] = (real_T)(xOpt[i]);
380 out_nWSR[0] = (real_T)(nWSR);
398 for ( i=1; i<5; ++i )
400 if ( ssGetPWork(S)[i] != 0 )
401 free( ssGetPWork(S)[i] );
406 #ifdef MATLAB_MEX_FILE 407 #include "simulink.c" void QProblemBCON(QProblemB *_THIS, int _nV, HessianType _hessianType)
#define USING_NAMESPACE_QPOASES
static void mdlInitializeSampleTimes(SimStruct *S)
Implements the online active set strategy for box-constrained QPs.
returnValue QProblemB_reset(QProblemB *_THIS)
int qpOASES_getSimpleStatus(returnValue returnvalue, BooleanType doPrintStatus)
Allows to pass back messages to the calling function.
real_t QProblemB_getObjVal(QProblemB *_THIS)
returnValue MessageHandling_reset(MessageHandling *_THIS)
returnValue removeNaNs(real_t *const data, unsigned int dim)
static void mdlOutputs(SimStruct *S, int_T tid)
static void mdlTerminate(SimStruct *S)
static void mdlStart(SimStruct *S)
int_t QProblemB_hotstart(const real_t *const g, const real_t *const lb, const real_t *const ub, int_t *const nWSR, real_t *const cputime, real_t *const x, real_t *const y, real_t *const obj, int_t *const status)
Provides a generic way to set and pass user-specified options.
returnValue QProblemB_setPrintLevel(QProblemB *_THIS, PrintLevel _printlevel)
static returnValue QProblemB_setOptions(QProblemB *_THIS, Options _options)
returnValue Options_setToMPC(Options *_THIS)
MessageHandling * qpOASES_getGlobalMessageHandler()
returnValue QProblemB_getPrimalSolution(QProblemB *_THIS, real_t *const xOpt)
int_t QProblemB_init(const real_t *const H, const real_t *const g, const real_t *const lb, const real_t *const ub, int_t *const nWSR, real_t *const cputime, const qpOASES_Options *const options, real_t *const x, real_t *const y, real_t *const obj, int_t *const status)
static unsigned int QProblemB_getCount(QProblemB *_THIS)
returnValue removeInfs(real_t *const data, unsigned int dim)