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

TestCaseMatlabCopyPID_1.cpp

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