⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pid_lct.m

📁 this is matlab pid tuning code
💻 M
字号:
% Two 16-bits fixed-point PID implementations in C with 
% the Legacy code tool.
%
% Usage :
% Generation of 2 Simulink blocks that implement single and double
% precision 16-bits PID routines. 
%
% Before simulation :
% 1) Check the installation of the C compiler with
% the command "mex -setup".
% 2) Run this file to generate mex file and compile it.
%
% Fixed-point basics :
% http://en.wikipedia.org/wiki/Fixed-point_arithmetic
%
% Author :
% Gilles Bailly, nov. 2008.
% LCAR UMR5589-CNRS, Toulouse, France.

%% fixed-point PID controller : single precision
clear, clc;
pid_sp_lct = legacy_code('initialize');
pid_sp_lct.SFunctionName = 'pid_sp_SFUN';
pid_sp_lct.OutputFcnSpec = ['',...
    'int16 y1 ',...     % uc
    '= pid_sp(',...
    'int16 u1,',...     % yr
    'int16 u2,',...     % ym
    'int16 u3,',...     % kp
    'int16 u4,',...     % ki
    'int16 u5,',...     % rounding_enable
    'int16 work1[1]',...   % state
    ')'];
pid_sp_lct.HeaderFiles   = {'pid_header.h'};
pid_sp_lct.SourceFiles   = {'pid_source.c'};
pid_sp_lct.IncPaths      = {''};
pid_sp_lct.SrcPaths      = {''};

legacy_code('sfcn_cmex_generate', pid_sp_lct);
legacy_code('compile', pid_sp_lct);

% uncomment the following commands to generate blocks 
%legacy_code('slblock_generate', pid_sp_lct, 'FIXED_POINT_PID_SINGLE_PRECISION');

%% fixed-point PID controller : double precision
pid_dp_lct = legacy_code('initialize');
pid_dp_lct.SFunctionName = 'pid_dp_SFUN';
pid_dp_lct.OutputFcnSpec = ['',...
    'int16 y1 ',...     % uc
    '= pid_dp(',...
    'int16 u1,',...     % yr
    'int16 u2,',...     % ym
    'int16 u3,',...     % kp
    'int16 u4,',...     % ki
    'int16 u5,',...     % rounding_enable
    'int32 work1[1]',...   % state
    ')'];
pid_dp_lct.HeaderFiles   = {'pid_header.h'};
pid_dp_lct.SourceFiles   = {'pid_source.c'};
pid_dp_lct.IncPaths      = {''};
pid_dp_lct.SrcPaths      = {''};

legacy_code('sfcn_cmex_generate', pid_dp_lct);
legacy_code('compile', pid_dp_lct);

% uncomment the following commands to generate blocks 
%legacy_code('slblock_generate', pid_dp_lct, 'FIXED_POINT_PID_DOUBLE_PRECISION');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -