Control Design

To help you design interactive qdex control components, we have created a fragment called controlDesign.xml, available below. At this time, the control design package only includes continuous and discrete time LQR design functions. Over time it will exapnd to include other control design functions. 

To add the control design fragment to your app, download it by clicking the button above. Unzip the folder. You can drag-and-drop the xml file directly into your project in the solution explorer window in Visual Studio, or you can right click on your module and click Add > Existing Item (you may have to switch the file type from Visual C# Files to All Files).

Once added to your project, include the fragment in your module by placing the following code at the top of your document (above your first section)

<include src="controlDesign.xml" />

LQR Design

Given A, B, Q, and R matrices, the LQR design function returns the controller gains K, the solution to the algebraic Riccati equation, and the closed-loop eigenvalues. 

The below example computes the continuous-time LQR design values. To compute the discrete time LQR design values, use the discrete time LQR function instead, i.e.

 
k,s,e = controlDesign.dlqr(a, b, q, r);

Example

<script>
  -- Defining the A, B, Q, and R matrices
  local a = matrix({{-3,-2},{1,0}});
  local b = matrix({{1},{0}});
  local q = matrix({{1,0},{0,1}});
  local r = matrix({{1}});
</script>

<button content="Solve LQR Gains">
  <onClick>
    -- Compute the LQR design
    k,s,e = controlDesign.lqr(a, b, q, r);
    
    -- Fill the controller gain table with the values from matrix k
    K.R1.C1.value.Text = tostring(k:at(1, 1));
    K.R1.C2.value.Text = tostring(k:at(1, 2));
    
    -- Fill the Riccati equation table with the values from the matrix s
    S.R1.C1.value.Text = tostring(s:at(1, 1));
    S.R1.C2.value.Text = tostring(s:at(1, 2));
    S.R2.C1.value.Text = tostring(s:at(2, 1));
    S.R2.C2.value.Text = tostring(s:at(2, 2));
    
    -- Fill the eigenvalues table with the values from the matrix e
    E.R1.C1.value.Text = tostring(e:at(1));
    E.R2.C1.value.Text = tostring(e:at(2));
  </onClick>
</button>

<p>The gain matrix, K:</p>
<table name="K">
  <row name="R1">
    <column name="C1">
      <p name="value" />
    </column>
    <column name="C2">
      <p name="value" />
    </column>
  </row>
</table>
<p>The solution to the algebraic Riccati equation:</p>
<table name="S">
  <row name="R1">
    <column name="C1">
      <p name="value" />
    </column>
    <column name="C2">
      <p name="value" />
    </column>
  </row>
  <row name="R2">
    <column name="C1">
      <p name="value" />
    </column>
    <column name="C2">
      <p name="value" />
    </column>
  </row>
</table>
<p>The closed-loop eigenvalues:</p>
<table name="E">
  <row name="R1">
    <column name="C1">
      <p name="value" />
    </column>
  </row>
  <row name="R2">
    <column name="C1">
      <p name="value" />
    </column>
  </row>
</table>