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

📄 task1.m

📁 Matlab学习课件
💻 M
字号:
function task1
% Template for a typical task function (which has to be
% a separate file with the same name in Matlab)

%glbl_var	% 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 S_task1 S_task1_next % 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 S_task1 == 0
	% Initialization section - occurs once only
	S_task1 = 1;	% Make sure this section is not executed again!
	S_task1_next = 1;	% First state.
		%The default is -1 which indicates stay in same state
	return;
end

% This task runs at specific times. If current time has not reached
% the scheduled run time, just return.
if tstep < Ttask1
	return;
end

Ttask1 = Ttask1 + Tdelta;	% Time for next run -- in this case
	% the task runs at regular intervals, but that needn't
	% be true all the time.

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

% Run the code associated with the current state
if S_task1 == 1
	% Entry section
	if run_entry % Only run this on entry to the state
		% code for entry section goes here (if any)
	end
	% Action section
		% code for action section goes here (if any)
	%Test/exit section 
	if s1_test	% Test for first possible transition
			% this could be a separate function or
			% in-line code.
		% A new state has been requested
		S_task1_next = 2; % Specify the next state

		% Exit section
			% code for exit section (if any)
	end

	% Similar code goes here for additional transitions
	% associated with this state.

% Code for another state
elseif S_task1 == 2
% ... Repeat this pattern for as many states as there are
% in this task


else	% Check for a state variable value that doesn't
	% correspond to a defined state.
	error('Task: Task1 -- unknown state encountered');
end

⌨️ 快捷键说明

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