00001
00002
00003
00004
00005
00006
00007
00008
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
00029
if (pMPID->
getClassId()!=ID_MATLABPOINTERPID) {
00030 setTestResult(
TEST_FAILURE,
"Wrong class identifier");
00031
return;
00032 }
00033
00034
00035
if (pMPID->
isObjectConfigured()) {
00036 setTestResult(
TEST_FAILURE,
"Newly created control block is not configured");
00037
return;
00038 }
00039
00040
00041 pMPID->
setInputLink(0,&input);
00042
if (pMPID->
isObjectConfigured()) {
00043 setTestResult(
TEST_FAILURE,
"Wrong configuration status");
00044
return;
00045 }
00046
00047
00048 pMPID->
setOutputLink(0,&output);
00049
if (!pMPID->
isObjectConfigured()) {
00050 setTestResult(
TEST_FAILURE,
"failed to configure the control block");
00051
return;
00052 }
00053
00054
00055
if (pMPID->
getNumberOfParameters()!=numParams) {
00056 setTestResult(
TEST_FAILURE,
"Wrong number of parameters");
00057
return;
00058 }
00059
00060
#ifdef HAVE_SIMULINK
00061
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
00068
00069
00070
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
00076
00077
00078
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
00094
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
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
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
00122
00123
00124 pMPID->
propagate();
00125 pMPID->
reset();
00126
#endif
00127
00128 setTestResult(
TEST_SUCCESS,
"Test Successful");
00129
return;
00130 }