Main Content

Approximate High-Fidelity UAV Model with UAV Guidance Model Block

Simulation models often need different levels of fidelity during different development stages. During the rapid-prototyping stage, we would like to quickly experiment and tune parameters to test different autonomous algorithms. During the production development stage, we would like to validate our algorithms against models of increasing fidelities.

In this example, we demonstrate a method to approximate a high-fidelity model with the Guidance Model block and use it to prototype and tune a waypoint following navigation system. See Tuning Waypoint Following Controller for Fixed-Wing UAV. The same navigation system is tested against a high-fidelity model to verify its performance.

The example model uses a high-fidelity unmanned aerial vehicle (UAV) model consisting of a plant model and a mid-level built-in autopilot. This model contains close to a thousand blocks and it is quite complicated to work with. As a first step in the development process, we created a variant system that can switch between this high-fidelity model and the UAV Guidance Model block. The high-fidelity model is extracted from a File Exchange entry, Simulink Drone Reference Application.

UAV model of different fidelity

uavModel = 'FixedWingModel.slx';
open_system(uavModel);

You can switch between the low and high-fidelity models by changing the MATLAB® variable value stored in the data dictionary associated with this model.

plantDataDictionary = Simulink.data.dictionary.open('pathFollowingData.sldd');
plantDataSet = getSection(plantDataDictionary,'Design Data');

% Switch to high-fidelity model
assignin(plantDataSet,'useHighFidelity',1);

High fidelity UAV subsystem with control input and state output

% Switch to low-fidelity model
assignin(plantDataSet,'useHighFidelity',0);

Low fidelity UAV subsystem with control input and state output

Approximate high-fidelity fixed-wing model with low-fidelity guidance model

To approximate the high-fidelity model with the UAV Guidance Model block, create step control signals to feed into the model and observe the step response to RollAngle, Height, and AirSpeed commands.

stepModel = 'stepResponse';
open_system(stepModel)

First, command a change in roll angle.

controlBlock = get_param('stepResponse/Step Control Input','Object');
controlBlock.StepControl = 'RollAngle Step Control';

assignin(plantDataSet,'useHighFidelity',1);

sim(stepModel);
### Searching for referenced models in model 'stepResponse'.
### Total of 2 models to build.
### Starting serial model build.
### Model reference simulation target for PlantModel is up to date.
### Model reference simulation target for FixedWingModel is up to date.

Build Summary

0 of 2 models built (2 models already up to date)
Build duration: 0h 0m 19.999s
highFidelityRollAngle = RollAngle.Data(:);
highFidelityTime = RollAngle.Time;

figure()
plot(highFidelityTime, highFidelityRollAngle,'--r');
title('Roll Angle Step Response')

Figure contains an axes object. The axes object with title Roll Angle Step Response contains an object of type line.

Zooming into the simulation result above, you see the characteristics of the roll angle controller built into the high-fidelity model. The settling time for the roll angle is close to 2.5 seconds.

xlim([75 80])
ylim([-0.1 0.548])

Figure contains an axes object. The axes object with title Roll Angle Step Response contains an object of type line.

For a second-order PD controller, to achieve this settling time with a critically damped system, the following gains should be used to configure the UAV Guidance Model block inside the low-fidelity variant of the UAV model. For this example, the UAV Guidance Model block is simulated using code generation to increase speed for multiple runs. See the block parameters.

zeta = 1.0; % critically damped
ts = 2.5; % 2 percent settling time
wn = 5.8335/(ts*zeta);
newRollPD = [wn^2 2*zeta*wn];

Set the new gains and simulate the step response for the low-fidelity model. Compare it to the original response.

load_system(uavModel)
set_param('FixedWingModel/FixedWingModel/LowFidelity/Fixed Wing UAV Guidance Model',...
    'PDRollFixedWing',strcat('[',num2str(newRollPD),']'))
save_system(uavModel)

assignin(plantDataSet, 'useHighFidelity', 0);

sim(stepModel);
### Searching for referenced models in model 'stepResponse'.
### Total of 1 models to build.
### Starting serial model build.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Model reference simulation targets:

Model           Build Reason                              Status                        Build Duration
======================================================================================================
FixedWingModel  Model or library FixedWingModel changed.  Code generated and compiled.  0h 0m 24.619s 

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 25.204s
lowFidelityRollAngle = RollAngle.Data(:);
lowFidelityTime = RollAngle.Time;

hold on;
plot(lowFidelityTime, lowFidelityRollAngle,'-b');
legend('High-Fidelity Response', 'Low-Fidelity Response', 'Location','southeast');

Figure contains an axes object. The axes object with title Roll Angle Step Response contains 2 objects of type line. These objects represent High-Fidelity Response, Low-Fidelity Response.

The low-fidelity model achieves a similar step response. Similarly, we can tune the other two control channels: Height and AirSpeed. More sophisticated methods can be used here to optimize the control gains instead of visual inspection of the control response. Consider using System Identification Toolbox® to perform further analysis of the high-fidelity UAV model behavior.

controlBlock.StepControl = 'AirSpeed Step Control';
assignin(plantDataSet, 'useHighFidelity', 0);

sim(stepModel);
### Searching for referenced models in model 'stepResponse'.
### Total of 1 models to build.
### Starting serial model build.
### Model reference simulation target for FixedWingModel is up to date.

Build Summary

0 of 1 models built (1 models already up to date)
Build duration: 0h 0m 1.7137s
lowFidelityAirSpeed = AirSpeed.Data(:);
lowFidelityTime = AirSpeed.Time;

assignin(plantDataSet, 'useHighFidelity', 1);

sim(stepModel);
### Searching for referenced models in model 'stepResponse'.
### Total of 2 models to build.
### Starting serial model build.
### Model reference simulation target for PlantModel is up to date.
VarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC Y### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Model reference simulation targets:

Model           Build Reason                                                            Status                        Build Duration
====================================================================================================================================
FixedWingModel  Variant control useHighFidelity == 1 value changed from false to true.  Code generated and compiled.  0h 0m 31.406s 

1 of 2 models built (1 models already up to date)
Build duration: 0h 0m 38.299s
highFidelityAirSpeed = AirSpeed.Data(:);
highFidelityTime = AirSpeed.Time;

figure()
plot(lowFidelityTime, lowFidelityAirSpeed,'-b');
hold on;
plot(highFidelityTime, highFidelityAirSpeed,'--r');
legend('Low-Fidelity Response', 'High-Fidelity Response', 'Location','southeast');
title('Air Speed Step Response')
xlim([70 80])
ylim([17.5 19.2])

Figure contains an axes object. The axes object with title Air Speed Step Response contains 2 objects of type line. These objects represent Low-Fidelity Response, High-Fidelity Response.

controlBlock.StepControl = 'Height Step Control';
assignin(plantDataSet, 'useHighFidelity', 0);

sim(stepModel);
### Searching for referenced models in model 'stepResponse'.
### Total of 1 models to build.
### Starting serial model build.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Model reference simulation targets:

Model           Build Reason                                                            Status                        Build Duration
====================================================================================================================================
FixedWingModel  Variant control useHighFidelity == 1 value changed from true to false.  Code generated and compiled.  0h 0m 19.668s 

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 20.106s
lowFidelityHeight = Height.Data(:);
lowFidelityTime = Height.Time;

assignin(plantDataSet, 'useHighFidelity', 1);

sim(stepModel);
### Searching for referenced models in model 'stepResponse'.
### Total of 2 models to build.
### Starting serial model build.
### Model reference simulation target for PlantModel is up to date.
VarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC Y### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Model reference simulation targets:

Model           Build Reason                                                            Status                        Build Duration
====================================================================================================================================
FixedWingModel  Variant control useHighFidelity == 1 value changed from false to true.  Code generated and compiled.  0h 0m 29.576s 

1 of 2 models built (1 models already up to date)
Build duration: 0h 0m 36.618s
highFidelityHeight = Height.Data(:);
highFidelityTime = Height.Time;

figure()
plot(lowFidelityTime, lowFidelityHeight,'-b');
hold on;
plot(highFidelityTime, highFidelityHeight,'--r');
legend('Low-Fidelity Response', 'High-Fidelity Response', 'Location','southeast');
title('Height Step Response')
xlim([70 150])
ylim([49 56])

Figure contains an axes object. The axes object with title Height Step Response contains 2 objects of type line. These objects represent Low-Fidelity Response, High-Fidelity Response.

Test navigation algorithm with low-fidelity model

Now that we have approximated the high-fidelity model with the UAV Guidance Model block, we can try to replace it with the UAV Guidance Model block in the Tuning Waypoint Following Controller for Fixed-Wing UAV example. Test the effect of the lookahead distance and heading control gains against these models of different fidelities.

navigationModel = 'pathFollowing';
open_system(navigationModel);
assignin(plantDataSet,'useHighFidelity',0);

sim(navigationModel);
### Searching for referenced models in model 'pathFollowing'.
### Total of 1 models to build.
### Starting serial model build.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Model reference simulation targets:

Model           Build Reason                                                            Status                        Build Duration
====================================================================================================================================
FixedWingModel  Variant control useHighFidelity == 1 value changed from true to false.  Code generated and compiled.  0h 0m 29.41s  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 29.852s
figure
visualizeSimStates(simStates);

Figure contains an axes object. The axes object contains 204 objects of type patch, line.

Validate with high-fidelity model

assignin(plantDataSet,'useHighFidelity',1);

sim(navigationModel);
### Searching for referenced models in model 'pathFollowing'.
### Total of 2 models to build.
### Starting serial model build.
### Model reference simulation target for PlantModel is up to date.
VarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC YVarDim N, SF N, concat N, TLC Y### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Model reference simulation targets:

Model           Build Reason                                                            Status                        Build Duration
====================================================================================================================================
FixedWingModel  Variant control useHighFidelity == 1 value changed from false to true.  Code generated and compiled.  0h 0m 44.879s 

1 of 2 models built (1 models already up to date)
Build duration: 0h 1m 2.9506s
figure
visualizeSimStates(simStates);

Figure contains an axes object. The axes object contains 204 objects of type patch, line.

Conclusion

This example shows how we can approximate a high-fidelity model with a low-fidelity abstraction of a fixed-wing UAV. The opposite approach can be used as well to help with choosing autopilot control gains for the high-fidelity model. You can first decide acceptable characteristics of an autopilot control response by simulating a low-fidelity model in different test scenarios and then tune the high-fidelity model autopilot accordingly.

discardChanges(plantDataDictionary);
clear plantDataSet
clear plantDataDictionary
close_system(uavModel, 0);
close_system(stepModel, 0);
close_system(navigationModel, 0);

See Also

| |

Topics