資源簡介
這是一個系統建模的實例,是基于小球平衡的,用matlab做的界面以及寫的相關程序
代碼片段和文件信息
function?ballbeam(action)
%?BALLBEAM?demonsrates?Proportional-Derivative?(PD)?control?as?applied?to?a
%?ball?and?beam?demonstration?experiment.?Execute?by?calling?with?no?arguments.
%
%?P?and?PD?controllers?are?implemented?which?manipulates?the?beam?angle?in
%?response?to?the?position?of?the?ball?on?the?beam.?The?setpoint?is?indicated
%?by?the?red?marker?and?is?adjusted?using?the?slider?at?the?bottom?of?the?figure.
%?The?control?gain?Kc?and?the?Derivative?Time?constant?Td?are?adjusted?by
%?a?sliders?located?in?the?right?hand?control?panel.
%
%?This?demo?has?been?tested?on?Matlab?5.3?and?Matlab?6.0.?Some?of?the?user
%?interface?code?was?shamelessly?ripped?out?of?the?standard?Matlab?demos.
%
%?Jeff?Kantor
%?Version?1.0
%?March?24?2001
if?nargin?1
????action?=?‘initialize‘;
end
persistent?ballradius?beamlength?beamwidth
persistent?xmin?xmax?umin?umax?g?dt?
persistent?t?x?v?u?done
persistent?Kc?Td?N?xsp?xlast?dterm?Ad?Bd
persistent?ballHndl?xball?yball?
persistent?beamHndl?xbeam?ybeam
persistent?markerHndl?xmarker?ymarker
persistent?setpointHndl
persistent?runHndl?resetHndl?stopHndl?closeHndl?infoHndl
persistent?gainHndl?gaintxtHndl?gainlblHndl
persistent?dervHndl?dervtxtHndl?dervlblHndl
persistent?manualHndl?modeHndl?mode
persistent?bbAxes?plotAxes?plotHndl?legHndl?tdata?xdata?xspdata
switch?lower(action)
case?{‘initialize‘}
????
????%?Basic?dimensions.
????
????ballradius?=?1;
????beamlength?=?20;
????beamwidth?=?0.3;
????
????%?System?parameters
????
????xmin?=?0;???????????????????%?Left?limit
????xmax?=?beamlength;??????????%?Right?limit
????umin?=?-0.25;???????????????%?Minimum?beam?angle
????umax?=?0.25;????????????????%?Maximum?beam?angle
????g?=?0.05;???????????????????%?Gravitational?Constant
????dt?=?0.2;???????????????????%?Time?Step
????%?Set?initial?conditions?for?ball?and?beam?position
????t?=?0;??????????????????????%?Initial?time
????x?=?beamlength/2;???????????%?Initial?Ball?position
????v?=?0;??????????????????????%?Initial?Velocity
????u?=?0;??????????????????????%?Initial?beam?angle
????done?=?0;???????????????????%?Done?Flag
????%?Setup?controller?with?initial?parameters
????mode?=?1;???????????????????%?Flag?start?in?manual?mode
????????????????????????????????%???Mode?==?1?=>?Manual
????????????????????????????????%???Mode?==?2?=>?Proportional
????????????????????????????????%???Mode?==?3?=>?PD
????Kc?=?0.1;???????????????????%?Proportional?Gain
????Td?=?20;????????????????????%?Derivative?time?constant
????N?=?10;?????????????????????%?Maximum?derivative?gain
????xsp?=?x;????????????????????%?Initial?setpoint
????xlast?=?x;??????????????????%?Last?measured?value
????dterm?=?0;??????????????????%?Derivative?term
????Ad?=?Td/(Td+N*dt);??????????%?Derivative?filter?constant
????Bd?=?Kc*Td*N/(Td+N*dt);?????%?Derivative?gain
????
????%?Create?figure
????figNumber?=?figure(?...
????????‘Name‘‘Ball?&?Beam?Demo‘?...
????????‘NumberTit
- 上一篇:canny邊緣檢測算法的matlab實現
- 下一篇:MATLAB QR分解
評論
共有 條評論