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

pid.c

00001 #pragma warning(disable:4001) 00002 00003 #include "../GeneralInclude/CompilerSwitches.h" 00004 00005 #ifndef HAVE_SIMULINK 00006 00007 /* 00008 * We need this to keep Visual C++ happy: trying to compile an empty file is 00009 * a fatal error (sic). 00010 * On the other side, we have to comment out the whole file if we want to be able 00011 * to compile the Obs Framework on machines where Matlab + Simulink are not installed. 00012 */ 00013 void PID_dummy(void) { 00014 return; 00015 } 00016 00017 #else 00018 00019 /* 00020 * Real-Time Workshop code generation for Simulink model "PID.mdl". 00021 * 00022 * Model Version : 1.15 00023 * Real-Time Workshop file version : 5.0 $Date: 2004/01/16 06:53:50 $ 00024 * Real-Time Workshop file generated on : Mon Jun 02 11:22:38 2003 00025 * TLC version : 5.0 (Jun 18 2002) 00026 * C source code generated on : Mon Jun 02 11:22:38 2003 00027 */ 00028 00029 #include "PID.h" 00030 #include "PID_private.h" 00031 00032 /* Exported block signals */ 00033 real_T Output; /* <Root>/Sum */ 00034 real_T Input; /* <Root>/Input */ 00035 00036 /* Exported block parameters */ 00037 real_T Kd = 1.0; 00038 real_T Ki = 1.0; 00039 real_T Kp = -1.0; 00040 00041 /* Block signals (auto storage) */ 00042 BlockIO_PID PID_B; 00043 00044 /* Block states (auto storage) */ 00045 D_Work_PID PID_DWork; 00046 00047 /* Real-time model */ 00048 RT_MODEL_PID PID_M_; 00049 RT_MODEL_PID *PID_M = &PID_M_; 00050 00051 /* Model step function */ 00052 void PID_step(void) 00053 { 00054 /* local block i/o variables */ 00055 real_T rtb_I_Gain; 00056 real_T rtb_D_Gain; 00057 real_T rtb_Discrete_Transfer_Fcn; 00058 00059 /* Gain: '<Root>/I Gain' incorporates: 00060 * Inport: '<Root>/Input' 00061 * 00062 * Regarding '<Root>/I Gain': 00063 * Gain value: Ki 00064 */ 00065 rtb_I_Gain = Input * Ki; 00066 00067 /* DiscreteIntegrator: '<Root>/Discrete-Time Integrator' 00068 * 00069 * Regarding '<Root>/Discrete-Time Integrator': 00070 * Unlimited, w/o Saturation Port 00071 */ 00072 /* system was just enabled */ 00073 if ( PID_DWork.Discrete_Time_Int_SYSTEM_ENABLE) { 00074 PID_DWork.Discrete_Time_Int_SYSTEM_ENABLE = false; 00075 PID_B.Discrete_Time_Int = PID_DWork.Discrete_Time_Int_DSTATE; 00076 } else { 00077 PID_B.Discrete_Time_Int = PID_DWork.Discrete_Time_Int_DSTATE + 0.125 * 00078 rtb_I_Gain; 00079 } 00080 00081 /* Gain: '<Root>/D Gain' incorporates: 00082 * Inport: '<Root>/Input' 00083 * 00084 * Regarding '<Root>/D Gain': 00085 * Gain value: Kd 00086 */ 00087 rtb_D_Gain = Input * Kd; 00088 00089 /* DiscreteTransferFcn: '<Root>/Discrete Transfer Fcn' */ 00090 rtb_Discrete_Transfer_Fcn = 4.0*rtb_D_Gain; 00091 rtb_Discrete_Transfer_Fcn += -4.0*PID_DWork.Discrete_Transfer_Fcn_DSTATE; 00092 00093 /* Sum: '<Root>/Sum' incorporates: 00094 * Gain: '<Root>/P Gain' 00095 * Inport: '<Root>/Input' 00096 * 00097 * Regarding '<Root>/P Gain': 00098 * Gain value: Kp 00099 */ 00100 Output = (Input * Kp) + PID_B.Discrete_Time_Int + rtb_Discrete_Transfer_Fcn; 00101 00102 /* DiscreteIntegrator Block: <Root>/Discrete-Time Integrator */ 00103 PID_DWork.Discrete_Time_Int_DSTATE = PID_B.Discrete_Time_Int + 0.125 * 00104 rtb_I_Gain; 00105 00106 /* DiscreteTransferFcn Block: <Root>/Discrete Transfer Fcn */ 00107 { 00108 PID_DWork.Discrete_Transfer_Fcn_DSTATE = rtb_D_Gain + 00109 (0.0)*PID_DWork.Discrete_Transfer_Fcn_DSTATE; 00110 } 00111 } 00112 00113 /* Model initialize function */ 00114 void PID_initialize(boolean_T firstTime) 00115 { 00116 if (firstTime) { 00117 /* registration code */ 00118 rtmSetErrorStatus(PID_M, (const char_T *)0); 00119 00120 /* block I/O */ 00121 { 00122 void *b = (void *) &PID_B; 00123 { 00124 int_T i; 00125 00126 b =&PID_B.Discrete_Time_Int; 00127 for (i = 0; i < 1; i++) { 00128 ((real_T*)b)[i] = 0.0; 00129 } 00130 } 00131 00132 /* exported global signals */ 00133 Output = 0.0; 00134 } 00135 00136 /* data type work */ 00137 (void)memset((char_T *) &PID_DWork, 0, sizeof(D_Work_PID)); 00138 { 00139 int_T i; 00140 real_T *dwork_ptr = (real_T *) &PID_DWork.Discrete_Time_Int_DSTATE; 00141 00142 for (i = 0; i < 2; i++) { 00143 dwork_ptr[i] = 0.0; 00144 } 00145 } 00146 00147 /* external inputs */ 00148 Input = 0.0; 00149 00150 /* external outputs */ 00151 Output = 0.0; 00152 } 00153 00154 /* DiscreteIntegrator Block: <Root>/Discrete-Time Integrator */ 00155 PID_DWork.Discrete_Time_Int_SYSTEM_ENABLE = true; 00156 } 00157 00158 /* Model terminate function */ 00159 void PID_terminate(void) 00160 { 00161 /* (no terminate code required) */ 00162 } 00163 00164 #endif
Copyright 2003 P&P Software GmbH - All Rights Reserved