-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.m
44 lines (31 loc) · 873 Bytes
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
clear all
addpath(genpath([pwd '/build']))
addpath(genpath([pwd '/c_generated_code']))
import casadi.*
%% Horizon parameters
N = 100;
Ts = 0.1; % sampling time [s]
T = N*Ts; % time horizon length [s]
%% Create solver using native MEX interface
if exist('ocp','var')
ocp.delete;
clear ocp
end
ocp_model = model_setup(T);
ocp_opts = solver_setup(N,T);
ocp = acados_ocp(ocp_model, ocp_opts);
ocp.generate_c_code;
%% Create solver using template based interface
% Uncomment and run this section to exploit generated code
cd c_generated_code
t_ocp = long_control_mex_solver;
cd ..
% keyboard
disp('SIM native')
results = run_simulation(ocp, N);
% keyboard
disp('SIM templated')
t_results = run_simulation(t_ocp, N);
semilogy(abs(results.u - t_results.u))
disp(['diff control trajs:', num2str(norm(results.u - t_results.u))])
% norm(results.u - t_results.u)