Update part2 function to use MPC_Class

- Update part2 deliverable function to use `MPC_Class`
- Clean-up some comments in `MPC_Class`
- Add MPC tunable parameters to `MPC_Class`
- Add TODO comments
This commit is contained in:
Sravan Balaji
2021-12-10 08:05:47 -05:00
parent b562360f6b
commit d16e25ca85
2 changed files with 47 additions and 22 deletions

View File

@@ -34,8 +34,10 @@ function [Utemp, FLAG_terminate] = ROB535_ControlProject_part2_Team3(TestTrack,X
% %
% Written by: Sravan Balaji, Xenia Demenchuk, and Peter Pongsachai % Written by: Sravan Balaji, Xenia Demenchuk, and Peter Pongsachai
% Created: 30 Nov 2021 % Created: 30 Nov 2021
Utemp = NaN(51,2); load('ROB535_ControlProject_part1_Team3.mat');
Utemp(:,1) = 0 .* ones(51,1); % delta Y_ref = ROB535_ControlProject_part1_state;
Utemp(:,2) = 5000 .* ones(51,1); % F_x U_ref = ROB535_ControlProject_part1_input;
FLAG_terminate = rand(1,1) > 0.9;
obj = MPC_Class(TestTrack, Y_ref, U_ref);
[Utemp, FLAG_terminate] = obj.compute_inputs(Xobs_seen, curr_state);
end end

View File

@@ -1,9 +1,18 @@
% Filename: MPC_Class.m
% Written by: Sravan Balaji, Xenia Demenchuk, and Peter Pongsachai % Written by: Sravan Balaji, Xenia Demenchuk, and Peter Pongsachai
% Created: 10 Dec 2021 % Created: 10 Dec 2021
classdef MPC_Class classdef MPC_Class
%MPC_CLASS Summary of this class goes here %MPC_CLASS TODO: Summary of this class goes here
% Detailed explanation goes here % TODO: Detailed explanation goes here
% Miscellaneous Notes
% - Error in States = Actual - Reference
% - Y: State [x; u; y; v; psi; r]
% - Y_err: State Error [x - x_ref; u - u_ref; y - y_ref; v - v_ref; psi - psi_ref; r - r_ref]
% - U: Input [delta_f; F_x]
% - U_err: Input Error [delta_f - delta_f_ref; F_x - F_x_ref]
% - Z: Decision Variable [Y(0);...;Y(n+1);U(0);...;U(n)]
% - Z_err: Decision Variable Error [Y_err(0);...;Y_err(n+1);U_err(0);...;U_err(n)]
properties properties
% Vehicle Parameters (Table 1) % Vehicle Parameters (Table 1)
@@ -31,12 +40,12 @@ classdef MPC_Class
% Initial Conditions (Equation 15) % Initial Conditions (Equation 15)
state_init = [ ... state_init = [ ...
287; ... % x [m] 287; ... % x [m]
5; ... % u [m/s] 5; ... % u [m/s]
-176; ... % y [m] -176; ... % y [m]
0; ... % v [m/s] 0; ... % v [m/s]
2; ... % psi [rad] 2; ... % psi [rad]
0; ... % r [rad/s] 0; ... % r [rad/s]
]; ];
% Simulation Parameters % Simulation Parameters
@@ -44,9 +53,6 @@ classdef MPC_Class
T_p = 0.5; % Prediction Horizon [s] T_p = 0.5; % Prediction Horizon [s]
% Decision Variables % Decision Variables
% Y: State [x; u; y; v; psi; r]
% U: Input [delta_f; F_x]
% Z: Decision Variable [Y(0);...;Y(n+1);U(0);...;U(n)]
npred = T_p / T_s; npred = T_p / T_s;
nstates = 6; nstates = 6;
ninputs = 2; ninputs = 2;
@@ -56,9 +62,23 @@ classdef MPC_Class
TestTrack; TestTrack;
Y_ref; Y_ref;
U_ref; U_ref;
% MPC Tunable Parameters
Q = [ ... % State Error Costs
1; ... % x_err [m]
1; ... % u_err [m/s]
1; ... % y_err [m]
1; ... % v_err [m/s]
1; ... % psi_err [rad]
1; ... % r_err [rad/s]
];
R = [ ... % Input Error Costs
0.1; ... % delta_f_err [rad]
0.01; ... % F_x_err [N]
];
end end
methods methods (Access = public)
function obj = MPC_Class(TestTrack, Y_ref, U_ref) function obj = MPC_Class(TestTrack, Y_ref, U_ref)
%MPC_CLASS Construct an instance of this class %MPC_CLASS Construct an instance of this class
% Store provided track & trajectory information % Store provided track & trajectory information
@@ -67,11 +87,14 @@ classdef MPC_Class
obj.U_ref = U_ref; obj.U_ref = U_ref;
end end
% function outputArg = method1(obj,inputArg) function [Utemp, FLAG_terminate] = compute_inputs(obj, Xobs_seen, curr_state)
% %METHOD1 Summary of this method goes here %compute_inputs TODO: Summary of this method goes here
% % Detailed explanation goes here % TODO: Detailed explanation goes here
% outputArg = obj.Property1 + inputArg; end
% end end
methods (Access = private)
% TODO: Add MPC related private functions
end end
end end