c语言 阶跃检测程序,C语言S-Function实现离散数字PID时,系统直接阶跃输出

本文介绍如何使用C语言编写Simulink S-Function模块,实现位置式离散数字PID控制器,仅包含积分项Ki。通过S-Function处理函数,计算系统的阶跃输出。
摘要由CSDN通过智能技术生成

使用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

<
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值