使用Simulink中的S-Function模块,用C语言编写位置式离散数字PID时,函数处理只是做了Ki=1的积分计算,说白了PID中只有I项积分项。系统直接阶跃输出
//c语言 S-Function文件如下
/*
* sfuntmpl_basic.c: Basic 'C' template for a level 2 S-function.
*
* Copyright 1990-2013 The MathWorks, Inc.
*/
/*
* You must specify the S_FUNCTION_NAME as the name of your S-function
* (i.e. replace sfuntmpl_basic with the name of your S-function).
*/
#define S_FUNCTION_NAME Discrete_Position_PID_SFunc
#define S_FUNCTION_LEVEL 2
/*
* Need to include simstruc.h for the definition of the SimStruct and
* its associated macro definitions.
*/
#include "simstruc.h"
int OutputRef,OutputReal;
static int IntegrateSum;
/* Error handling
* --------------
*
* You should use the following technique to report errors encountered within
* an S-function:
*
* ssSetErrorStatus(S,"Error encountered due to ...");
* return;
*
* Note that the 2nd argument to ssSetErrorStatus must be persistent memory.
* It cannot be a local variable. For example the following will cause
* unpredictable errors:
*
* mdlOutputs()
* {
* char msg[256]; {ILLEGAL: to fix use "static char msg[256];"}
* sprintf(msg,"Error due to %s", string);
* ssSetErrorStatus(S,msg);
* return;
* }
*
*/
/*====================*
* S-function methods *
*====================*/
/* Function: mdlInitializeSizes ===============================================
* Abstract:
* The sizes information is used by Simulink to determine the S-function
<