資源簡介
自抗擾控制,最速跟蹤微分器Matlab仿真,用S函數寫的,參數已經調好,MATLAB configure得設置為fix step ,采樣時間設置為1e-3(與步長h相同即可)。

代碼片段和文件信息
/*
?*?sfuntmpl_basic.c:?Basic?‘C‘?template?for?a?level?2?S-function.
?*
?*??-------------------------------------------------------------------------
?*??|?See?matlabroot/simulink/src/sfuntmpl_doc.c?for?a?more?detailed?template?|
?*??-------------------------------------------------------------------------
?*
?*?Copyright?1990-2002?The?MathWorks?Inc.
?*?$Revision:?1.27?$
?*/
/*
?*?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??ADRC_TD
#define?S_FUNCTION_LEVEL?2
/*
?*?Need?to?include?simstruc.h?for?the?definition?of?the?SimStruct?and
?*?its?associated?macro?definitions.
?*/
#include?“simstruc.h“
#include?
/*?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(Smsg);
?*?????????return;
?*??????}
?*
?*?See?matlabroot/simulink/src/sfuntmpl_doc.c?for?more?details.
?*/
/*====================*
?*?S-function?methods?*
?*====================*/
/*?Function:?mdlInitializeSizes?===============================================
?*?Abstract:
?*????The?sizes?information?is?used?by?Simulink?to?determine?the?S-function
?*????block‘s?characteristics?(number?of?inputs?outputs?states?etc.).
?*/
static?void?mdlInitializeSizes(SimStruct?*S)
{
????/*?See?sfuntmpl_doc.c?for?more?details?on?the?macros?below?*/
????ssSetNumSFcnParams(S?0);??/*?Number?of?expected?parameters?*/
????if?(ssGetNumSFcnParams(S)?!=?ssGetSFcnParamsCount(S))?{
????????/*?Return?if?number?of?expected?!=?number?of?actual?parameters?*/
????????return;
????}
????ssSetNumContStates(S?0);
????ssSetNumDiscStates(S?0);
????
????if?(!ssSetNumInputPorts(S?1))?return;?????????//input????r?h?x0?N
????ssSetInputPortWidth(S?0?4);
????
??
????
???ssSetInputPortRequiredContiguous(S?0?true);?/*direct?input?signal?access*/
????/*
?????*?Set?direct?feedthrough?flag?(1=yes?0=no).
?????*?A?port?has?direct?feedthrough?if?the?input?is?used?in?either
?????*?the?mdlOutputs?or?mdlGetTimeOfNextVarHit?functions.
?????*?See?matlabroot/simulink/src/sfuntmpl_directfeed.txt.
?????*/
????ssSetInputPortDirectFeedThrough(S?0?1);
????
????if?(!ssSetNumOutputPorts(S?1))?return;?????????//output??x1?x2
????ssSetOutputPortWidth(S?0?2);
????
????ssSetNumSampleTimes(S?1);
????ssSetNumRWork(S?0);
????ssSetNumIWork(S?0);
????ssSetNumPWork(S?0);
????ssSetNumModes(S?0);
????ssSetNumNonsampledZCs(S?0);
????ssSetOptions(S1);
????
????
}
/*?Function:?mdlInitiali
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????8055??2019-07-01?20:17??ADRC_TD.c
?????文件???????35328??2019-06-18?19:44??ADRC_TD.mexw64
?????文件???????45114??2019-06-27?15:10??TD_TEST.mdl
評論
共有 條評論