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

📄 c_templ.m

📁 Matlab学习课件
💻 M
字号:
% Template for Matlab mechatronics control programs
% File: c_templ.m
% Created 7/22/95 by DM Auslander

glbl_var	% Read in global definitions -- because each function
	%in Matlab requires a new file, this is a more compact
	%way to share variables

% System setup and initialization
% Put initial values for all variables here

% Simulation parameter values
tfinal = 30;
del_t = 0.2;
ept = del_t / 100;	% Used to check for round-off errors
nsteps = ceil(tfinal / del_t);

% Use this to control the number of output values
t_outint = 0.2;	% Time interval for outputs
		% This is particularly important for the student edition!
nouts = ceil(tfinal / t_outint);
yout = zeros(nouts + 1,4); % Set this up for proper output dimension
tout = zeros(nouts + 1,1);
t_outnext = 0;	% Time at which next output will be copied
iout = 1;		% Index for outputs
tstep = 0;		% Running time

% Set up the options for the differential equation solver
% (if one is being used). The lines given here use a modified
% version of "Odesuite"
ode_opts = odeset('refine',0,'rtol',1.e-3);	% Differential solver options

% Make up a task list using the string-matrix function, str2mat()
% Note that this can only take 11 strings in each call, so it must be called
% multiple times for more than 11 tasks
% Each name represents a function (file) for that task

t1 = str2mat('task1','task2','task3');
tasks = str2mat(t1);
nn = size(tasks);
ntasks = nn(1);		% Number of rows in 'tasks'

% Set initial states
Stask1 = 0;	% A state of 0 is used as a a flag to the
Stask2 = 0;	% state to do whatever initialization it needs
Stask3 = 0;

% Initialize all the tasks
for j = 1:ntasks
	tsk = tasks(j,:);	% name of j-th task
	feval(tsk);	% No arguments - task takes care of state
			% and when it runs internally.
end

i_audit = 1;	% Index for transition audit trail

% Step out the solution

for i = 1:nsteps
	% Copy output values to the output array
	if (tstep + ept) >= t_outnext
		t_outnext = t_outnext + t_outint;	% Time for next output
		yout(iout,1) = out1;
		yout(iout,2) = out2;
		yout(iout,3) = out3;
		yout(iout,4) = out4;
		tout(iout) = tstep; % Record current time
		iout = iout + 1;
	end
	
	% Run the control tasks

	for j = 1:ntasks
		tsk = tasks(j,:);	% name of j-th task
		feval(tsk);	% No arguments - task takes care of state
				% and when it runs internally.
	end

	% Simulate control object over one discrete time step
	% Use of the modified Odesuite with 'hfirst' allows
	% for more efficient simulation. The 'odeeul' is
	% a one-step Euler integrator.
	[tt,xx] = odeeul('proc_sys',del_t,x,ode_opts); 
		
	tstep = tstep + del_t;
end
% Record the final output values
yout(iout,1) = out1;
yout(iout,2) = out2;
yout(iout,3) = out3;
yout(iout,4) = out4;
tout(iout) = tstep;

⌨️ 快捷键说明

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