Main Content

Gain-Scheduled PID Autotuning a VTOL UAV During Forward and Backward Transition

Since R2024a

This example shows how to tune, in flight, a vertical takeoff and landing (VTOL) UAV for transition between hover and fixed-wing flight and from fixed-wing flight to hover using the Gain-Scheduled PID Autotuner block. This UAV model is based on the example Design and Tune Controller for VTOL UAV (UAV Toolbox).

Getting Started

Click the Getting Started button in project shortcuts to setup the aircraft plant model and base controller.

prj = openProject('VTOLApp/VTOLRefApp.prj');

% Setup Plant
setupPlant;

% Open model
open_system(mdl);

Reference Application Updates

This VTOL UAV template models a tiltrotor where the front rotors can tilt to transition from hover to fixed wing flight. During hover flight the yaw controller and horizontal position controllers are both active which can result in the two control loops interfering with one another causing an instability. These two controllers are used in the VTOL UAV reference application model to move the aircraft from one point to another (horizontal position control) and to counteract outside disturbances that cause the UAV to yaw (yaw control). In order to allow these 2 controllers to still be present but make the entire control system more robust 2 improvements are made to the existing model:

  1. Replace the existing PID yaw controller with a velocity PID controller

  2. Replace the existing horizontal position controllers with gain-scheduled PID controllers

The first improvement allows the yaw controller to still correct for yaw angle disturbances but restricts the amount of control effort the controller can apply through limiting the rate-of-change of the control effort. Using a velocity PID controller helps prevent wind-up instead of using a typical rate limiter. This example does not go into detail on velocity PID controllers but this controller is shown below for reference.

In the existing UAV reference application, the horizontal position control is only active during hover flight mode and is disabled during fixed-wing flight and during transition between hover and fixed-wing or vice-versa. However, because this controller is disabled, there is a large transient on UAV tilt rotors when switching either to or from the controller. In order to make this switching smoother the existing mode switching is replaced with a single gain-scheduled PID controller. The controller gains ramp down from their nominal value during hover flight to 1% of their nominal value during transition. Below is a snapshot of the subsystem containing the gain-scheduled PID controllers used in the horizontal position controller.

Previously, forward transition (hover to fixed-wing) used an open-loop approach to set the desired rate of change of the rotor tilt angle and backward transition was handled by a proportional controller that used the tilt angle to reduce the velocity of the UAV to zero. This has been updated to use a single gain-scheduled PID controller shown below.

The details of this updated control methodology is detailed in the following section.

Transition and Backward Transition Unified Control

The UAV tiltrotor begins landed and in the hover configuration before taking off to a desired altitude. Once this altitude is reached the UAV enters the transition mode to tilt the front rotors forward until they reach the critical tilt angle and the UAV transitions to fixed-wing flight. When the UAV is desired to land the UAV will slow down and enter the back transition mode to begin tilting the front rotors back to their starting position. Once the front rotors have completed this transition the UAV will be in the hover mode again and perform a vertical landing. The two transition modes are the focus of this example and were previously handled by two separate algorithms. In this example forward transition and backward transition have been combined into a single gain-scheduled PID controller.

The nature of the UAV plant requires that anti-windup only be used during back transition so the output saturation during forward transition is applied external to the Simulink PID Controller while the saturation for the backward transition is internal to the PID Controller to use the clamping anti-windup algorithm.

The forward transition algorithm uses the tilt angle for both the process and manipulated variables while the backward transition algorithm uses the UAV forward velocity. When not in transition the controller error is held to zero and the integrator is reset.

The two algorithms only change based on the mode of the UAV so the flight mode is used as the scheduling variable for the gain-scheduling implementation. To implement gain-scheduling and autotuning the Gain-Scheduled PID Autotuner block from Simulink Control Design is used. This block allows for the implementation of gain-scheduling and provides a way to both tune the gains at multiple operating conditions and store the gains for use elsewhere in the model or system.

The autotuning workflow for this block is similar to the Closed-Loop PID Autotuner. The Gain-Scheduled PID Autotuner block allows you to tune one PID controller at a time. It injects perturbation signals at the plant input and measures the plant output during a closed-loop experiment. When the experiment stops, the block computes PID gains based on the plant frequency responses estimated at a small number of points near the desired bandwidth. The tuned PID gains are stored and the existing gain array, if available, is updated at the corresponding value of the scheduling variable (by default the scheduling variable is the same as the plant output). The Gain-Scheduled PID Autotuner block will also automatically determine the current PID gains based on the current value of the scheduling variable and output the corresponding gains for use in a PID Controller.

Gain-Scheduled PID Autotuning Setup

The Gain Scheduled PID Autotuner is added to the model after the PID Controller and before the plant input. When not enabled (start/stop signal is 0) the autotuner will be a passthrough from the input u to the output u+Δu and output the PID gains corresponding to the value of the scheduling variable. To setup the Gain Scheduled PID Autotuner block used in this example first the autotuning settings on the Autotuner tab are:

  • Controller Type: PI to match the PID controller

  • Bandwidth: 10 rad/sec to allow the transitions to complete in roughly 200 ms

  • Phase Margin: 60 degrees to balance overshoot and robustness

  • Signal Amplitudes: 0.075 to allow for sufficient perturbation amplitudes and keep away from down stream limits

Next, the block is configured gain scheduling on the Gain scheduling tab as follows:

  • Breakpoints: set to [0 1 2 3] for the four different flight modes

  • Method of storing gains: Data store memory so that the gains can be viewed externally via display blocks

  • P Gain Parameter Name: PGains_Transition

  • P Gain initial conditions: [1e-5; 5; 1e-5; 1]. These are the default values used for the P gain at the four flight modes and will be autotuned for the two transition modes and left small for hover and fixed-wing modes

  • I Gain Parameter Name: IGains_Transition

  • I Gain initial conditions: [1e-5; 0.5;1e-5; 0]. These are the default values used for the I gain at the four flight modes and will be autotuned for the two transition modes and left small for hover and fixed-wing modes

The gains from the Gain Scheduled PID Autotuner are output and fed back to the PID Controller block. The gains are filtered with a first order filter to prevent step changes in the PID gains when changing from one flight mode to another. This is necessary as the scheduling variable used here is the flight mode which experiences a step change every time the mode switches. This first order filter is set to allow the gains to reach their final value in about 300 ms.

After the Gain Scheduled PID Autotuner is setup the Change Operating Points block needs to be setup in order to provide the start/stop signal needed in the Gain Scheduled PID Autotuner as well as change the target transition angle from 90 degrees to about 70 degrees. This is done to leave enough room away from the saturation limit of 90 degrees so that the perturbations needed for autotuning do not get limited. The desired bandwidth, as mentioned above, is 10 rad/sec so the autotuning time span is set to be slightly above the recommended 550/bandwidth or 60 seconds. Finally, the Change Operating Points block is set to automatically perform autotuning 2 seconds after the UAV has reached one of the transition flight modes.

A second Change Operating Points block is used in the Autotuning control mode in order to only place the UAV in the forward or backward transition modes and hold the UAV there for the entirety of the simulation. When tuning is completed the gains will be saved, the gain array updated, and then the simulation will be reconfigured to run the standard full transition mission from takeoff (hover) to fixed-wing flight then land (hover).

Automate Tuning of Tiltrotor in Forward and Backward Transition

The model is setup with the above settings to perform gain scheduled autotuning during both forward and backward transitions.

Setup the model to run the autotuning mission

% Setup autotuning mission
setupTransitionAutotuning

% Set default PID Gains
set_param([mdl '/Autopilot/Tilt Scheduler/DataStore P'],'InitialValue','[1e-05;5;1e-05;1]')
set_param([mdl '/Autopilot/Tilt Scheduler/Gain-Scheduled PID Autotuner'],'PGainInitialConditions','[1e-05;5;1e-05;1]')
set_param([mdl '/Autopilot/Tilt Scheduler/DataStore I'],'InitialValue','[1e-5; 0.5;1e-5; 0]')
set_param([mdl '/Autopilot/Tilt Scheduler/Gain-Scheduled PID Autotuner'],'IGainInitialConditions','[1e-5; 0.5;1e-5; 0]')

Run the model and open the data inspector to view the rotor tilt angle and observe the tilt angle being perturbed during the autotuning process. During the autotuning process the UAV will fly straight due to the front rotors tilting forwards and will come to a stop after back transition because the front rotors will be returned to their vertical position.

% Run autotuning simulation
outAutotuning = sim(mdl);
### Searching for referenced models in model 'VTOLTiltrotor'.
### Found 1 model references to update.
### Starting serial model reference simulation build.
### Successfully updated the model reference simulation target for: PropellerDynamics

Build Summary

Simulation targets built:

Model              Action                        Rebuild Reason  
=================================================================
PropellerDynamics  Code generated and compiled.                  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 58.884s

Figure UAV Animation contains an axes object. The axes object with xlabel North, ylabel West contains 5 objects of type patch, line.

% Plot results from tuning
exampleHelperPlotTransitionTuning(outAutotuning);

Figure contains 2 axes objects. Axes object 1 with title Tilt and Pitch Angles, ylabel Tilt contains an object of type line. This object represents Tilt angle. Axes object 2 with xlabel Time [sec], ylabel Pitch contains an object of type line. This object represents Pitch angle.

During the simulation, perturbations are injected to the two forward rotors. During the injection (20-80 seconds for forward transition and 110 to 175 seconds for backward transition) the pitch angle of the UAV is affected. Because the UAV is moving forward during the autotuning process for forward transition the pitch of the UAV is more greatly affected than during back transition.

After simulation is completed the PID gains used in the transition controller need to be updated for use during normal flight missions.

% Update the PID Gains for transition using set_param
set_param([mdl '/Autopilot/Tilt Scheduler/DataStore P'],'InitialValue',mat2str(outAutotuning.PGains_Transition'))
set_param([mdl '/Autopilot/Tilt Scheduler/Gain-Scheduled PID Autotuner'],'PGainInitialConditions',mat2str(outAutotuning.PGains_Transition'))
set_param([mdl '/Autopilot/Tilt Scheduler/DataStore I'],'InitialValue',mat2str(outAutotuning.IGains_Transition'))
set_param([mdl '/Autopilot/Tilt Scheduler/Gain-Scheduled PID Autotuner'],'IGainInitialConditions',mat2str(outAutotuning.IGains_Transition'))

Verify Tracking Performance

With the gains tuned and updated in the model a full mission can be simulated from landed to takeoff to fixed-wing flight and then, finally, to hover to land.

Set up and simulate the transition guidance mission with the tuned transition parameters.

% Setup full transition mission to observe behavior
setupTransitionGuidanceMission

Using the gain-scheduled PID autotuner to tune the transition controller allows for a controlled and stable way to achieve the desired front rotor tilt performance during transition while only requiring a stabilizing controller to get started.

% Run full transition mission
outFullMission = sim(mdl);
### Searching for referenced models in model 'VTOLTiltrotor'.
### Found 1 model references to update.
### Starting serial model reference simulation build.
### Successfully updated the model reference simulation target for: PropellerDynamics

Build Summary

Simulation targets built:

Model              Action                        Rebuild Reason  
=================================================================
PropellerDynamics  Code generated and compiled.                  

1 of 1 models built (0 models already up to date)
Build duration: 0h 1m 33.605s

Figure UAV Animation contains an axes object. The axes object with xlabel North, ylabel West contains 5 objects of type patch, line.

% Plot results from full transition
tLayout=tiledlayout(4,1);
exampleHelperPlotTransitionResults(tLayout,outFullMission);

Figure contains 4 axes objects. Axes object 1 with ylabel Altitude (m) contains an object of type line. Axes object 2 with ylabel Pitch contains an object of type line. Axes object 3 with ylabel Tilt contains an object of type line. Axes object 4 with xlabel Time (sec), ylabel Airspeed contains an object of type line.

% Discard changes
discardChanges(myDictionaryObj);

From the results shown, the UAV is performs both the forward and backward transition using the implemented gain-scheduled PID controller.

Summary

This example shows some improvements to the VTOL UAV Reference Application for transition modes by using the Simulink Control Design Gain-Scheduled PID Autotuner block and Change Operating Points block. These two blocks work together to implement gain-scheduling for the transition controller and tune the gains for the two transition modes. Other improvements to the hover mode controller along with the new gain-scheduled PID implementation allow for a smooth transition from hover to fixed-wing flight and back.

See Also

|