MCPcopy Create free account
hub / github.com/TinyMPC/TinyMPC / tiny_setup

Function tiny_setup

src/tinympc/tiny_api.cpp:21–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21int tiny_setup(TinySolver** solverp,
22 tinyMatrix Adyn, tinyMatrix Bdyn, tinyMatrix fdyn, tinyMatrix Q, tinyMatrix R,
23 tinytype rho, int nx, int nu, int N, int verbose) {
24
25 TinySolution *solution = new TinySolution();
26 TinyCache *cache = new TinyCache();
27 TinySettings *settings = new TinySettings();
28 TinyWorkspace *work = new TinyWorkspace();
29 TinySolver *solver = new TinySolver();
30
31 solver->solution = solution;
32 solver->cache = cache;
33 solver->settings = settings;
34 solver->work = work;
35
36 *solverp = solver;
37
38 // Initialize solution
39 solution->iter = 0;
40 solution->solved = 0;
41 solution->x = tinyMatrix::Zero(nx, N);
42 solution->u = tinyMatrix::Zero(nu, N-1);
43
44 // Initialize settings
45 tiny_set_default_settings(settings);
46
47 // Initialize workspace
48 work->nx = nx;
49 work->nu = nu;
50 work->N = N;
51
52 // Make sure arguments are the correct shapes
53 int status = 0;
54 status |= check_dimension("State transition matrix (A)", "rows", Adyn.rows(), nx);
55 status |= check_dimension("State transition matrix (A)", "columns", Adyn.cols(), nx);
56 status |= check_dimension("Input matrix (B)", "rows", Bdyn.rows(), nx);
57 status |= check_dimension("Input matrix (B)", "columns", Bdyn.cols(), nu);
58 status |= check_dimension("Affine vector (f)", "rows", fdyn.rows(), nx);
59 status |= check_dimension("Affine vector (f)", "columns", fdyn.cols(), 1);
60 status |= check_dimension("State stage cost (Q)", "rows", Q.rows(), nx);
61 status |= check_dimension("State stage cost (Q)", "columns", Q.cols(), nx);
62 status |= check_dimension("State input cost (R)", "rows", R.rows(), nu);
63 status |= check_dimension("State input cost (R)", "columns", R.cols(), nu);
64 if (status) {
65 return status;
66 }
67
68 work->x = tinyMatrix::Zero(nx, N);
69 work->u = tinyMatrix::Zero(nu, N-1);
70
71 work->q = tinyMatrix::Zero(nx, N);
72 work->r = tinyMatrix::Zero(nu, N-1);
73
74 work->p = tinyMatrix::Zero(nx, N);
75 work->d = tinyMatrix::Zero(nu, N-1);
76
77 // Bound constraint slack variables
78 work->v = tinyMatrix::Zero(nx, N);

Callers 8

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 8

check_dimensionFunction · 0.85
asDiagonalMethod · 0.80
rowsMethod · 0.45
colsMethod · 0.45
diagonalMethod · 0.45

Tested by

no test coverage detected