diff options
author | Nao Pross <np@0hm.ch> | 2024-04-04 20:12:32 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-04-04 20:12:32 +0200 |
commit | 734ee9e826b490137e3d8af627019098cafa1403 (patch) | |
tree | 46666fe7c47eb8cc9240028c30c363d5cbdbe540 /uav_model.m | |
parent | Update a lot of small things and add SIMULINK model (diff) | |
download | uav-734ee9e826b490137e3d8af627019098cafa1403.tar.gz uav-734ee9e826b490137e3d8af627019098cafa1403.zip |
Move uncertain model design into uav_model and add more design parameter
Diffstat (limited to '')
-rw-r--r-- | uav_model.m | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/uav_model.m b/uav_model.m index 5650946..ce7cddb 100644 --- a/uav_model.m +++ b/uav_model.m @@ -2,7 +2,9 @@ % % Compute model for UAV for given set of parameters. -function [model] = uav_model(params) +function [model] = uav_model(params, perf, uncert) + +model = struct(); % ------------------------------------------------------------------------ % Symbolic variables @@ -121,6 +123,17 @@ f = [ inv(J) * (tau - cross(Omega, J * Omega)); % rotational dynamics ]; +% Save function to compute the rotation matrix +model.FrameRot = @(pitch, roll, yaw) ... + subs(R, [phi, theta, psi], [pitch, roll, yaw]); + +% Save equations of non-linear model (algebraic) +model.nonlinear = struct(... + 'State', xi, ... + 'Inputs', u, ... + 'Dynamics', f ... +); + % ------------------------------------------------------------------------ % Linearization at equilibrium @@ -187,6 +200,14 @@ sys = ss(A, B, C, D); % T = params.actuators.MeasurementDelay; % sys = ss(A, B, C, D, 'OutputDelay', T); +% Save linearized dynamics (numerical) +model.linear = struct(... + 'Nx', nx, 'Nu', nu, 'Ny', ny, ... % number of states, inputs, and outputs + 'State', xi, 'Inputs', u, ... % state and input variables + 'StateEq', xi_eq, 'InputEq', u_eq, ... % where the system was linearized + 'StateSpace', sys ... % state space object +); + % ------------------------------------------------------------------------ % Check properties of linearized model eigvals = eig(A); @@ -242,27 +263,24 @@ if rank(Wo) < nx end % ------------------------------------------------------------------------ -% Save model +% Add uncertainties using SIMULINK model -model = struct(); +% Load simulink model with uncertainties and pass in parameters +h = load_system('uav_model_uncertain'); +hws = get_param('uav_model_uncertain', 'modelworkspace'); -% Function to compute the rotation matrix -model.FrameRot = @(pitch, roll, yaw) ... - subs(R, [phi, theta, psi], [pitch, roll, yaw]); +hws.assignin('model', model); +hws.assignin('perf', perf); +hws.assignin('uncert', uncert); -% Equations of non-linear model (algebraic) -model.nonlinear = struct(... - 'State', xi, ... - 'Inputs', u, ... - 'Dynamics', f ... -); +% Get uncertain model +ulmod = linmod('uav_model_uncertain'); +usys = ss(ulmod.a, ulmod.b, ulmod.c, ulmod.d); -% Linearized dynamics (numerical) -model.linear = struct(... - 'Nx', nx, 'Nu', nu, 'Ny', ny, ... % number of states, inputs, and outputs - 'State', xi, 'Inputs', u, ... % state and input variables - 'StateEq', xi_eq, 'InputEq', u_eq, ... % where the system was linearized - 'StateSpace', sys ... % state space object +% Save uncertain model +model.uncertain = struct(... + 'Simulink', ulmod, ... + 'StateSpace', usys ... ); end |