function varargout = pid_model(varargin)
% PID_MODEL MATLAB code for pid_model.fig
% PID_MODEL, by itself, creates a new PID_MODEL or raises the existing
% singleton*.
%
% H = PID_MODEL returns the handle to a new PID_MODEL or the handle to
% the existing singleton*.
%
% PID_MODEL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PID_MODEL.M with the given input arguments.
%
% PID_MODEL('Property','Value',...) creates a new PID_MODEL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before pid_model_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to pid_model_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help pid_model
% Last Modified by GUIDE v2.5 17-Dec-2019 11:26:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pid_model_OpeningFcn, ...
'gui_OutputFcn', @pid_model_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before pid_model is made visible.
function pid_model_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to pid_model (see VARARGIN)
% Choose default command line output for pid_model
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes pid_model wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = pid_model_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%%%PID控制算法
ts=0.5; %采样时间=0.5s
sys=tf(4,[1 2 0]);%建立被控对象传递函数
dsys=c2d(sys,ts,'z');%离散化,表示为z传递函数的形式
[num,den]=tfdata(dsys,'v');%输出num和den,分别代表差分方程分子与分母的系数
e_1=0; %初始化k-1时刻的偏差
e_2=0;
u_1=0.0; %初始化k-1时刻时刻的输入量
u_2=0.0;
y_1=0; %初始化k-1时刻时刻的输出量
y_2=0;
%PID参数
global Kp;
global Ki;
global Kd;
u=zeros(1,100);%数组的大小
time=zeros(1,100);%初始化数组的大小
ts=0.5;
for k=1:1:100
time(k)=k*ts; %时间参数由 1 时刻开始
r(k)=1; %期望值
y(k)=-1*den(3)*y_2-den(2)*y_1+num(3)*u_2+num(2)*u_1+num(1)*u(k);% 初始化系统响应输出序列,与前一时刻的输出有关(这就是差分方程)
e(k)=r(k)-y(k); %期望输出与实际输出之间的差值,代表误差信号
u(k)=Kp*(e(k)-e_1)+Ki*e(k)+Kd*(e(k)-2*e_1+e_2); %系统PID控制器输出序列
u_2=u_1;
y_2=y_1;
e_2=e_1;
u_1=u(k); %前一个的控制器输出值
y_1=y(k); %前一个的系统响应输出值
e_1=e(k); %前一个误差信号的值
end
maxy=max(y);
axes(handles.axes1);
p1=plot(time,r,'-.');xlim([0,50]);hold on;%指令信号的曲线(即期望输入)
p2=plot(time,y);xlim([0,50]);ylim([0,maxy+0.07]);xlabel('t(s)');ylabel('yout');hold on;%不含积分分离的PID曲线
title('PID响应--时间')
%峰值时间
for k=1:1:100
if (y(k)==maxy)
Tp=ts*k;
break;
end
end
%最大值不超过1的情况
if maxy<=0.98
set(handles.Trise,'String','无穷大');
set(handles.Tover,'String','无');
set(handles.Tpeak,'String',Tp);
set(handles.ess,'String',y(99)-1);
end
%最大值超过1
if maxy>0.98
for k=2:1:99
if (y(k)<1)&&(y(k+1)>=0.998)
Tr=ts*k;
break;
end
end
end
if maxy>0.98
set(handles.Tpeak,'String',Tp);
set(handles.Trise,'String',Tr);
set(handles.Tover,'String',maxy-1);
set(handles.ess,'String',y(99)-1);
end
maxy
y(99)-1
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 重置清空图片
cla(handles.axes1,'reset');
function Kp_Callback(hObject, eventdata, handles)
% hObject handle to Kp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Kp;
Kp=str2double(get(hObject,'String'));
% Hints: get(hObject,'String') returns contents of Kp as text
% str2double(get(hObject,'String')) returns contents of Kp as a double
% --- Executes during object creation, after setting all properties.
function Kp_CreateFcn(hObject, eventdata, handles)
% hObject handle to Kp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Ki_Callback(hObject, eventdata, handles)
% hObject handle to Ki (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Ki;
Ki=str2double(get(hObject,'String'));
% Hints: get(hObject,'String') returns contents of Ki as text
% str2double(get(hObject,'String')) returns contents of Ki as a double
% --- Executes during object creation, after setting all properties.
function Ki_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ki (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Kd_Callback(hObject, eventdata, handles)
% hObject handle to Kd (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Kd;
Kd=str2double(get(hObject,'String'));
% Hints: get(hObject,'String') returns contents of Kd as text
% str2double(get(hObject,'String')) returns contents of Kd as a double
% --- Executes during object creation, after setting all properties.
function Kd_CreateFcn(hObject, eventdata, handles)
% hObject handle to Kd (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && iseq
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于Matlab GUI 设计了PID控制器调参界面源码+GUI界面+详细文档+全部资料(高分项目)本资源中的源码都是经过本地编译过可运行的,评审分达到95分以上。资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 【备注】 1、该项目是个人高分毕业设计项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 基于Matlab GUI 设计了PID控制器调参界面源码+GUI界面+详细文档+全部资料(高分项目)本资源中的源码都是经过本地编译过可运行的,评审分达到95分以上。资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果
资源推荐
资源详情
资源评论
收起资源包目录
基于Matlab GUI 设计了PID控制器调参界面源码+GUI界面+详细文档+全部资料(高分项目).zip (10个子文件)
Digital_PID_Conroler-master
PID
pid_model.fig 66KB
digital_pid.m 1KB
BP_network.m 1KB
pid_model.m 13KB
gs.GIF 6KB
pid_model.fig 78KB
kuangtu.GIF 8KB
USTC.jpg 28KB
matlabrc.mat 128B
pid_model.m 14KB
共 10 条
- 1
资源评论
盈梓的博客
- 粉丝: 7279
- 资源: 2021
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功