0001 function getInstructions(obj, cppobj, get)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 global ACADO_;
0032
0033 if (get == 'B')
0034
0035 fprintf(cppobj.fileMEX,sprintf(' SimulationEnvironment %s(%s, %s, %s, %s);\n', obj.name, stringIntDouble(obj.startTime), stringIntDouble(obj.endTime), obj.process.name, obj.controller.name));
0036
0037 if (~isempty(obj.initvector))
0038 fprintf(cppobj.fileMEX,sprintf(' %s.init(%s);\n', obj.name, obj.initvector.name));
0039 end
0040
0041 fprintf(cppobj.fileMEX,sprintf(' returnValue returnvalue = %s.run();\n', obj.name));
0042
0043 fprintf(cppobj.fileMEX,'\n');
0044 fprintf(cppobj.fileMEX,'\n');
0045
0046
0047 fprintf(cppobj.fileMEX,' VariablesGrid out_processout; \n');
0048 fprintf(cppobj.fileMEX,' VariablesGrid out_feedbackcontrol; \n');
0049 fprintf(cppobj.fileMEX,' VariablesGrid out_feedbackparameter; \n');
0050 fprintf(cppobj.fileMEX,' VariablesGrid out_states; \n');
0051 fprintf(cppobj.fileMEX,' VariablesGrid out_intermediate_states; \n');
0052 fprintf(cppobj.fileMEX,' VariablesGrid out_algstates; \n');
0053
0054 fprintf(cppobj.fileMEX,sprintf(' %s.getSampledProcessOutput(out_processout);\n', obj.name));
0055 fprintf(cppobj.fileMEX,sprintf(' %s.getProcessDifferentialStates(out_states);\n', obj.name));
0056 if (~isempty(cppobj.u))
0057 fprintf(cppobj.fileMEX,sprintf(' %s.getFeedbackControl(out_feedbackcontrol);\n', obj.name));
0058 end
0059 if (~isempty(cppobj.p))
0060 fprintf(cppobj.fileMEX,sprintf(' %s.getFeedbackParameter(out_feedbackparameter);\n', obj.name));
0061 end
0062 if (~isempty(cppobj.ints))
0063 fprintf(cppobj.fileMEX,sprintf(' %s.getProcessIntermediateStates(out_intermediate_states);\n', obj.name));
0064 end
0065 if (~isempty(cppobj.z))
0066 fprintf(cppobj.fileMEX,sprintf(' %s.getProcessAlgebraicStates(out_algstates);\n', obj.name));
0067 end
0068
0069
0070 if (ACADO_.results_to_file == true)
0071
0072 fprintf(cppobj.fileMEX,sprintf(' out_processout.printToFile( "%s_OUT_states_sampled.m","STATES_SAMPLED",PS_MATLAB ); \n', cppobj.problemname));
0073 fprintf(cppobj.fileMEX,sprintf(' out_feedbackcontrol.printToFile( "%s_OUT_controls.m","CONTROLS",PS_MATLAB ); \n', cppobj.problemname));
0074 fprintf(cppobj.fileMEX,sprintf(' out_feedbackparameter.printToFile( "%s_OUT_parameters.m","PARAMETERS",PS_MATLAB ); \n', cppobj.problemname));
0075 fprintf(cppobj.fileMEX,sprintf(' out_states.printToFile( "%s_OUT_states.m","STATES",PS_MATLAB ); \n', cppobj.problemname));
0076 fprintf(cppobj.fileMEX,sprintf(' out_intermediate_states.printToFile( "%s_OUT_intermediatestates.m","INTERMEDIATESTATES",PS_MATLAB ); \n', cppobj.problemname));
0077 fprintf(cppobj.fileMEX,sprintf(' out_algstates.printToFile( "%s_OUT_algebraicstates.m","ALGEBRAICSTATES",PS_MATLAB ); \n', cppobj.problemname));
0078 end
0079
0080
0081 fprintf(cppobj.fileMEX,' const char* outputFieldNames[] = {"STATES_SAMPLED", "CONTROLS", "PARAMETERS", "STATES", "INTERMEDIATESTATES", "ALGEBRAICSTATES", "CONVERGENCE_ACHIEVED"}; \n');
0082 fprintf(cppobj.fileMEX,' plhs[0] = mxCreateStructMatrix( 1,1,7,outputFieldNames ); \n');
0083
0084 cppobj.getCPPlefthandout('OutSS', 'outSS', 'out_processout')
0085 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"STATES_SAMPLED",OutSS );\n');
0086
0087 cppobj.getCPPlefthandout('OutS', 'outS', 'out_states')
0088 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"STATES",OutS );\n');
0089
0090 cppobj.getCPPlefthandout('OutC', 'outC', 'out_feedbackcontrol')
0091 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"CONTROLS",OutC );\n');
0092
0093 cppobj.getCPPlefthandout('OutP', 'outP', 'out_feedbackparameter')
0094 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"PARAMETERS",OutP );\n');
0095
0096 cppobj.getCPPlefthandout('OutIS', 'outIS', 'out_intermediate_states')
0097 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"INTERMEDIATESTATES",OutIS );\n');
0098
0099 cppobj.getCPPlefthandout('OutZ', 'outZ', 'out_algstates')
0100 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"ALGEBRAICSTATES",OutZ );\n');
0101
0102 fprintf(cppobj.fileMEX,' mxArray *OutConv = NULL;\n');
0103 fprintf(cppobj.fileMEX,' if ( returnvalue == SUCCESSFUL_RETURN ) { OutConv = mxCreateDoubleScalar( 1 ); }else{ OutConv = mxCreateDoubleScalar( 0 ); } \n');
0104 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"CONVERGENCE_ACHIEVED",OutConv );\n');
0105
0106 fprintf(cppobj.fileMEX,'\n');
0107
0108 end
0109
0110 end