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

📄 heat_pid.m

📁 Matlab学习课件
💻 M
字号:
function heat_pid
% PID control computation for the heater control system
% Modify this for performance evaluation
% Remove timing check and put in a state transition for timing
% Re-organize the state code to account for this

heatglbl 	% Global definitions

% The 'next-state'is maintained as a separate variable so that the
% initialization canbe handled correctly and so a test can be
% constructed to tell whether the entry function of a state
% should be run. The next-state variable must be static so it
% remembered across function invocations. The 'global' designation
% is the only way Matlab has of making a variable static.
% The default value of the next-state variable is -1, indicating
% that no state change has taken place.

global Sheat_pid_next intvv intv minmc maxmc setprev valueprev
	% Next state for this task (other local statics
	% can be listed here.
	% These aren't really global,  but do have to be 'static'
	% Matlab doesn't have a 'static' declaration so this will have to do!

if Sheat_pid == 0
	% Initialization section - occurs once only
	Sheat_pid = 1;	% Make sure this section is not executed again!
	Sheat_pid_next = 1;	% First state.
		%The default is -1 which indicates stay in same state
	duty_cycle = 0;
	%duty_cycle = 0.43;	% Test value
	value = x(1);	% Temperature
	valueprev = value;
	intvv = 0;	% Integrator value
	setprev = temp_set;
	minmc = 0;	% No cooling for this system
	maxmc = 1;	% Maximum duty cycle
	return;
end


if Sheat_pid_next ~= -1
	% There has been a state change (including self-transition)
	[i_audit,trans_trail] = audit(1,Sheat_pid,Sheat_pid_next,...
		tstep,trans_trail,i_audit);
		% Record this transition
	Sheat_pid = Sheat_pid_next;
	run_entry = 1;
	Sheat_pid_next = -1;	% Default - stay in same state
else
	run_entry = 0;
end

% This task has only one state -- it produces a command duty cycle as
% a function of time, based on a PID feedback control calculation

% Run the code associated with the current state
if Sheat_pid == 1
	% Entry section
	if run_entry
		% The control code runs once -- subsequent scans just check the time
		Theat_pid = Theat_pid + Tpid_delt;	% Time for next execution
		value = x(1);	% Temperature
		 [mc,intv] = pidcntrl(Tpid_delt,temp_set,setprev,value,valueprev,intvv,...
			   Kp,Ki,Kd,minmc,maxmc);
		duty_cycle = mc;
		duty_cycle = 0.43;	% Test value
		intvv = intv;	% New integrator value
		valueprev = value;  % Save values for next time
		setprev = temp_set;
	end
	% Action section
	%Test/exit section  -- check for when it is time for the next sample
	if tstep >= Theat_pid
		Sheat_pid_next = 1;	% Transition to this state -- execute control
	end
else	% Check for a state variable value that doesn't
	% to a defined state.
	error('Task: heat_pid -- unknown state encountered');
end

⌨️ 快捷键说明

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