# A & B. Modeling and Control Design (Week 1)

## Objective

The purpose of this experiment is to design a controller that maintains the direction of a gyroscope under base excitation. The controller can also be used to rotate the gyro platform to a desired orientation using the gyroscopic principle.

## Introduction

Gyroscopes have become of great practical interest as they are used in control and guidance systems for air, sea, and space vehicles. One of their biggest advantages is that they can generate a large output (orientation change of an entire spacecraft) using a small input (torque input tilting a rotating disk) through torque amplification.

<figure><img src="/files/4Xt7acQY9wvig1u5g0hT" alt="" width="417"><figcaption><p>Figure 1. Quanser 3-DOF Gyroscope</p></figcaption></figure>

## Description of Quanser Gyroscope system

The Quanser 3 DOF Gyroscope system (see Figure 1) can be actuated about all of its frames using the mounted motors while encoders measure the angle about each axis. In addition, the rotor itself is actuated and measured in the same manner.

The gyroscope setup is shown in Figure 2, and its components are provided in a table in Figure 3. The outer rectangular gray frame, the outer red gimbal and the inner blue gimbal are designed such that they can be individually fixed in place upon desire. This allows the users to perform a variety of different experiments using the device.

In this experiment, the gyroscopic effect will be employed to control the angle of the gray frame by applying the control command about the blue gimbal. The red outer gimbal will be fixed. In order to do this, the rotor has to have acquired enough angular momentum (RPM) for the gyroscopic effect to take place. Therefore, a controller is required to control the angular speed of the disk while another is required to control the blue gimbal angle.

<figure><img src="/files/dtQAh5DGOFjRKh3FORtG" alt="" width="450"><figcaption><p>Figure 2. Gyroscope components figure</p></figcaption></figure>

<figure><img src="/files/zpcehhZuqDqf257y9vfa" alt=""><figcaption><p>Figure 3. Gyroscope components table</p></figcaption></figure>

In the next sections, we will develop a model of the gyroscope device from first principles in order to obtain a transfer function of the plant, which we will later use in a control scheme.

## A. Modeling

The angular position about the outer gray frame (Body A), i.e., the yaw angle $$\psi$$, is controlled by changing the angular position, the roll angle $$\phi$$, of the blue gimbal (Body C), with the torque generated by motor 2, $$\tau\_2$$ (see Figure 4). The red gimbal/y-axis (Body B) is locked in our experiment.

The rotational dynamics of rigid bodies can be modeled using the Newton-Euler equation, which states that the rate of change of angular momentum of a rigid body about its mass center equals the total external moment applied about its mass center. Using the Newton-Euler equation, one can derive the equations for rotational motion of individual gimbals and the outer frame. The resulting equations will be non-linear. They are linearized with the disk spinning at a constant high speed $$(\Omega)$$with the gyroscope system at rest, i.e., roll $$(\phi)$$, pitch $$(\theta)$$ and yaw $$(\psi)$$ equal zero. In our experiment, we will lock the the rotation of the red gimbal, i.e., $$\theta=0$$, for all the time. Further, we will align the disk spin axis along the y-axis (see Figure 4).

<figure><img src="/files/QP29cCC7Nv9v76pFWw7i" alt=""><figcaption><p>Figure 4. Components of Quanser 3 DOF gyroscope</p></figcaption></figure>

The resulting **linearized equations** of motion when the red gimbal is locked, i.e., $$\theta=0$$, and after neglecting the small amount of bearing friction associated with gimbal and frame rotations can be obtained as

$$
J\_d\dot{\omega}=\tau\_1 \qquad \qquad \tag{1}
$$

$$
J\_x\ddot{\phi}=\tau\_2+J\_d\Omega\dot{\psi}\qquad \qquad \tag{2}
$$

$$
J\_z \ddot{\psi}=-J\_d\Omega\dot{\phi}\qquad \qquad \tag{3}
$$

where $$\omega$$ is the change in disc speed from its steady state value of $$\Omega$$, $$J\_d$$ is the disc mass moment of inertia about its spin axis, $$J\_x$$ is the mass moment of inertia of the disk and motor 1 plus the blue gimbal and motor 2 about the x-axis (roll axis), $$J\_z$$ is the mass moment of inertia of the entire system, i.e., including the disk, red and blue gimbals, motors 1 and 2 and the outer gray frame about the z-axis.

Equation (1) is for the disc spinning about its own axis. Equation (2) is for the motion about the roll/blue x-axis that is driven by the torque applied from motor 2 and the gyroscopic reaction torque. Equation (3) is for the motion about the yaw/gray frame that is driven exclusively by the gyroscopic reaction torque.

The Quanser 3 DOF Gyroscope is driven by a current-controller amplifier. The relation between the torque outputs of motors 1 and 2 and their respective current inputs are

$$
\tau\_1=k\_tu\_1\qquad \qquad \tag{4}
$$

$$
\tau\_2=k\_tu\_2\qquad \qquad \tag{5}
$$

where $$k\_t$$ is the current-to-torque constant of the motor, $$u\_1$$ is the current applied to motor 1, and $$u\_2$$ is the current applied to motor 2.

The disc is rotated at a fixed, steady-state speed of $$\Omega$$. Given this and applying Laplace transforms to Equations (1) to (3) we arrive at the following transfer function models:

$$
\frac{\omega(s)}{\tau\_1 (s)}=\frac{1}{J\_d s }\qquad \qquad \tag{6}
$$

$$
\frac{Φ(s)}{τ\_2 (s)}=\frac{J\_z}{J\_x J\_z s^2+J\_d^2 Ω^2}=P\_1 (s)\qquad \qquad \tag{7}
$$

$$
\frac{Ψ(s)}{Φ(s)}=\frac{-ΩJ\_d}{J\_z s}=P\_2 (s)\qquad \qquad \tag{8}
$$

A state-space model representation of Equations (2-3) with the state vector as $$\[\phi \quad \psi \quad \dot{\phi} \quad \dot{\psi}]^T$$ can be written as

$$
\frac{d}{dt} \begin{bmatrix}
\phi \\
\psi \\
\dot{\phi} \\
\dot{\psi} \\
\end{bmatrix} = \begin{bmatrix}
0& 0& 1& 0 \\
0& 0& 0& 1 \\
0& 0& 0& J\_d\Omega/J\_x \\
0& 0& -J\_d\Omega/J\_z& 0
\end{bmatrix}\begin{bmatrix}
\phi \\
\psi \\
\dot{\phi} \\
\dot{\psi} \\
\end{bmatrix} + \begin{bmatrix}
0 \\
0 \\
1/J\_x \\
0 \\
\end{bmatrix}\qquad \qquad \tag{9}
$$

The gyroscope system parameters are provided in Table 1:

| Parameter Name                                                                |       Parameter Symbol      | Value      | Unit  |
| ----------------------------------------------------------------------------- | :-------------------------: | ---------- | ----- |
| Rotor mass                                                                    |           $$m\_d$$          | 1.907      | kg    |
| Rotor radius                                                                  |           $$r\_d$$          | 0.0762     | m     |
| MOI of disk about spin axis                                                   |           $$J\_d$$          | 0.0055     | kg    |
| <p>MOI about x-axis/blue gimbal<br>(disc rotor + blue gimbal)</p>             |           $$J\_x$$          | 0.00388552 | kgm^2 |
| <p>MOI about y-axis/red gimbal<br>(disc rotor + blue gimbal + red gimbal)</p> |           $$J\_y$$          | 0.02344554 | kgm^2 |
| <p>MOI about z-axis/gray gimbal,<br>i.e., disc and blue, red, gray frames</p> |           $$J\_z$$          | 0.06632120 | kgm^2 |
| Gimbal motor current-torque constant                                          |           $$k\_t$$          | 0.115      | Nm/A  |
| Disc motor current-torque constant                                            |       $$k\_{t,disk}$$       | 0.0704     | Nm/A  |
| Max current                                                                   |         $$I\_{max}$$        | 3          | A     |
| Max torque                                                                    |       $$\tau\_{max}$$       | 0.3450     | Nm    |
| Disk rotor steady-state speed                                                 | $$\Omega, ,, \omega\_{ss}$$ | 78.5398    | rad/s |

## B. Control Design

The objective is to design a controller for regulation and control of the outer frame (gray frame) angular position $$\psi$$ using the inner gimbal (blue gimbal) torque $$\tau\_2$$. This mimics the following problem: Given a spacecraft with a momentum gyro, we would like to regulate and control the spacecraft yaw angle $$\psi$$ using the tilting of a high-speed spinning disk mounted in the spacecraft. In this lab, the rotation about the z-axis, $$\psi$$, is controlled by torque applied about the x-axis through motor 2.

### Controller Specifications:

**Specification 1:** All closed-loop poles must be in the left half of the complex plane.

**Specification 2:** The peak time in response to a $$10\degree$$ step command must be less than 0.45 seconds.

**Specification 3:** The 2% settling time to a $$10\degree$$ step command input must be less than 0.50 seconds.

**Specification 4:** Control current must not saturate (see Table 1 for max current input).

**Specification 5:** For the outer loop, $$|k\_p|<6$$ and $$|k\_d|<0.4$$.

In order to meet the given controller specifications, we will make use of a technique known as successive loop closures. We will first design an inner loop rate feedback, i.e., feedback of $$\dot{\phi}$$,  to damp the rotation of the inner blue gimbal. Subsequently, an outer loop PD controller is used to control the outer frame (gray frame) rotation $$\psi$$. The selected control logic is summarized in Figure 5.

<figure><img src="/files/TQZ06M6Oi45Ms9yWqIpA" alt=""><figcaption><p>Figure 5. Gyroscope plant and control architecture</p></figcaption></figure>

The transfer functions $$P\_1(s)$$ and $$P\_2(s)$$ are previously obtained in the modeling section as Equations (7) and (8). In the following section, we will form the overall transfer function and do controller design.

### Controller Design Procedure:

{% file src="/files/Za7kQK8Ffe35CuOnGCFc" %}

1. Open the script *gyro\_sim\_week1.mlx* and run the first section to initialize symbolic system parameters.
2. At the second section of the script, generate the transfer functions $$P\_1(s)$$ and $$P\_2(s)$$ using the given parameters. Note that $$P\_2(s)$$ has a negative sign in the numerator.
3. Obtain the overall transfer function from $$r\_i$$ to $$\psi$$, which will be your plant $$G(s)$$ (see Figure 5) for the outer loop PD controller design. Remember to close the loop for $$P\_1(s)$$.
4. Select a nominal value for the inner loop rate feedback gain $$k\_v$$, for example $$k\_v=0.2$$
5. Based on the symbolic G function from step 3, generate a numeric transfer function $$G(s)$$ from $$r\_i$$ to $$\psi$$ that you will use for the **controlSystemDesigner** window. This function should not contain any symbols.\
   **Note:** Check your $$G(s)$$ with your TA before proceeding.
6. Initialize C = 1, then open **controlSystemDesigner(G,C)** in MATLAB.
7. The control architecture shown in Figure 5 is different from the default architecture that opens in **controlSystemDesigner**. To account for this change, on the Control System Designer window, select CONTROL SYSTEM > Edit Architecture, and select the following architecture:&#x20;

   <figure><img src="/files/tAv8axos3oB36rDEvmrA" alt=""><figcaption><p>Figure 6. Gyroscope outer control loop architecture – Control System Designer</p></figcaption></figure>
8. Select some arbitrary **negative** values (within the limits of Specification 5) for both $$k\_p$$ (C1 in Figure 6) and $$k\_d$$ (C2 in Figure 6). Since C2 is a pure derivative gain, you need to add a differentiator in C2, not a real zero.
9. Tune the values for $$k\_p$$ and $$k\_d$$ as needed to meet the given set of specifications. If needed, readjust the $$k\_v$$ value of the inner loop, which is positive.
10. **Save** the **controlSystemDesigner** window plots, and your final gains $$k\_p, , k\_d, , k\_v.$$\
    **Note:** Check your final gains with your TA before proceeding.
11. Use Figure 5 as a guide to create the SImulink diagram for this experiment. Adjust the step size to be a fixed-step size of 0.002 under model settings.
12. To the model created in step 11, add the following:
    * A scope for the commanded input to the system.
    * A saturation block before $$P\_1(s)$$ to limit the torque $$\tau\_2$$ applied to the system.\
      **Note:** Since we need to satisfy Specification 4 (current saturation), we should ensure torque saturation as torque and current are linearly related (see Equation (5)).
    * A scope to the torque applied to the system, $$\tau\_2$$ (after the saturation block).
    * A scope between $$P\_1(s)$$ and $$P\_2(s)$$ that measures the gyro angle, $$\phi$$.
    * A scope at the final output, $$\psi$$.\
      **Note:** Check your final Simulink diagram with your TA before proceeding.
13. Run the Simulink diagram for a reference angle of $$\psi\_{ref}=10^o$$. This can be accomplished in one of two ways:
    1. Provide a step input of an initial value of 0 and a final value of 10. This will generate a step input of  $$\psi\_{ref}=10^o$$.
    2. Provide a square wave of amplitude 5, frequency of 0.333 Hz and an offset of +5. This will generate a square wave of an upper value  $$\psi\_{ref}=10^o$$ and a lower value of 0.
14. Verify if the Simulink diagram output is similar to the **controlSystemDesigner** step-input plot.
15. Check if the Simulink response satisfies all the given specifications **(not on controlSystemDesigner)**. If not, further tune your $$k\_p$$ and $$k\_d$$ values (and $$k\_v$$ if required) till all requirements are met.\
    **Note:** Check your final gains with your TA before proceeding.

{% hint style="info" %}
To check if your Simulink response meets Specification 2 and Specification 3, you can do **one of the following approaches**:

* Place markers on the plot to manually check for peak time and 2% settling time.
* Use stepinfo() command in MATLAB window to obtain the peak time and 2% settling time.
  {% endhint %}

<figure><img src="/files/B4tDAWjTyy2DO6B6VS7i" alt=""><figcaption><p>Figure 7. Simulation plots for <span class="math">\psi_{ref}=10^o</span>  square wave</p></figcaption></figure>

## Results and Questions for Report

### Modeling

#### Results

1. General principle used to obtain equations of motion for the gyroscope.
2. The three time-domain linearized equations of motion for the experiment.
3. $$P\_1(s)$$ (both symbolic and numerical forms).
4. $$P\_2(s)$$ (both symbolic and numerical forms).

### Control Design

#### Results

1. Brief description of control design objective.
2. The closed-loop transfer function for $$P\_1(s)$$ using rate feedback.
3. $$G(s)$$, the transfer function from $$r\_i$$ to $$\psi$$ (both symbolic and numerical forms).
4. Gain values  $$k\_p, , k\_d, , k\_v$$ from controlSystemDesigner (Step 10).
5. Control System Designer plots (root locus and bode plots for C1 and C2 and step response plot with peak time, settling time and steady-state values indicated).
6. Simulink model (Step 12).
7. Simulink response plots (to be generated using MATLAB, not Scope).
8. Validation of control design specifications being met or not.
9. Final tuned gain values  $$k\_p, , k\_d, , k\_v$$ from Simulink (Step 15).

#### Questions

1. How is the default Control System Designer control architecture different from the one used in this experiment? In your explanation, mention how the locations of the PD controller gains in Figure 5 are different from a traditional PD controller.
2. Briefly explain the need for the inner loop rate ($$\dot{\phi}$$) feedback.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gtae.gitbook.io/ae4610/gyro_sp24/a-and-b.-modeling-and-control-design-week-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
