39 #include <qpOASES/QProblemB.hpp> 47 #define S_FUNCTION_NAME qpOASES_QProblemB 48 #define S_FUNCTION_LEVEL 2 56 #define SAMPLINGTIME 0.1 57 #define NCONTROLINPUTS 2 61 static void mdlInitializeSizes (SimStruct *S) 66 ssSetNumContStates(
S, 0);
67 ssSetNumDiscStates(
S, 0);
70 if ( !ssSetNumInputPorts(
S, 4) )
74 if ( !ssSetNumOutputPorts(
S, 4) )
78 ssSetInputPortVectorDimension(
S, 0, DYNAMICALLY_SIZED);
79 ssSetInputPortVectorDimension(
S, 1, DYNAMICALLY_SIZED);
80 ssSetInputPortVectorDimension(
S, 2, DYNAMICALLY_SIZED);
81 ssSetInputPortVectorDimension(
S, 3, DYNAMICALLY_SIZED);
84 ssSetOutputPortVectorDimension(
S, 0, 1 );
85 ssSetOutputPortVectorDimension(
S, 1, nU );
86 ssSetOutputPortVectorDimension(
S, 2, 1 );
87 ssSetOutputPortVectorDimension(
S, 3, 1 );
90 ssSetInputPortDirectFeedThrough(
S, 0, 1);
91 ssSetInputPortDirectFeedThrough(
S, 1, 1);
92 ssSetInputPortDirectFeedThrough(
S, 2, 1);
93 ssSetInputPortDirectFeedThrough(
S, 3, 1);
96 ssSetNumSampleTimes(
S, 1);
113 #if defined(MATLAB_MEX_FILE) 115 #define MDL_SET_INPUT_PORT_DIMENSION_INFO 116 #define MDL_SET_OUTPUT_PORT_DIMENSION_INFO 118 static void mdlSetInputPortDimensionInfo(SimStruct *
S, int_T port,
const DimsInfo_T *dimsInfo)
120 if ( !ssSetInputPortDimensionInfo(S, port, dimsInfo) )
124 static void mdlSetOutputPortDimensionInfo(SimStruct *S, int_T port,
const DimsInfo_T *dimsInfo)
126 if ( !ssSetOutputPortDimensionInfo(S, port, dimsInfo) )
136 ssSetOffsetTime(S, 0, 0.0);
147 int size_H, size_g, size_lb, size_ub;
155 size_H = ssGetInputPortWidth(S, 0);
156 size_g = ssGetInputPortWidth(S, 1);
157 size_lb = ssGetInputPortWidth(S, 2);
158 size_ub = ssGetInputPortWidth(S, 3);
167 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch!" );
172 if ( size_H != nV*nV )
175 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch!" );
183 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch!" );
191 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch!" );
199 mexErrMsgTxt(
"ERROR (qpOASES): Dimension mismatch!" );
210 mexErrMsgTxt(
"ERROR (qpOASES): Unable to create QProblemB object!" );
218 #ifdef __SUPPRESSANYOUTPUT__ 225 ssGetPWork(S)[0] = (
void *) problem;
228 ssGetPWork(S)[1] = (
void *) calloc( size_H,
sizeof(
real_t) );
229 ssGetPWork(S)[2] = (
void *) calloc( size_g,
sizeof(
real_t) );
230 ssGetPWork(S)[3] = (
void *) calloc( size_lb,
sizeof(
real_t) );
231 ssGetPWork(S)[4] = (
void *) calloc( size_ub,
sizeof(
real_t) );
232 ssGetPWork(S)[5] = (
void *) calloc( 1,
sizeof(
real_t) );
235 count = (
real_t *) ssGetPWork(S)[5];
252 InputRealPtrsType in_H, in_g, in_lb, in_ub;
259 real_T *out_objVal, *out_xOpt, *out_status, *out_nWSR;
263 in_H = ssGetInputPortRealSignalPtrs(S, 0);
264 in_g = ssGetInputPortRealSignalPtrs(S, 1);
265 in_lb = ssGetInputPortRealSignalPtrs(S, 2);
266 in_ub = ssGetInputPortRealSignalPtrs(S, 3);
269 problem = (
QProblemB *) ssGetPWork(S)[0];
271 H = (
real_t *) ssGetPWork(S)[1];
272 g = (
real_t *) ssGetPWork(S)[2];
273 lb = (
real_t *) ssGetPWork(S)[3];
274 ub = (
real_t *) ssGetPWork(S)[4];
276 count = (
real_t *) ssGetPWork(S)[5];
280 nV = ssGetInputPortWidth(S, 1);
282 for ( i=0; i<nV*nV; ++i )
285 for ( i=0; i<nV; ++i )
297 status = problem->
init( H,g,lb,ub, nWSR,0 );
298 ssGetPWork(S)[0] = (
void* ) problem;
304 status = problem->
hotstart( g,lb,ub, nWSR,0 );
309 problem->
init( H,g,lb,ub, nWSR,0 );
319 out_objVal = ssGetOutputPortRealSignal(S, 0);
320 out_xOpt = ssGetOutputPortRealSignal(S, 1);
321 out_status = ssGetOutputPortRealSignal(S, 2);
322 out_nWSR = ssGetOutputPortRealSignal(S, 3);
324 out_objVal[0] = ((real_T) problem->
getObjVal( ));
326 for ( i=0; i<nU; ++i )
327 out_xOpt[i] = ((real_T) xOpt[i]);
341 out_status[0] = -2.0;
346 out_status[0] = -3.0;
350 out_status[0] = -1.0;
354 out_nWSR[0] = ((real_T) nWSR);
357 count[0] = count[0] + 1;
373 for ( i=0; i<6; ++i )
375 if ( ssGetPWork(S)[i] != 0 )
376 free( ssGetPWork(S)[i] );
381 #ifdef MATLAB_MEX_FILE 382 #include "simulink.c" returnValue getPrimalSolution(real_t *const xOpt) const
static void mdlStart(SimStruct *S)
Implements the online active set strategy for box-constrained QPs.
returnValue init(const real_t *const _H, const real_t *const _g, const real_t *const _lb, const real_t *const _ub, int &nWSR, const real_t *const yOpt=0, real_t *const cputime=0)
returnValue hotstart(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, int &nWSR, real_t *const cputime)
static void mdlInitializeSampleTimes(SimStruct *S)
static void mdlOutputs(SimStruct *S, int_T tid)
static void mdlTerminate(SimStruct *S)
MessageHandling * getGlobalMessageHandler()
returnValue setPrintLevel(PrintLevel _printlevel)