mirror of
https://github.com/ROB-535-F21-Team-3/Control-Project.git
synced 2025-08-19 17:22:45 +00:00
More outputs / debugging info
- Decrease `sim_stop_idx` to 1500 - Add some debugging messages for when simulation hits limit or when `fmincon` can't satisfy constraints - Add more `fmincon` outputs for future debugging - Add obstacle information to `getTrajectoryInfo` call in `part2_test_controller.m` to see when car crashes
This commit is contained in:
@@ -54,9 +54,9 @@ classdef MPC_Class
|
|||||||
];
|
];
|
||||||
|
|
||||||
% Simulation Parameters
|
% Simulation Parameters
|
||||||
T_s = 0.01; % Step Size [s]
|
T_s = 0.01; % Step Size [s]
|
||||||
T_p = 0.5; % Prediction Horizon [s]
|
T_p = 0.5; % Prediction Horizon [s]
|
||||||
sim_stop_idx = 2e3; % Index in reference trajectory to stop sim
|
sim_stop_idx = 1.5e3; % Index in reference trajectory to stop sim
|
||||||
|
|
||||||
% Decision Variables
|
% Decision Variables
|
||||||
nstates = 6; % Number of states per prediction
|
nstates = 6; % Number of states per prediction
|
||||||
@@ -130,6 +130,7 @@ classdef MPC_Class
|
|||||||
% Stop simulation when `sim_stop_idx` is reached
|
% Stop simulation when `sim_stop_idx` is reached
|
||||||
obj.FLAG_terminate = 0;
|
obj.FLAG_terminate = 0;
|
||||||
if obj.ref_idx > obj.sim_stop_idx
|
if obj.ref_idx > obj.sim_stop_idx
|
||||||
|
disp('Reached simulation stop index')
|
||||||
obj.FLAG_terminate = 1;
|
obj.FLAG_terminate = 1;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -146,8 +147,13 @@ classdef MPC_Class
|
|||||||
[Aeq, beq] = obj.eq_cons(A, B);
|
[Aeq, beq] = obj.eq_cons(A, B);
|
||||||
[Lb, Ub] = obj.bound_cons();
|
[Lb, Ub] = obj.bound_cons();
|
||||||
|
|
||||||
Z_err = ...
|
[ ... % `fmincon` outputs
|
||||||
fmincon( ...
|
Z_err, ... % x: Solution
|
||||||
|
J_val, ... % fval: Objective function value at solution
|
||||||
|
exitflag, ... % exitflag: Reason `fmincon` stopped
|
||||||
|
output, ... % output: Information about the optimization process
|
||||||
|
] = ...
|
||||||
|
fmincon( ... % `fmincon` inputs
|
||||||
@obj.cost_fun, ... % fun: Function to minimize
|
@obj.cost_fun, ... % fun: Function to minimize
|
||||||
Z_err_init, ... % x0: Initial point
|
Z_err_init, ... % x0: Initial point
|
||||||
[], ... % A: Linear inequality constraints
|
[], ... % A: Linear inequality constraints
|
||||||
@@ -160,6 +166,11 @@ classdef MPC_Class
|
|||||||
obj.options ... % options: Optimization options
|
obj.options ... % options: Optimization options
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if exitflag == -2
|
||||||
|
disp('No feasible point was found')
|
||||||
|
obj.FLAG_terminate = 1;
|
||||||
|
end
|
||||||
|
|
||||||
% NOTE: Error = Actual - Reference
|
% NOTE: Error = Actual - Reference
|
||||||
% => Actual = Error + Reference
|
% => Actual = Error + Reference
|
||||||
Z_ref = obj.get_ref_decision_variable();
|
Z_ref = obj.get_ref_decision_variable();
|
||||||
|
@@ -5,7 +5,7 @@ clc;
|
|||||||
|
|
||||||
%% Call simulation functions
|
%% Call simulation functions
|
||||||
[Y,U,t_total,t_update,Xobs] = forwardIntegrate();
|
[Y,U,t_total,t_update,Xobs] = forwardIntegrate();
|
||||||
info = getTrajectoryInfo(Y,U)
|
info = getTrajectoryInfo(Y,U,Xobs)
|
||||||
|
|
||||||
%% Figures
|
%% Figures
|
||||||
% Plot segmented trajectory for debugging purposes
|
% Plot segmented trajectory for debugging purposes
|
||||||
|
Reference in New Issue
Block a user