Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

TestCaseMatlabPointerPID_1.cpp

00001 // 00002 // Copyright 2004 P&P Software GmbH - All Rights Reserved 00003 // 00004 // TestCaseMatlabPointerPID_1.cpp 00005 // 00006 // Version 1.0 00007 // Date 29.10.03 (Version 1.0) 00008 // Author R. Totaro 00009 00010 #include "../GeneralInclude/CompilerSwitches.h" 00011 #include "../GeneralInclude/ClassId.h" 00012 #include "../GeneralInclude/Constants.h" 00013 #include "../Data/DC_MatlabPointerPID.h" 00014 #include "../Data/ControlBlock.h" 00015 #include "TestCaseMatlabPointerPID_1.h" 00016 00017 TestCaseMatlabPointerPID_1::TestCaseMatlabPointerPID_1(void) : 00018 TestCaseGenericSetUp(ID_MATLABPOINTERPID*10+1,"TestCaseMatlabPointerPID_1") { 00019 return; 00020 } 00021 00022 void TestCaseMatlabPointerPID_1::runTestCase(void) { 00023 TD_Float input; 00024 TD_Float output; 00025 const unsigned int numParams=3; 00026 DC_MatlabPointerPID *pMPID =new DC_MatlabPointerPID; 00027 00028 // Verify correctness of class identifier 00029 if (pMPID->getClassId()!=ID_MATLABPOINTERPID) { 00030 setTestResult(TEST_FAILURE,"Wrong class identifier"); 00031 return; 00032 } 00033 00034 // A newly created DC_MatlabPointerPID shall not be configured 00035 if (pMPID->isObjectConfigured()) { 00036 setTestResult(TEST_FAILURE,"Newly created control block is not configured"); 00037 return; 00038 } 00039 00040 // Link the input and verify the block is not yet configured 00041 pMPID->setInputLink(0,&input); 00042 if (pMPID->isObjectConfigured()) { 00043 setTestResult(TEST_FAILURE,"Wrong configuration status"); 00044 return; 00045 } 00046 00047 // Link the output and verify the block is now configured 00048 pMPID->setOutputLink(0,&output); 00049 if (!pMPID->isObjectConfigured()) { 00050 setTestResult(TEST_FAILURE,"failed to configure the control block"); 00051 return; 00052 } 00053 00054 // Verify the correctness of the number of parameters 00055 if (pMPID->getNumberOfParameters()!=numParams) { 00056 setTestResult(TEST_FAILURE,"Wrong number of parameters"); 00057 return; 00058 } 00059 00060 #ifdef HAVE_SIMULINK 00061 // Initialize the model's parameters 00062 const TD_Float defaultParameters[]={(TD_Float)-1.0,(TD_Float)1.0,(TD_Float)1.0}; 00063 00064 for (unsigned int i=0;i<numParams;i++) 00065 pMPID->setParameter(i,defaultParameters[i]); 00066 00067 // The following array contains the expected output values. These 00068 // are correct if and only if the initial value of Kp, Ki and Kd 00069 // (see pid.c and DC_MatlabPointerPID.cpp) are, respectively, -1.0, 1.0 00070 // and 1.0. The value of the time step shall be 0.25. 00071 const TD_Float expectedResults[]={(TD_Float)3.0,(TD_Float)-0.75, 00072 (TD_Float)3.0,(TD_Float)-1.0,(TD_Float)0.25}; 00073 const TD_Float *pRes =expectedResults; 00074 00075 // Set the input to a fixed value and verify that 00076 // the model is invoked and properly working. 00077 // Initially the parameters are left at their default 00078 // values (see pid.c and DC_MatlabPointerPID.cpp). 00079 input=(TD_Float)1.0; 00080 00081 pMPID->propagate(); 00082 if (fabsf(output-*pRes++)>=FLT_EPSILON) { 00083 setTestResult(TEST_FAILURE,"Control block returned wrong value"); 00084 return; 00085 } 00086 00087 pMPID->propagate(); 00088 if (fabsf(output-*pRes++)>=FLT_EPSILON) { 00089 setTestResult(TEST_FAILURE,"Control block returned wrong value"); 00090 return; 00091 } 00092 00093 // Let's reset the model and verify that we get the right output 00094 // value after a propagate. 00095 pMPID->reset(); 00096 pMPID->propagate(); 00097 if (fabsf(output-*pRes++)>=FLT_EPSILON) { 00098 setTestResult(TEST_FAILURE,"Control block reset failed"); 00099 return; 00100 } 00101 00102 // We now reset the model and set the value of Kd to 0.0f 00103 pMPID->reset(); 00104 pMPID->setParameter(2,(TD_Float)0.0); 00105 pMPID->propagate(); 00106 if (fabsf(output-*pRes++)>=FLT_EPSILON) { 00107 setTestResult(TEST_FAILURE,"Failed to set the D gain"); 00108 return; 00109 } 00110 00111 // We do the same with Kp 00112 pMPID->reset(); 00113 pMPID->setParameter(0,(TD_Float)0.0); 00114 pMPID->propagate(); 00115 pMPID->propagate(); 00116 if (fabsf(output-*pRes++)>=FLT_EPSILON) { 00117 setTestResult(TEST_FAILURE,"Failed to set the P gain"); 00118 return; 00119 } 00120 #else 00121 // This is done to prevent the test coverage results from 00122 // degrading when Simulink is not available. These two calls 00123 // become a no-op. 00124 pMPID->propagate(); 00125 pMPID->reset(); 00126 #endif 00127 00128 setTestResult(TEST_SUCCESS,"Test Successful"); 00129 return; 00130 }
Copyright 2003 P&P Software GmbH - All Rights Reserved