https://wiki.octave.org/wiki/api.php?action=feedcontributions&user=178.5.170.67&feedformat=atom
Octave - User contributions [en]
2024-03-29T09:38:33Z
User contributions
MediaWiki 1.39.2
https://wiki.octave.org/wiki/index.php?title=Control_package&diff=9800
Control package
2017-02-02T15:55:58Z
<p>178.5.170.67: Added not listed sgrid function (not implemented)</p>
<hr />
<div>The {{Forge|control}} package is part of the [[Octave Forge]] project.<br />
<br />
== Function list ==<br />
<br />
=== Linear System Representation ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Chapter !! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| rowspan="11" | Basic Models || tf || style="background: green;" | yes || @tf/tf.m || || || ||<br />
|-<br />
| zpk || style="background: green;" | yes || zpk.m || || || ||<br />
|-<br />
| ss || style="background: green;" | yes || @ss/ss.m || || || ||<br />
|-<br />
| frd || style="background: green;" | yes || @frd/frd.m || || || ||<br />
|- <br />
| pid || style="background: red;" | no || || || || ||<br />
|-<br />
| pidstd || style="background: red;" | no || || || || ||<br />
|-<br />
| pid2 || style="background: red;" | no || || || || ||<br />
|-<br />
| dss || style="background: green;" | yes || @lti/dss.m || || || ||<br />
|-<br />
| drss || style="background: red;" | no || || || || ||<br />
|-<br />
| filt || style="background: green;" | yes || filt.m || || || ||<br />
|-<br />
| rss || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="24" | Tunable Models || ltiblock.gain || style="background: red;" | no || || || || ||<br />
|-<br />
| ltiblock.pid || style="background: red;" | no || || || || ||<br />
|-<br />
| ltiblock.pid2 || style="background: red;" | no || || || || ||<br />
|-<br />
| ltiblock.ss || style="background: red;" | no || || || || ||<br />
|-<br />
| ltiblock.tf || style="background: red;" | no || || || || ||<br />
|-<br />
| realp || style="background: red;" | no || || || || ||<br />
|-<br />
| AnalysisPoint || style="background: red;" | no || || || || ||<br />
|-<br />
| genss || style="background: red;" | no || || || || ||<br />
|-<br />
| genfrd || style="background: red;" | no || || || || ||<br />
|-<br />
| genmat || style="background: red;" | no || || || || ||<br />
|-<br />
| getLoopTransfer || style="background: red;" | no || || || || ||<br />
|-<br />
| getIOTransfer || style="background: red;" | no || || || || ||<br />
|-<br />
| getSensitivity || style="background: red;" | no || || || || ||<br />
|-<br />
| getCompSensitivity || style="background: red;" | no || || || || ||<br />
|-<br />
| getPoints || style="background: red;" | no || || || || ||<br />
|-<br />
| replaceBlock || style="background: red;" | no || || || || ||<br />
|-<br />
| getValue || style="background: red;" | no || || || || ||<br />
|-<br />
| setValue || style="background: red;" | no || || || || ||<br />
|-<br />
| getBlockValue || style="background: red;" | no || || || || ||<br />
|-<br />
| setBlockValue || style="background: red;" | no || || || || ||<br />
|-<br />
| showBlockValue || style="background: red;" | no || || || || ||<br />
|-<br />
| showTunable || style="background: red;" | no || || || || ||<br />
|-<br />
| nblocks || style="background: red;" | no || || || || ||<br />
|-<br />
| getLFTModel || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="9" | Model with Time Delays || pade || style="background: red;" | no || || || || ||<br />
|-<br />
| absorbDelay || style="background: red;" | no || || || || ||<br />
|-<br />
| thiran || style="background: green;" | yes || thiran.m || || || ||<br />
|-<br />
| hasdelay || style="background: red;" | no || || || || ||<br />
|-<br />
| hasInternalDelay || style="background: red;" | no || || || || ||<br />
|-<br />
| totaldelay || style="background: red;" | no || || || || ||<br />
|-<br />
| delayss || style="background: red;" | no || || || || ||<br />
|-<br />
| setDelayModel || style="background: red;" | no || || || || ||<br />
|-<br />
| getDelayModel || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="26" | Model Attributes || get || style="background: green;" | yes || @iddata/get.m || || || ||<br />
|-<br />
| set || style="background: green;" | yes || @iddata/set.m || || || ||<br />
|-<br />
| tfdata || style="background: green;" | yes || @lti/tfdata.m || || || ||<br />
|-<br />
| zpkdata || style="background: green;" | yes || @lti/zpkdata.m || || || ||<br />
|-<br />
| ssdata || style="background: green;" | yes || @lti/ssdata.m || || || ||<br />
|-<br />
| frdata || style="background: green;" | yes || @lti/frdata.m || || || ||<br />
|-<br />
| piddata || style="background: red;" | no || || || || ||<br />
|-<br />
| pidstddata || style="background: red;" | no || || || || ||<br />
|-<br />
| piddata2 || style="background: red;" | no || || || || ||<br />
|-<br />
| pidstddata2 || style="background: red;" | no || || || || ||<br />
|-<br />
| dssdata || style="background: green;" | yes || @lti/dssdata.m || || || ||<br />
|-<br />
| chgFreqUnit || style="background: red;" | no || || || || ||<br />
|-<br />
| chgTimeUnit || style="background: red;" | no || || || || ||<br />
|-<br />
| isct || style="background: green;" | yes || @lti/isct.m || || || ||<br />
|-<br />
| isdt || style="background: green;" | yes || @lti/isdt.m || || || ||<br />
|-<br />
| isempty || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| isfinite || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| isParametric || style="background: red;" | no || || || || ||<br />
|-<br />
| isproper || style="background: red;" | no || || || || ||<br />
|-<br />
| isreal || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| isiso || style="background: red;" | no || || || || ||<br />
|-<br />
| isstable || style="background: green;" | yes || @lti/isstable.m || || || ||<br />
|-<br />
| isstatic || style="background: red;" | no || || || || ||<br />
|-<br />
| order || style="background: red;" | no || || || || ||<br />
|-<br />
| ndims || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| size || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| rowspan="5" | Model Arrays || stack || style="background: red;" | no || || || || ||<br />
|-<br />
| nmodels || style="background: red;" | no || || || || ||<br />
|-<br />
| permute || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| reshape || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| repsys || style="background: green;" | yes || repsys.m || || || ||<br />
|-<br />
|}<br />
<br />
=== Model Interconnection ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| feedback || style="background: green;" | yes || @lti/feedback.m || || || ||<br />
|-<br />
| connect || style="background: green;" | yes || @lti/connect.m || || || ||<br />
|-<br />
| sumblk || style="background: green;" | yes || sumblk.m || || || ||<br />
|-<br />
| series || style="background: red;" | no || || || || ||<br />
|-<br />
| parallel || style="background: red;" | no || || || || ||<br />
|-<br />
| append || style="background: green;" | yes || append.m || || || ||<br />
|-<br />
| blkdiag || style="background: green;" | yes || @lti/blkdiag.m || || || ||<br />
|-<br />
| imp2exp || style="background: red;" | no || || || || ||<br />
|-<br />
| inv || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| lft || style="background: red;" | no || || || || ||<br />
|-<br />
| connectOptions || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
=== Model Transformation ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Chapter !! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| rowspan="4" | Model Type Conversion || pidstd2 || style="background: red;" | no || || || || ||<br />
|-<br />
| make1DOF || style="background: red;" | no || || || || ||<br />
|-<br />
| make2DOF || style="background: red;" | no || || || || ||<br />
|-<br />
| getComponents || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="7" | Continuous-Discrete Conversion || c2d || style="background: green;" | yes || @lti/c2d.m || || || ||<br />
|-<br />
| d2c || style="background: green;" | yes || @lti/d2c.m || || || ||<br />
|-<br />
| d2d || style="background: green;" | yes || @lti/d2d.m || || || ||<br />
|-<br />
| upsample || style="background: red;" | no || || || || ||<br />
|-<br />
| c2dOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| d2cOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| d2dOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="9" | Model Simplification || hsvd || style="background: green;" | yes || hsvd.m || || || ||<br />
|-<br />
| hsvplot || style="background: red;" | no || || || || ||<br />
|-<br />
| sminreal || style="background: green;" | yes || @lti/sminreal.m || || || ||<br />
|-<br />
| balred || style="background: red;" | no || || || || ||<br />
|-<br />
| minreal || style="background: green;" | yes || @lti/minreal.m || || || ||<br />
|-<br />
| balreal || style="background: red;" | no || || || || ||<br />
|-<br />
| modred || style="background: red;" | no || || || || ||<br />
|-<br />
| balredOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| hsvdOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="4" | State-Coordinate Transformation || canon || style="background: red;" | no || || || || ||<br />
|-<br />
| prescale || style="background: green;" | yes || @lti/prescale.m || || || ||<br />
|-<br />
| ss2ss || style="background: red;" | no || || || || ||<br />
|-<br />
| xperm || style="background: green;" | yes || @lti/xperm.m || || || ||<br />
|-<br />
| rowspan="5" | Modal Decomposition || modsep || style="background: red;" | no || || || || ||<br />
|-<br />
| stabsep || style="background: red;" | no || || || || ||<br />
|-<br />
| freqsep || style="background: red;" | no || || || || ||<br />
|-<br />
| stabsepOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| freqsepOptions || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
=== Linear Analysis ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Chapter !! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| rowspan="13" | Time-Domain Analysis || linearSystemAnalyzer || style="background: red;" | no || || || || ||<br />
|-<br />
| impulseplot || style="background: red;" | no || || || || ||<br />
|-<br />
| initialplot || style="background: red;" | no || || || || ||<br />
|-<br />
| lsimplot || style="background: red;" | no || || || || ||<br />
|-<br />
| stepplot || style="background: red;" | no || || || || ||<br />
|-<br />
| covar || style="background: green;" | yes || covar.m || || || ||<br />
|-<br />
| impulse || style="background: green;" | yes || impulse.m || || || ||<br />
|-<br />
| initial || style="background: green;" | yes || initial.m || || || ||<br />
|-<br />
| lsim || style="background: green;" | yes || lsim.m || || || ||<br />
|-<br />
| step || style="background: green;" | yes || step.m || || || ||<br />
|-<br />
| lsiminfo || style="background: red;" | no || || || || ||<br />
|-<br />
| stepinfo || style="background: red;" | no || || || || ||<br />
|-<br />
| stepDataOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="14" | Frequency-Domain Analysis || bodeplot || style="background: red;" | no || || || || ||<br />
|-<br />
| nicholsplot || style="background: red;" | no || || || || ||<br />
|-<br />
| nyquistplot || style="background: red;" | no || || || || ||<br />
|-<br />
| sigmaplot || style="background: red;" | no || || || || ||<br />
|-<br />
| bode || style="background: green;" | yes || bode.m || || || ||<br />
|-<br />
| nichols || style="background: green;" | yes || nichols.m || || || ||<br />
|-<br />
| nyquist || style="background: green;" | yes || nyquist.m || || || ||<br />
|-<br />
| sigma || style="background: green;" | yes || sigma.m || || || ||<br />
|-<br />
| evalfr || style="background: red;" | no || || || || ||<br />
|-<br />
| freqresp || style="background: green;" | yes || @lti/freqresp.m || || || ||<br />
|-<br />
| bandwidth || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| dcgain || style="background: green;" | yes || @lti/dcgain.m || || || ||<br />
|-<br />
| getGainCrossover || style="background: red;" | no || || || || ||<br />
|-<br />
| getPeakGain || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="11" | Stability Analysis || pole || style="background: green;" | yes || @lti/pole.m || || || ||<br />
|-<br />
| zero || style="background: green;" | yes || @lti/zero.m || || || ||<br />
|-<br />
| damp || style="background: red;" | no || || || || ||<br />
|-<br />
| dsort || style="background: red;" | no || || || || ||<br />
|-<br />
| esort || style="background: red;" | no || || || || ||<br />
|-<br />
| tzero || style="background: red;" | no || || || || ||<br />
|-<br />
| pzmap || style="background: green;" | yes || pzmap.m || || || ||<br />
|-<br />
| pzplot || style="background: red;" | no || || || || ||<br />
|-<br />
| iopzplot || style="background: red;" | no || || || || ||<br />
|-<br />
| allmargin || style="background: red;" | no || || || || ||<br />
|-<br />
| margin || style="background: green;" | yes || margin.m || || || ||<br />
|-<br />
| rowspan="11" | Plot Customization || bodeoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| hsvoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| nicholsoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| nyquistoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| pzoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| sigmaoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| timeoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| setoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| getoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| ctrlpref || style="background: red;" | no || || || || ||<br />
|-<br />
| updateSystem || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
=== Control Design ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Chapter !! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| rowspan="3" | PID Controller Tuning || pidTuner || style="background: red;" | no || || || || ||<br />
|-<br />
| pidtune || style="background: red;" | no || || || || ||<br />
|-<br />
| pidtuneOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="5" | SISO Feedback Loops || rlocus || style="background: green;" | yes || rlocus.m || || || ||<br />
|-<br />
| sgrid || style="background: red;" | no || || || || ||<br />
|-<br />
| rlocusplot || style="background: red;" | no || || || || ||<br />
|-<br />
| controlSystemDesigner || style="background: red;" | no || || || || ||<br />
|-<br />
| sisoinit || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="12" | Linear-Quadratic-Gaussian Control || lqr || style="background: green;" | yes || lqr.m || || || ||<br />
|-<br />
| lqry || style="background: red;" | no || || || || ||<br />
|-<br />
| lqi || style="background: red;" | no || || || || ||<br />
|-<br />
| dlqr || style="background: green;" | yes || dlqr.m || || || ||<br />
|-<br />
| lqrd || style="background: red;" | no || || || || ||<br />
|-<br />
| kalman || style="background: green;" | yes || kalman.m || || || ||<br />
|-<br />
| kalmd || style="background: red;" | no || || || || ||<br />
|-<br />
| lqg || style="background: red;" | no || || || || ||<br />
|-<br />
| lqgreg || style="background: red;" | no || || || || ||<br />
|-<br />
| lqgtrack || style="background: red;" | no || || || || ||<br />
|-<br />
| augstate || style="background: red;" | no || || || || ||<br />
|-<br />
| norm || style="background: green;" | yes || @lti/norm.m || || || ||<br />
|-<br />
| rowspan="3" | Pole Placement || estim || style="background: green;" | yes || estim.m || || || ||<br />
|-<br />
| place || style="background: green;" | yes || place.m || || || ||<br />
|-<br />
| reg || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
=== Matrix Computations ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| lyap || style="background: green;" | yes || lyap.m || || || ||<br />
|-<br />
| lyapchol || style="background: green;" | yes || lyapchol.m || || || ||<br />
|-<br />
| dlyap || style="background: green;" | yes || dlyap.m || || || ||<br />
|-<br />
| dlyapchol || style="background: green;" | yes || dlyapchol.m || || || ||<br />
|-<br />
| care || style="background: green;" | yes || care.m || || || ||<br />
|-<br />
| dare || style="background: green;" | yes || dare.m || || || ||<br />
|-<br />
| gcare || style="background: red;" | no || || || || ||<br />
|-<br />
| gdare || style="background: red;" | no || || || || ||<br />
|-<br />
| ctrb || style="background: green;" | yes || ctrb.m || || || ||<br />
|-<br />
| obsv || style="background: green;" | yes || obsv.m || || || ||<br />
|-<br />
| ctrbf || style="background: green;" | yes || ctrbf.m || || || ||<br />
|-<br />
| obsvf || style="background: green;" | yes || obsvf.m || || || ||<br />
|-<br />
| gram || style="background: green;" | yes || gram.m || || || ||<br />
|-<br />
| bdschur || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
== Examples ==<br />
<br />
=== PT1 / Low-pass filter step response ===<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating a transfer function and plotting its response|<syntaxhighlight lang="octave" style="font-size:14px"><br />
T1 = 0.4; # time constant<br />
P = tf([1], [T1 1]); # create transfer function model<br />
step(P, 2) # plot step response<br />
<br />
#add some common markers like the tangent line at the origin, which crosses lim(n->inf) f(t) at t=T1<br />
hold on<br />
plot ([0 T1], [0 1], "g")<br />
plot ([T1 T1], [0 1], "k")<br />
plot ([0 T1], [1-1/e 1-1/e], "m")<br />
hold off<br />
</syntaxhighlight>}}<br />
<br />
[[File:Pt1.png|600px]]<br />
<br />
==== Bode Diagram with TikZ/PGFplots ====<br />
<br />
We use the same system as before but we draw now with <code style="font-size:14px; border:solid lightgray 1px; padding: 2px">bode(P)</code> a bode diagram.<br />
The output is written to a .csv file.<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating a transfer function and calculating its bode diagram|<syntaxhighlight lang="octave" style="font-size:14px"><br />
T1 = 0.4; # time constant<br />
P = tf([1], [T1 1]);<br />
<br />
[mag, pha, w] = bode(P);<br />
<br />
csvwrite("dat/bode_p.csv", [w', 20*log10(mag), pha]);<br />
</syntaxhighlight>}}<br />
<br />
We can then invoke LaTeX with the following .tex file<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating a bode diagram with pgfplots|<syntaxhighlight lang="latex" style="font-size:14px"><br />
\documentclass[tikz]{standalone}<br />
\usepackage{pgfplotstable}<br />
\usepackage{siunitx}<br />
\usetikzlibrary{pgfplots.groupplots}<br />
<br />
\begin{document}<br />
\pgfplotstableread[col sep=comma]{\detokenize{/path/to/csv/file/dat/bode_p.csv}}\datatable<br />
\begin{tikzpicture}<br />
\begin{groupplot}[<br />
group style={rows=2}, <br />
width=0.8\textwidth,<br />
height=0.4\textwidth, <br />
xmajorgrids, <br />
ymajorgrids, <br />
enlarge x limits=false,<br />
xmode=log,<br />
] <br />
\nextgroupplot[<br />
title={Bode Diagram of $P$},<br />
ylabel={Magnitude / \si{\decibel}},<br />
]<br />
\addplot[blue,line width=1pt] table[x index=0,y index=1]{\datatable}; <br />
\nextgroupplot[<br />
xlabel={Frequency / \si{\radian\per\second}},<br />
ylabel={Phase / \si{\degree}},<br />
] <br />
\addplot[red,line width=1pt] table[x index=0,y index=2]{\datatable};<br />
\end{groupplot}<br />
\end{tikzpicture}<br />
\end{document}<br />
</syntaxhighlight>}}<br />
<br />
to generate a beautiful bode diagram<br />
<br />
[[File:bode_p.png]]<br />
<br />
It can be seen that a first order low-pass filter has <math display="inline">-3\,dB</math> magnitude at <math display="inline">f=1/T_1=2.5\,rad/s</math>.<br />
<br />
=== Inverted Pendulum ===<br />
<br />
==== Model ====<br />
<br />
A nonlinear model of the inverted pendulum can be derived by<br />
<br />
<math><br />
\begin{cases}<br />
(M+m)\ddot{x}+c\dot{x}-ml\cos{\theta}\ddot{\theta}+ml\sin{\theta}\dot{\theta}^2&=f(t)\\<br />
-ml\ddot{x}\cos{\theta}+(ml^2+I)\ddot{\theta}+b\dot{\theta}+mgl\sin{\theta}&=0<br />
\end{cases}\text{,}<br />
</math><br />
<br />
where the variables are defined as<br />
<br />
{|<br />
! align="left" | Name<br />
! align="left" | Definition<br />
|-<br />
|<math display="inline">M</math><br />
|Mass of the cart<br />
|-<br />
|<math display="inline">m</math><br />
|Mass of the pendulum<br />
|-<br />
|<math display="inline">c</math><br />
|Translational damping coefficient<br />
|-<br />
|<math display="inline">l</math><br />
|Length of the pendulum<br />
|-<br />
|<math display="inline">I</math><br />
|Inertia of the pendulum<br />
|-<br />
|<math display="inline">b</math><br />
|Rotational damping coefficient<br />
|}<br />
<br />
[[File:inverted_pendulum_new.png|frame|Schematic drawing of the inverted pendulum.]]<br />
<br />
Linearization around the point <math display="inline">\theta=\pi</math> and substitution of <math display="inline">\theta'=\theta-\pi</math> (from here on in the analysis, <math display="inline">\theta'</math> will be written as <math display="inline">\theta</math>, but it should be noted that <math display="inline">\theta</math> now<br />
measures from a new reference) leads to<br />
<br />
<math><br />
\begin{cases}<br />
(M+m)\ddot{x}+c\dot{x}+ml\ddot{\theta}&=f(t)\\<br />
ml\dot{x}+(ml^2+I)\ddot{\theta}+b\dot{\theta}-mgl\theta&=0<br />
\end{cases}\text{.}<br />
</math><br />
<br />
This can be expressed in the frequency domain like<br />
<br />
<math><br />
\begin{cases}<br />
(M+m)s^2X(s)+csX(s)+mls^2\Theta(s)&=F(s)\\<br />
mlsX(s)+(ml^2+I)s^2\Theta(s)+bs\Theta(s)-mgl\Theta(s)&=0<br />
\end{cases}<br />
</math><br />
<br />
==== Transfer functions ====<br />
<br />
By dividing the state variables by the input one obtains the transfer functions<br />
<br />
<math><br />
\begin{align}<br />
G_1(s)&=\frac{X(s)}{F(s)}=\frac{\alpha_2s^2+\alpha_1s+\alpha_0}{\beta_4s^4+\beta_3s^3+\beta_2s^2+\beta_1s}\\<br />
G_2(s)&=\frac{\Theta(s)}{F(s)}=\frac{\gamma_1s}{\beta_4s^3+\beta_3s^2+\beta_2s+\beta_1}<br />
\end{align}<br />
</math><br />
<br />
with<br />
<br />
{|<br />
|<math display="inline">\alpha_2=ml^2+I</math><br />
|-<br />
|<math display="inline">\alpha_1=b</math><br />
|-<br />
|<math display="inline">\alpha_0=-mgl</math><br />
|-<br />
|<math display="inline">\beta_4=(M+m)(ml^2+I)-m^2l^2</math><br />
|-<br />
|<math display="inline">\beta_3=(M+m)b+(ml^2+I)c</math><br />
|-<br />
|<math display="inline">\beta_2=-(M+m)mgl+bc</math><br />
|-<br />
|<math display="inline">\beta_1=-mglc</math><br />
|-<br />
|<math display="inline">\gamma_1=-ml</math><br />
|}<br />
<br />
This can be expressed in Octave<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating the transfer functions for the inverted pendulum|<syntaxhighlight lang="octave" style="font-size:14px"><br />
m = 0.15;<br />
l = 0.314;<br />
M = 1.3;<br />
I = 0;<br />
g = 9.80665;<br />
b = 20;<br />
c = 20;<br />
<br />
G1 = tf([m*l^2+I b -m*g*l],<br />
[(M+m)*(m*l^2+I)-m^2*l^2 (M+m)*b+(m*l^2+I)*c -(M+m)*m*g*l+b*c -m*g*l*c 0]);<br />
G2 = tf([-m*l],<br />
[(M+m)*(m*l^2+I)-m^2*l^2 (M+m)*b+(m*l^2+I)*c -(M+m)*m*g*l+b*c -m*g*l*c]);<br />
</syntaxhighlight>}}<br />
<br />
and by invoking the <code style="font-size:14px; border:solid lightgray 1px; padding: 2px">bode</code> command<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating Bode plots for the inverted pendulum|<syntaxhighlight lang="octave" style="font-size:14px"><br />
bode(G1);<br />
bode(G2);<br />
</syntaxhighlight>}}<br />
<br />
one obtains the bode diagrams of the two transfer functions.<br />
<br />
<div><ul><br />
<li style="display: inline-block;"> [[File:bode_g1.png|frame|Bode diagram of the cart movement transfer function.]] </li><br />
<li style="display: inline-block;"> [[File:bode_g2.png|frame|Bode diagram of the pendulums rotation transfer function.]] </li><br />
</ul></div><br />
<br />
==References==<br />
<references /><br />
<br />
<br />
[[Category:Octave-Forge]]</div>
178.5.170.67
https://wiki.octave.org/wiki/index.php?title=Control_package&diff=9799
Control package
2017-02-02T15:50:10Z
<p>178.5.170.67: Added not listed pzmap function (which is already implemented)</p>
<hr />
<div>The {{Forge|control}} package is part of the [[Octave Forge]] project.<br />
<br />
== Function list ==<br />
<br />
=== Linear System Representation ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Chapter !! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| rowspan="11" | Basic Models || tf || style="background: green;" | yes || @tf/tf.m || || || ||<br />
|-<br />
| zpk || style="background: green;" | yes || zpk.m || || || ||<br />
|-<br />
| ss || style="background: green;" | yes || @ss/ss.m || || || ||<br />
|-<br />
| frd || style="background: green;" | yes || @frd/frd.m || || || ||<br />
|- <br />
| pid || style="background: red;" | no || || || || ||<br />
|-<br />
| pidstd || style="background: red;" | no || || || || ||<br />
|-<br />
| pid2 || style="background: red;" | no || || || || ||<br />
|-<br />
| dss || style="background: green;" | yes || @lti/dss.m || || || ||<br />
|-<br />
| drss || style="background: red;" | no || || || || ||<br />
|-<br />
| filt || style="background: green;" | yes || filt.m || || || ||<br />
|-<br />
| rss || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="24" | Tunable Models || ltiblock.gain || style="background: red;" | no || || || || ||<br />
|-<br />
| ltiblock.pid || style="background: red;" | no || || || || ||<br />
|-<br />
| ltiblock.pid2 || style="background: red;" | no || || || || ||<br />
|-<br />
| ltiblock.ss || style="background: red;" | no || || || || ||<br />
|-<br />
| ltiblock.tf || style="background: red;" | no || || || || ||<br />
|-<br />
| realp || style="background: red;" | no || || || || ||<br />
|-<br />
| AnalysisPoint || style="background: red;" | no || || || || ||<br />
|-<br />
| genss || style="background: red;" | no || || || || ||<br />
|-<br />
| genfrd || style="background: red;" | no || || || || ||<br />
|-<br />
| genmat || style="background: red;" | no || || || || ||<br />
|-<br />
| getLoopTransfer || style="background: red;" | no || || || || ||<br />
|-<br />
| getIOTransfer || style="background: red;" | no || || || || ||<br />
|-<br />
| getSensitivity || style="background: red;" | no || || || || ||<br />
|-<br />
| getCompSensitivity || style="background: red;" | no || || || || ||<br />
|-<br />
| getPoints || style="background: red;" | no || || || || ||<br />
|-<br />
| replaceBlock || style="background: red;" | no || || || || ||<br />
|-<br />
| getValue || style="background: red;" | no || || || || ||<br />
|-<br />
| setValue || style="background: red;" | no || || || || ||<br />
|-<br />
| getBlockValue || style="background: red;" | no || || || || ||<br />
|-<br />
| setBlockValue || style="background: red;" | no || || || || ||<br />
|-<br />
| showBlockValue || style="background: red;" | no || || || || ||<br />
|-<br />
| showTunable || style="background: red;" | no || || || || ||<br />
|-<br />
| nblocks || style="background: red;" | no || || || || ||<br />
|-<br />
| getLFTModel || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="9" | Model with Time Delays || pade || style="background: red;" | no || || || || ||<br />
|-<br />
| absorbDelay || style="background: red;" | no || || || || ||<br />
|-<br />
| thiran || style="background: green;" | yes || thiran.m || || || ||<br />
|-<br />
| hasdelay || style="background: red;" | no || || || || ||<br />
|-<br />
| hasInternalDelay || style="background: red;" | no || || || || ||<br />
|-<br />
| totaldelay || style="background: red;" | no || || || || ||<br />
|-<br />
| delayss || style="background: red;" | no || || || || ||<br />
|-<br />
| setDelayModel || style="background: red;" | no || || || || ||<br />
|-<br />
| getDelayModel || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="26" | Model Attributes || get || style="background: green;" | yes || @iddata/get.m || || || ||<br />
|-<br />
| set || style="background: green;" | yes || @iddata/set.m || || || ||<br />
|-<br />
| tfdata || style="background: green;" | yes || @lti/tfdata.m || || || ||<br />
|-<br />
| zpkdata || style="background: green;" | yes || @lti/zpkdata.m || || || ||<br />
|-<br />
| ssdata || style="background: green;" | yes || @lti/ssdata.m || || || ||<br />
|-<br />
| frdata || style="background: green;" | yes || @lti/frdata.m || || || ||<br />
|-<br />
| piddata || style="background: red;" | no || || || || ||<br />
|-<br />
| pidstddata || style="background: red;" | no || || || || ||<br />
|-<br />
| piddata2 || style="background: red;" | no || || || || ||<br />
|-<br />
| pidstddata2 || style="background: red;" | no || || || || ||<br />
|-<br />
| dssdata || style="background: green;" | yes || @lti/dssdata.m || || || ||<br />
|-<br />
| chgFreqUnit || style="background: red;" | no || || || || ||<br />
|-<br />
| chgTimeUnit || style="background: red;" | no || || || || ||<br />
|-<br />
| isct || style="background: green;" | yes || @lti/isct.m || || || ||<br />
|-<br />
| isdt || style="background: green;" | yes || @lti/isdt.m || || || ||<br />
|-<br />
| isempty || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| isfinite || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| isParametric || style="background: red;" | no || || || || ||<br />
|-<br />
| isproper || style="background: red;" | no || || || || ||<br />
|-<br />
| isreal || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| isiso || style="background: red;" | no || || || || ||<br />
|-<br />
| isstable || style="background: green;" | yes || @lti/isstable.m || || || ||<br />
|-<br />
| isstatic || style="background: red;" | no || || || || ||<br />
|-<br />
| order || style="background: red;" | no || || || || ||<br />
|-<br />
| ndims || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| size || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| rowspan="5" | Model Arrays || stack || style="background: red;" | no || || || || ||<br />
|-<br />
| nmodels || style="background: red;" | no || || || || ||<br />
|-<br />
| permute || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| reshape || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| repsys || style="background: green;" | yes || repsys.m || || || ||<br />
|-<br />
|}<br />
<br />
=== Model Interconnection ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| feedback || style="background: green;" | yes || @lti/feedback.m || || || ||<br />
|-<br />
| connect || style="background: green;" | yes || @lti/connect.m || || || ||<br />
|-<br />
| sumblk || style="background: green;" | yes || sumblk.m || || || ||<br />
|-<br />
| series || style="background: red;" | no || || || || ||<br />
|-<br />
| parallel || style="background: red;" | no || || || || ||<br />
|-<br />
| append || style="background: green;" | yes || append.m || || || ||<br />
|-<br />
| blkdiag || style="background: green;" | yes || @lti/blkdiag.m || || || ||<br />
|-<br />
| imp2exp || style="background: red;" | no || || || || ||<br />
|-<br />
| inv || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| lft || style="background: red;" | no || || || || ||<br />
|-<br />
| connectOptions || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
=== Model Transformation ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Chapter !! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| rowspan="4" | Model Type Conversion || pidstd2 || style="background: red;" | no || || || || ||<br />
|-<br />
| make1DOF || style="background: red;" | no || || || || ||<br />
|-<br />
| make2DOF || style="background: red;" | no || || || || ||<br />
|-<br />
| getComponents || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="7" | Continuous-Discrete Conversion || c2d || style="background: green;" | yes || @lti/c2d.m || || || ||<br />
|-<br />
| d2c || style="background: green;" | yes || @lti/d2c.m || || || ||<br />
|-<br />
| d2d || style="background: green;" | yes || @lti/d2d.m || || || ||<br />
|-<br />
| upsample || style="background: red;" | no || || || || ||<br />
|-<br />
| c2dOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| d2cOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| d2dOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="9" | Model Simplification || hsvd || style="background: green;" | yes || hsvd.m || || || ||<br />
|-<br />
| hsvplot || style="background: red;" | no || || || || ||<br />
|-<br />
| sminreal || style="background: green;" | yes || @lti/sminreal.m || || || ||<br />
|-<br />
| balred || style="background: red;" | no || || || || ||<br />
|-<br />
| minreal || style="background: green;" | yes || @lti/minreal.m || || || ||<br />
|-<br />
| balreal || style="background: red;" | no || || || || ||<br />
|-<br />
| modred || style="background: red;" | no || || || || ||<br />
|-<br />
| balredOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| hsvdOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="4" | State-Coordinate Transformation || canon || style="background: red;" | no || || || || ||<br />
|-<br />
| prescale || style="background: green;" | yes || @lti/prescale.m || || || ||<br />
|-<br />
| ss2ss || style="background: red;" | no || || || || ||<br />
|-<br />
| xperm || style="background: green;" | yes || @lti/xperm.m || || || ||<br />
|-<br />
| rowspan="5" | Modal Decomposition || modsep || style="background: red;" | no || || || || ||<br />
|-<br />
| stabsep || style="background: red;" | no || || || || ||<br />
|-<br />
| freqsep || style="background: red;" | no || || || || ||<br />
|-<br />
| stabsepOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| freqsepOptions || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
=== Linear Analysis ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Chapter !! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| rowspan="13" | Time-Domain Analysis || linearSystemAnalyzer || style="background: red;" | no || || || || ||<br />
|-<br />
| impulseplot || style="background: red;" | no || || || || ||<br />
|-<br />
| initialplot || style="background: red;" | no || || || || ||<br />
|-<br />
| lsimplot || style="background: red;" | no || || || || ||<br />
|-<br />
| stepplot || style="background: red;" | no || || || || ||<br />
|-<br />
| covar || style="background: green;" | yes || covar.m || || || ||<br />
|-<br />
| impulse || style="background: green;" | yes || impulse.m || || || ||<br />
|-<br />
| initial || style="background: green;" | yes || initial.m || || || ||<br />
|-<br />
| lsim || style="background: green;" | yes || lsim.m || || || ||<br />
|-<br />
| step || style="background: green;" | yes || step.m || || || ||<br />
|-<br />
| lsiminfo || style="background: red;" | no || || || || ||<br />
|-<br />
| stepinfo || style="background: red;" | no || || || || ||<br />
|-<br />
| stepDataOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="14" | Frequency-Domain Analysis || bodeplot || style="background: red;" | no || || || || ||<br />
|-<br />
| nicholsplot || style="background: red;" | no || || || || ||<br />
|-<br />
| nyquistplot || style="background: red;" | no || || || || ||<br />
|-<br />
| sigmaplot || style="background: red;" | no || || || || ||<br />
|-<br />
| bode || style="background: green;" | yes || bode.m || || || ||<br />
|-<br />
| nichols || style="background: green;" | yes || nichols.m || || || ||<br />
|-<br />
| nyquist || style="background: green;" | yes || nyquist.m || || || ||<br />
|-<br />
| sigma || style="background: green;" | yes || sigma.m || || || ||<br />
|-<br />
| evalfr || style="background: red;" | no || || || || ||<br />
|-<br />
| freqresp || style="background: green;" | yes || @lti/freqresp.m || || || ||<br />
|-<br />
| bandwidth || style="background: green;" | yes || built-in function || || || ||<br />
|-<br />
| dcgain || style="background: green;" | yes || @lti/dcgain.m || || || ||<br />
|-<br />
| getGainCrossover || style="background: red;" | no || || || || ||<br />
|-<br />
| getPeakGain || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="11" | Stability Analysis || pole || style="background: green;" | yes || @lti/pole.m || || || ||<br />
|-<br />
| zero || style="background: green;" | yes || @lti/zero.m || || || ||<br />
|-<br />
| damp || style="background: red;" | no || || || || ||<br />
|-<br />
| dsort || style="background: red;" | no || || || || ||<br />
|-<br />
| esort || style="background: red;" | no || || || || ||<br />
|-<br />
| tzero || style="background: red;" | no || || || || ||<br />
|-<br />
| pzmap || style="background: green;" | yes || pzmap.m || || || ||<br />
|-<br />
| pzplot || style="background: red;" | no || || || || ||<br />
|-<br />
| iopzplot || style="background: red;" | no || || || || ||<br />
|-<br />
| allmargin || style="background: red;" | no || || || || ||<br />
|-<br />
| margin || style="background: green;" | yes || margin.m || || || ||<br />
|-<br />
| rowspan="11" | Plot Customization || bodeoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| hsvoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| nicholsoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| nyquistoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| pzoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| sigmaoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| timeoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| setoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| getoptions || style="background: red;" | no || || || || ||<br />
|-<br />
| ctrlpref || style="background: red;" | no || || || || ||<br />
|-<br />
| updateSystem || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
=== Control Design ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Chapter !! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| rowspan="3" | PID Controller Tuning || pidTuner || style="background: red;" | no || || || || ||<br />
|-<br />
| pidtune || style="background: red;" | no || || || || ||<br />
|-<br />
| pidtuneOptions || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="4" | SISO Feedback Loops || rlocus || style="background: green;" | yes || rlocus.m || || || ||<br />
|-<br />
| rlocusplot || style="background: red;" | no || || || || ||<br />
|-<br />
| controlSystemDesigner || style="background: red;" | no || || || || ||<br />
|-<br />
| sisoinit || style="background: red;" | no || || || || ||<br />
|-<br />
| rowspan="12" | Linear-Quadratic-Gaussian Control || lqr || style="background: green;" | yes || lqr.m || || || ||<br />
|-<br />
| lqry || style="background: red;" | no || || || || ||<br />
|-<br />
| lqi || style="background: red;" | no || || || || ||<br />
|-<br />
| dlqr || style="background: green;" | yes || dlqr.m || || || ||<br />
|-<br />
| lqrd || style="background: red;" | no || || || || ||<br />
|-<br />
| kalman || style="background: green;" | yes || kalman.m || || || ||<br />
|-<br />
| kalmd || style="background: red;" | no || || || || ||<br />
|-<br />
| lqg || style="background: red;" | no || || || || ||<br />
|-<br />
| lqgreg || style="background: red;" | no || || || || ||<br />
|-<br />
| lqgtrack || style="background: red;" | no || || || || ||<br />
|-<br />
| augstate || style="background: red;" | no || || || || ||<br />
|-<br />
| norm || style="background: green;" | yes || @lti/norm.m || || || ||<br />
|-<br />
| rowspan="3" | Pole Placement || estim || style="background: green;" | yes || estim.m || || || ||<br />
|-<br />
| place || style="background: green;" | yes || place.m || || || ||<br />
|-<br />
| reg || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
=== Matrix Computations ===<br />
<br />
{| class="wikitable" <br />
|-<br />
! Function !! Implemented !! File !! Number of Tests !! Status !! SLICOT functions !! Priority (0-2)<br />
|-<br />
| lyap || style="background: green;" | yes || lyap.m || || || ||<br />
|-<br />
| lyapchol || style="background: green;" | yes || lyapchol.m || || || ||<br />
|-<br />
| dlyap || style="background: green;" | yes || dlyap.m || || || ||<br />
|-<br />
| dlyapchol || style="background: green;" | yes || dlyapchol.m || || || ||<br />
|-<br />
| care || style="background: green;" | yes || care.m || || || ||<br />
|-<br />
| dare || style="background: green;" | yes || dare.m || || || ||<br />
|-<br />
| gcare || style="background: red;" | no || || || || ||<br />
|-<br />
| gdare || style="background: red;" | no || || || || ||<br />
|-<br />
| ctrb || style="background: green;" | yes || ctrb.m || || || ||<br />
|-<br />
| obsv || style="background: green;" | yes || obsv.m || || || ||<br />
|-<br />
| ctrbf || style="background: green;" | yes || ctrbf.m || || || ||<br />
|-<br />
| obsvf || style="background: green;" | yes || obsvf.m || || || ||<br />
|-<br />
| gram || style="background: green;" | yes || gram.m || || || ||<br />
|-<br />
| bdschur || style="background: red;" | no || || || || ||<br />
|-<br />
|}<br />
<br />
== Examples ==<br />
<br />
=== PT1 / Low-pass filter step response ===<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating a transfer function and plotting its response|<syntaxhighlight lang="octave" style="font-size:14px"><br />
T1 = 0.4; # time constant<br />
P = tf([1], [T1 1]); # create transfer function model<br />
step(P, 2) # plot step response<br />
<br />
#add some common markers like the tangent line at the origin, which crosses lim(n->inf) f(t) at t=T1<br />
hold on<br />
plot ([0 T1], [0 1], "g")<br />
plot ([T1 T1], [0 1], "k")<br />
plot ([0 T1], [1-1/e 1-1/e], "m")<br />
hold off<br />
</syntaxhighlight>}}<br />
<br />
[[File:Pt1.png|600px]]<br />
<br />
==== Bode Diagram with TikZ/PGFplots ====<br />
<br />
We use the same system as before but we draw now with <code style="font-size:14px; border:solid lightgray 1px; padding: 2px">bode(P)</code> a bode diagram.<br />
The output is written to a .csv file.<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating a transfer function and calculating its bode diagram|<syntaxhighlight lang="octave" style="font-size:14px"><br />
T1 = 0.4; # time constant<br />
P = tf([1], [T1 1]);<br />
<br />
[mag, pha, w] = bode(P);<br />
<br />
csvwrite("dat/bode_p.csv", [w', 20*log10(mag), pha]);<br />
</syntaxhighlight>}}<br />
<br />
We can then invoke LaTeX with the following .tex file<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating a bode diagram with pgfplots|<syntaxhighlight lang="latex" style="font-size:14px"><br />
\documentclass[tikz]{standalone}<br />
\usepackage{pgfplotstable}<br />
\usepackage{siunitx}<br />
\usetikzlibrary{pgfplots.groupplots}<br />
<br />
\begin{document}<br />
\pgfplotstableread[col sep=comma]{\detokenize{/path/to/csv/file/dat/bode_p.csv}}\datatable<br />
\begin{tikzpicture}<br />
\begin{groupplot}[<br />
group style={rows=2}, <br />
width=0.8\textwidth,<br />
height=0.4\textwidth, <br />
xmajorgrids, <br />
ymajorgrids, <br />
enlarge x limits=false,<br />
xmode=log,<br />
] <br />
\nextgroupplot[<br />
title={Bode Diagram of $P$},<br />
ylabel={Magnitude / \si{\decibel}},<br />
]<br />
\addplot[blue,line width=1pt] table[x index=0,y index=1]{\datatable}; <br />
\nextgroupplot[<br />
xlabel={Frequency / \si{\radian\per\second}},<br />
ylabel={Phase / \si{\degree}},<br />
] <br />
\addplot[red,line width=1pt] table[x index=0,y index=2]{\datatable};<br />
\end{groupplot}<br />
\end{tikzpicture}<br />
\end{document}<br />
</syntaxhighlight>}}<br />
<br />
to generate a beautiful bode diagram<br />
<br />
[[File:bode_p.png]]<br />
<br />
It can be seen that a first order low-pass filter has <math display="inline">-3\,dB</math> magnitude at <math display="inline">f=1/T_1=2.5\,rad/s</math>.<br />
<br />
=== Inverted Pendulum ===<br />
<br />
==== Model ====<br />
<br />
A nonlinear model of the inverted pendulum can be derived by<br />
<br />
<math><br />
\begin{cases}<br />
(M+m)\ddot{x}+c\dot{x}-ml\cos{\theta}\ddot{\theta}+ml\sin{\theta}\dot{\theta}^2&=f(t)\\<br />
-ml\ddot{x}\cos{\theta}+(ml^2+I)\ddot{\theta}+b\dot{\theta}+mgl\sin{\theta}&=0<br />
\end{cases}\text{,}<br />
</math><br />
<br />
where the variables are defined as<br />
<br />
{|<br />
! align="left" | Name<br />
! align="left" | Definition<br />
|-<br />
|<math display="inline">M</math><br />
|Mass of the cart<br />
|-<br />
|<math display="inline">m</math><br />
|Mass of the pendulum<br />
|-<br />
|<math display="inline">c</math><br />
|Translational damping coefficient<br />
|-<br />
|<math display="inline">l</math><br />
|Length of the pendulum<br />
|-<br />
|<math display="inline">I</math><br />
|Inertia of the pendulum<br />
|-<br />
|<math display="inline">b</math><br />
|Rotational damping coefficient<br />
|}<br />
<br />
[[File:inverted_pendulum_new.png|frame|Schematic drawing of the inverted pendulum.]]<br />
<br />
Linearization around the point <math display="inline">\theta=\pi</math> and substitution of <math display="inline">\theta'=\theta-\pi</math> (from here on in the analysis, <math display="inline">\theta'</math> will be written as <math display="inline">\theta</math>, but it should be noted that <math display="inline">\theta</math> now<br />
measures from a new reference) leads to<br />
<br />
<math><br />
\begin{cases}<br />
(M+m)\ddot{x}+c\dot{x}+ml\ddot{\theta}&=f(t)\\<br />
ml\dot{x}+(ml^2+I)\ddot{\theta}+b\dot{\theta}-mgl\theta&=0<br />
\end{cases}\text{.}<br />
</math><br />
<br />
This can be expressed in the frequency domain like<br />
<br />
<math><br />
\begin{cases}<br />
(M+m)s^2X(s)+csX(s)+mls^2\Theta(s)&=F(s)\\<br />
mlsX(s)+(ml^2+I)s^2\Theta(s)+bs\Theta(s)-mgl\Theta(s)&=0<br />
\end{cases}<br />
</math><br />
<br />
==== Transfer functions ====<br />
<br />
By dividing the state variables by the input one obtains the transfer functions<br />
<br />
<math><br />
\begin{align}<br />
G_1(s)&=\frac{X(s)}{F(s)}=\frac{\alpha_2s^2+\alpha_1s+\alpha_0}{\beta_4s^4+\beta_3s^3+\beta_2s^2+\beta_1s}\\<br />
G_2(s)&=\frac{\Theta(s)}{F(s)}=\frac{\gamma_1s}{\beta_4s^3+\beta_3s^2+\beta_2s+\beta_1}<br />
\end{align}<br />
</math><br />
<br />
with<br />
<br />
{|<br />
|<math display="inline">\alpha_2=ml^2+I</math><br />
|-<br />
|<math display="inline">\alpha_1=b</math><br />
|-<br />
|<math display="inline">\alpha_0=-mgl</math><br />
|-<br />
|<math display="inline">\beta_4=(M+m)(ml^2+I)-m^2l^2</math><br />
|-<br />
|<math display="inline">\beta_3=(M+m)b+(ml^2+I)c</math><br />
|-<br />
|<math display="inline">\beta_2=-(M+m)mgl+bc</math><br />
|-<br />
|<math display="inline">\beta_1=-mglc</math><br />
|-<br />
|<math display="inline">\gamma_1=-ml</math><br />
|}<br />
<br />
This can be expressed in Octave<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating the transfer functions for the inverted pendulum|<syntaxhighlight lang="octave" style="font-size:14px"><br />
m = 0.15;<br />
l = 0.314;<br />
M = 1.3;<br />
I = 0;<br />
g = 9.80665;<br />
b = 20;<br />
c = 20;<br />
<br />
G1 = tf([m*l^2+I b -m*g*l],<br />
[(M+m)*(m*l^2+I)-m^2*l^2 (M+m)*b+(m*l^2+I)*c -(M+m)*m*g*l+b*c -m*g*l*c 0]);<br />
G2 = tf([-m*l],<br />
[(M+m)*(m*l^2+I)-m^2*l^2 (M+m)*b+(m*l^2+I)*c -(M+m)*m*g*l+b*c -m*g*l*c]);<br />
</syntaxhighlight>}}<br />
<br />
and by invoking the <code style="font-size:14px; border:solid lightgray 1px; padding: 2px">bode</code> command<br />
<br />
<!-- {{SyntaxHighlight| --><br />
{{Code|Creating Bode plots for the inverted pendulum|<syntaxhighlight lang="octave" style="font-size:14px"><br />
bode(G1);<br />
bode(G2);<br />
</syntaxhighlight>}}<br />
<br />
one obtains the bode diagrams of the two transfer functions.<br />
<br />
<div><ul><br />
<li style="display: inline-block;"> [[File:bode_g1.png|frame|Bode diagram of the cart movement transfer function.]] </li><br />
<li style="display: inline-block;"> [[File:bode_g2.png|frame|Bode diagram of the pendulums rotation transfer function.]] </li><br />
</ul></div><br />
<br />
==References==<br />
<references /><br />
<br />
<br />
[[Category:Octave-Forge]]</div>
178.5.170.67