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);
### Starting serial model reference simulation build.
### Successfully updated the model reference simulation target for: PlantModel
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Simulation targets built:

Model           Action                        Rebuild Reason                             
=========================================================================================
PlantModel      Code generated and compiled.  PlantModel_msf.mexw64 does not exist.      
FixedWingModel  Code generated and compiled.  FixedWingModel_msf.mexw64 does not exist.  

2 of 2 models built (0 models already up to date)
Build duration: 0h 2m 22.454s
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)
A copy of the original file "FixedWingModel.slx" has been created because it was last saved in an earlier version of Simulink. To recover the original version, rename the file "FixedWingModel.slx.r2020b" as "FixedWingModel.slx".

You can turn this feature off using the Simulink Preferences. Click here if you don't want to see this message again.
assignin(plantDataSet, 'useHighFidelity', 0);

sim(stepModel);
### Starting serial model reference simulation build.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Simulation targets built:

Model           Action                        Rebuild Reason                            
========================================================================================
FixedWingModel  Code generated and compiled.  Model or library FixedWingModel changed.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 27.045s
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);
### Starting serial model reference simulation 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 3.4589s
lowFidelityAirSpeed = AirSpeed.Data(:);
lowFidelityTime = AirSpeed.Time;

assignin(plantDataSet, 'useHighFidelity', 1);

sim(stepModel);
### Starting serial model reference simulation build.
### Model reference simulation target for PlantModel is up to date.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Simulation targets built:

Model           Action                        Rebuild Reason                                                          
======================================================================================================================
FixedWingModel  Code generated and compiled.  Variant control useHighFidelity == 1 value changed from false to true.  

1 of 2 models built (1 models already up to date)
Build duration: 0h 0m 36.51s
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);
### Starting serial model reference simulation build.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Simulation targets built:

Model           Action                        Rebuild Reason                                                          
======================================================================================================================
FixedWingModel  Code generated and compiled.  Variant control useHighFidelity == 1 value changed from true to false.  

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

assignin(plantDataSet, 'useHighFidelity', 1);

sim(stepModel);
### Starting serial model reference simulation build.
### Model reference simulation target for PlantModel is up to date.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Simulation targets built:

Model           Action                        Rebuild Reason                                                          
======================================================================================================================
FixedWingModel  Code generated and compiled.  Variant control useHighFidelity == 1 value changed from false to true.  

1 of 2 models built (1 models already up to date)
Build duration: 0h 0m 36.235s
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);
### Starting serial model reference simulation build.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Simulation targets built:

Model           Action                        Rebuild Reason                                                          
======================================================================================================================
FixedWingModel  Code generated and compiled.  Variant control useHighFidelity == 1 value changed from true to false.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 22.558s
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);
### Starting serial model reference simulation build.
### Model reference simulation target for PlantModel is up to date.
### Successfully updated the model reference simulation target for: FixedWingModel

Build Summary

Simulation targets built:

Model           Action                        Rebuild Reason                                                          
======================================================================================================================
FixedWingModel  Code generated and compiled.  Variant control useHighFidelity == 1 value changed from false to true.  

1 of 2 models built (1 models already up to date)
Build duration: 0h 0m 34.42s
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

| |

Related Topics