Skip to content

Commit ffacd64

Browse files
committed
code clean up
1 parent 641ca0a commit ffacd64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+7902
-6
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ FORCES_NLP_solver/**
99
.ipynb_checkpoints/**
1010
MPC_SOLVER/**
1111
trained_policy/**
12-
script/**
1312
FORCES_*
1413
run*
1514
test.*

main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
if __name__ == '__main__':
1212

1313
gaze_methods = ['NoControl']
14-
planners = ['Primitive']
14+
planners = ['MPC']
1515

1616
# Environment difficulty
1717
motion_profiles = ['CVM']
@@ -37,7 +37,7 @@
3737
axis_range = [40, 250, 460]
3838
for start_pos, target_pos in vis.product(product(axis_range, axis_range), product(axis_range, axis_range)):
3939
if start_pos != target_pos:
40-
cfg = Params(debug=False,
40+
cfg = Params(debug=True,
4141
gaze_method=gaze_method,
4242
planner=planner,
4343
motion_profile=motion_profile,
@@ -51,7 +51,7 @@
5151
init_pos=start_pos,
5252
target_list=[target_pos],
5353
drone_view_range=360,
54-
static_map='empty_map.npy')
54+
static_map='maps/empty_map.npy')
5555
experiment = Experiment(cfg, result_dir)
5656
experiment.run()
5757

File renamed without changes.
File renamed without changes.
File renamed without changes.

mpc/MPC_SOLVER/MPC_SOLVER.m

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
% MPC_SOLVER - a fast solver generated by FORCESPRO v6.1.0
2+
%
3+
% OUTPUT = MPC_SOLVER(PARAMS) solves a multistage problem
4+
% subject to the parameters supplied in the following struct:
5+
% PARAMS.x0 - matrix of size [175x1]
6+
% PARAMS.xinit - matrix of size [4x1]
7+
% PARAMS.all_parameters - matrix of size [700x1]
8+
% PARAMS.num_of_threads - scalar
9+
%
10+
% OUTPUT returns the values of the last iteration of the solver where
11+
% OUTPUT.x01 - column vector of length 7
12+
% OUTPUT.x02 - column vector of length 7
13+
% OUTPUT.x03 - column vector of length 7
14+
% OUTPUT.x04 - column vector of length 7
15+
% OUTPUT.x05 - column vector of length 7
16+
% OUTPUT.x06 - column vector of length 7
17+
% OUTPUT.x07 - column vector of length 7
18+
% OUTPUT.x08 - column vector of length 7
19+
% OUTPUT.x09 - column vector of length 7
20+
% OUTPUT.x10 - column vector of length 7
21+
% OUTPUT.x11 - column vector of length 7
22+
% OUTPUT.x12 - column vector of length 7
23+
% OUTPUT.x13 - column vector of length 7
24+
% OUTPUT.x14 - column vector of length 7
25+
% OUTPUT.x15 - column vector of length 7
26+
% OUTPUT.x16 - column vector of length 7
27+
% OUTPUT.x17 - column vector of length 7
28+
% OUTPUT.x18 - column vector of length 7
29+
% OUTPUT.x19 - column vector of length 7
30+
% OUTPUT.x20 - column vector of length 7
31+
% OUTPUT.x21 - column vector of length 7
32+
% OUTPUT.x22 - column vector of length 7
33+
% OUTPUT.x23 - column vector of length 7
34+
% OUTPUT.x24 - column vector of length 7
35+
% OUTPUT.x25 - column vector of length 7
36+
%
37+
% [OUTPUT, EXITFLAG] = MPC_SOLVER(PARAMS) returns additionally
38+
% the integer EXITFLAG indicating the state of the solution with
39+
% 1 - OPTIMAL solution has been found (subject to desired accuracy)
40+
% 0 - Timeout - maximum number of iterations reached
41+
% -6 - NaN or INF occured during evaluation of functions and derivatives. Please check your initial guess.
42+
% -7 - Method could not progress. Problem may be infeasible. Run FORCESdiagnostics on your problem to check for most common errors in the formulation.
43+
% -98 - Thread error
44+
% -99 - Locking mechanism error
45+
% -100 - License error
46+
% -101 - Insufficient number of internal memory instances
47+
% -102 - Number of threads larger than specified
48+
%
49+
% [OUTPUT, EXITFLAG, INFO] = MPC_SOLVER(PARAMS) returns
50+
% additional information about the last iterate:
51+
% INFO.it - scalar: iteration number
52+
% INFO.it2opt - scalar: number of iterations needed to optimality (branch-and-bound)
53+
% INFO.res_eq - scalar: inf-norm of equality constraint residuals
54+
% INFO.res_ineq - scalar: inf-norm of inequality constraint residuals
55+
% INFO.rsnorm - scalar: norm of stationarity condition
56+
% INFO.rcompnorm - scalar: max of all complementarity violations
57+
% INFO.pobj - scalar: primal objective
58+
% INFO.dobj - scalar: dual objective
59+
% INFO.dgap - scalar: duality gap := pobj - dobj
60+
% INFO.rdgap - scalar: relative duality gap := |dgap / pobj |
61+
% INFO.mu - scalar: duality measure
62+
% INFO.mu_aff - scalar: duality measure (after affine step)
63+
% INFO.sigma - scalar: centering parameter
64+
% INFO.lsit_aff - scalar: number of backtracking line search steps (affine direction)
65+
% INFO.lsit_cc - scalar: number of backtracking line search steps (combined direction)
66+
% INFO.step_aff - scalar: step size (affine direction)
67+
% INFO.step_cc - scalar: step size (combined direction)
68+
% INFO.solvetime - scalar: total solve time
69+
% INFO.fevalstime - scalar: time spent in function evaluations
70+
% INFO.solver_id - column vector of length 8: solver ID of FORCESPRO solver
71+
%
72+
% See also COPYING

mpc/MPC_SOLVER/MPC_SOLVER_interface.c

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*
2+
* AD tool to FORCESPRO Template - missing information to be filled in by createADTool.m
3+
* (C) embotech AG, Zurich, Switzerland, 2013-2023. All rights reserved.
4+
*
5+
* This file is part of the FORCESPRO client, and carries the same license.
6+
*/
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#include "include/MPC_SOLVER.h"
13+
14+
#ifndef NULL
15+
#define NULL ((void *) 0)
16+
#endif
17+
18+
#include "MPC_SOLVER_model.h"
19+
20+
21+
22+
/* copies data from sparse matrix into a dense one */
23+
static void MPC_SOLVER_sparse2fullcopy(solver_int32_default nrow, solver_int32_default ncol, const solver_int32_default *colidx, const solver_int32_default *row, MPC_SOLVER_callback_float *data, MPC_SOLVER_float *out)
24+
{
25+
solver_int32_default i, j;
26+
27+
/* copy data into dense matrix */
28+
for(i=0; i<ncol; i++)
29+
{
30+
for(j=colidx[i]; j<colidx[i+1]; j++)
31+
{
32+
out[i*nrow + row[j]] = ((MPC_SOLVER_float) data[j]);
33+
}
34+
}
35+
}
36+
37+
38+
39+
40+
/* AD tool to FORCESPRO interface */
41+
extern solver_int32_default MPC_SOLVER_adtool2forces(MPC_SOLVER_float *x, /* primal vars */
42+
MPC_SOLVER_float *y, /* eq. constraint multiplers */
43+
MPC_SOLVER_float *l, /* ineq. constraint multipliers */
44+
MPC_SOLVER_float *p, /* parameters */
45+
MPC_SOLVER_float *f, /* objective function (scalar) */
46+
MPC_SOLVER_float *nabla_f, /* gradient of objective function */
47+
MPC_SOLVER_float *c, /* dynamics */
48+
MPC_SOLVER_float *nabla_c, /* Jacobian of the dynamics (column major) */
49+
MPC_SOLVER_float *h, /* inequality constraints */
50+
MPC_SOLVER_float *nabla_h, /* Jacobian of inequality constraints (column major) */
51+
MPC_SOLVER_float *hess, /* Hessian (column major) */
52+
solver_int32_default stage, /* stage number (0 indexed) */
53+
solver_int32_default iteration, /* iteration number of solver */
54+
solver_int32_default threadID /* Id of caller thread */)
55+
{
56+
/* AD tool input and output arrays */
57+
const MPC_SOLVER_callback_float *in[4];
58+
MPC_SOLVER_callback_float *out[7];
59+
60+
61+
/* Allocate working arrays for AD tool */
62+
63+
MPC_SOLVER_callback_float w[46];
64+
65+
/* temporary storage for AD tool sparse output */
66+
MPC_SOLVER_callback_float this_f = (MPC_SOLVER_callback_float) 0.0;
67+
MPC_SOLVER_float nabla_f_sparse[5];
68+
MPC_SOLVER_float h_sparse[6];
69+
MPC_SOLVER_float nabla_h_sparse[17];
70+
MPC_SOLVER_float c_sparse[4];
71+
MPC_SOLVER_float nabla_c_sparse[10];
72+
73+
74+
/* pointers to row and column info for
75+
* column compressed format used by AD tool */
76+
solver_int32_default nrow, ncol;
77+
const solver_int32_default *colind, *row;
78+
79+
/* set inputs for AD tool */
80+
in[0] = x;
81+
in[1] = p;
82+
in[2] = l;
83+
in[3] = y;
84+
85+
if ((0 <= stage && stage <= 23))
86+
{
87+
88+
89+
out[0] = &this_f;
90+
out[1] = nabla_f_sparse;
91+
MPC_SOLVER_objective_0(in, out, NULL, w, 0);
92+
if( nabla_f )
93+
{
94+
nrow = MPC_SOLVER_objective_0_sparsity_out(1)[0];
95+
ncol = MPC_SOLVER_objective_0_sparsity_out(1)[1];
96+
colind = MPC_SOLVER_objective_0_sparsity_out(1) + 2;
97+
row = MPC_SOLVER_objective_0_sparsity_out(1) + 2 + (ncol + 1);
98+
MPC_SOLVER_sparse2fullcopy(nrow, ncol, colind, row, nabla_f_sparse, nabla_f);
99+
}
100+
101+
out[0] = c_sparse;
102+
out[1] = nabla_c_sparse;
103+
MPC_SOLVER_dynamics_0(in, out, NULL, w, 0);
104+
if( c )
105+
{
106+
nrow = MPC_SOLVER_dynamics_0_sparsity_out(0)[0];
107+
ncol = MPC_SOLVER_dynamics_0_sparsity_out(0)[1];
108+
colind = MPC_SOLVER_dynamics_0_sparsity_out(0) + 2;
109+
row = MPC_SOLVER_dynamics_0_sparsity_out(0) + 2 + (ncol + 1);
110+
MPC_SOLVER_sparse2fullcopy(nrow, ncol, colind, row, c_sparse, c);
111+
}
112+
if( nabla_c )
113+
{
114+
nrow = MPC_SOLVER_dynamics_0_sparsity_out(1)[0];
115+
ncol = MPC_SOLVER_dynamics_0_sparsity_out(1)[1];
116+
colind = MPC_SOLVER_dynamics_0_sparsity_out(1) + 2;
117+
row = MPC_SOLVER_dynamics_0_sparsity_out(1) + 2 + (ncol + 1);
118+
MPC_SOLVER_sparse2fullcopy(nrow, ncol, colind, row, nabla_c_sparse, nabla_c);
119+
}
120+
121+
out[0] = h_sparse;
122+
out[1] = nabla_h_sparse;
123+
MPC_SOLVER_inequalities_0(in, out, NULL, w, 0);
124+
if( h )
125+
{
126+
nrow = MPC_SOLVER_inequalities_0_sparsity_out(0)[0];
127+
ncol = MPC_SOLVER_inequalities_0_sparsity_out(0)[1];
128+
colind = MPC_SOLVER_inequalities_0_sparsity_out(0) + 2;
129+
row = MPC_SOLVER_inequalities_0_sparsity_out(0) + 2 + (ncol + 1);
130+
MPC_SOLVER_sparse2fullcopy(nrow, ncol, colind, row, h_sparse, h);
131+
}
132+
if( nabla_h )
133+
{
134+
nrow = MPC_SOLVER_inequalities_0_sparsity_out(1)[0];
135+
ncol = MPC_SOLVER_inequalities_0_sparsity_out(1)[1];
136+
colind = MPC_SOLVER_inequalities_0_sparsity_out(1) + 2;
137+
row = MPC_SOLVER_inequalities_0_sparsity_out(1) + 2 + (ncol + 1);
138+
MPC_SOLVER_sparse2fullcopy(nrow, ncol, colind, row, nabla_h_sparse, nabla_h);
139+
}
140+
}
141+
if ((24 == stage))
142+
{
143+
144+
145+
out[0] = &this_f;
146+
out[1] = nabla_f_sparse;
147+
MPC_SOLVER_objective_1(in, out, NULL, w, 0);
148+
if( nabla_f )
149+
{
150+
nrow = MPC_SOLVER_objective_1_sparsity_out(1)[0];
151+
ncol = MPC_SOLVER_objective_1_sparsity_out(1)[1];
152+
colind = MPC_SOLVER_objective_1_sparsity_out(1) + 2;
153+
row = MPC_SOLVER_objective_1_sparsity_out(1) + 2 + (ncol + 1);
154+
MPC_SOLVER_sparse2fullcopy(nrow, ncol, colind, row, nabla_f_sparse, nabla_f);
155+
}
156+
157+
out[0] = h_sparse;
158+
out[1] = nabla_h_sparse;
159+
MPC_SOLVER_inequalities_1(in, out, NULL, w, 0);
160+
if( h )
161+
{
162+
nrow = MPC_SOLVER_inequalities_1_sparsity_out(0)[0];
163+
ncol = MPC_SOLVER_inequalities_1_sparsity_out(0)[1];
164+
colind = MPC_SOLVER_inequalities_1_sparsity_out(0) + 2;
165+
row = MPC_SOLVER_inequalities_1_sparsity_out(0) + 2 + (ncol + 1);
166+
MPC_SOLVER_sparse2fullcopy(nrow, ncol, colind, row, h_sparse, h);
167+
}
168+
if( nabla_h )
169+
{
170+
nrow = MPC_SOLVER_inequalities_1_sparsity_out(1)[0];
171+
ncol = MPC_SOLVER_inequalities_1_sparsity_out(1)[1];
172+
colind = MPC_SOLVER_inequalities_1_sparsity_out(1) + 2;
173+
row = MPC_SOLVER_inequalities_1_sparsity_out(1) + 2 + (ncol + 1);
174+
MPC_SOLVER_sparse2fullcopy(nrow, ncol, colind, row, nabla_h_sparse, nabla_h);
175+
}
176+
}
177+
178+
/* add to objective */
179+
if (f != NULL)
180+
{
181+
*f += ((MPC_SOLVER_float) this_f);
182+
}
183+
184+
return 0;
185+
}
186+
187+
#ifdef __cplusplus
188+
} /* extern "C" */
189+
#endif

mpc/MPC_SOLVER/MPC_SOLVER_interface.o

5.05 KB
Binary file not shown.

0 commit comments

Comments
 (0)