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

Function main

examples/codegen_cartpole.cpp:28–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26std_fs::path output_dir_relative = "tinympc_generated_code_cartpole_example/";
27
28int main()
29{
30 TinySolver *solver;
31
32 tinytype rho_value = 1.0;
33
34 // Discrete, linear model of upright cartpole.
35 tinytype Adyn_data[NSTATES * NSTATES] = {1.0, 0.01, 0.0, 0.0, 0.0, 1.0, 0.039, 0.0, 0.0, 0.0, 1.002, 0.01, 0.0, 0.0, 0.458, 1.002};
36 tinytype Bdyn_data[NSTATES * NINPUTS] = {0.0, 0.02, 0.0, 0.067};
37 tinytype Q_data[NSTATES] = {10.0, 1.0, 10.0, 1.0};
38 tinytype R_data[NINPUTS] = {1.0};
39
40 tinyMatrix Adyn = Map<Matrix<tinytype, NSTATES, NSTATES, RowMajor>>(Adyn_data);
41 tinyMatrix Bdyn = Map<Matrix<tinytype, NSTATES, NINPUTS>>(Bdyn_data);
42 tinyVector fdyn = tiny_VectorNx::Zero();
43 tinyVector Q = Map<Matrix<tinytype, NSTATES, 1>>(Q_data);
44 tinyVector R = Map<Matrix<tinytype, NINPUTS, 1>>(R_data);
45
46 tinyMatrix x_min = tiny_MatrixNxNh::Constant(-1e17);
47 tinyMatrix x_max = tiny_MatrixNxNh::Constant(1e17);
48 tinyMatrix u_min = tiny_MatrixNuNhm1::Constant(-1e17);
49 tinyMatrix u_max = tiny_MatrixNuNhm1::Constant(1e17);
50
51 // Set up problem
52 int verbose = 0;
53 int status = tiny_setup(&solver,
54 Adyn, Bdyn, fdyn, Q.asDiagonal(), R.asDiagonal(),
55 rho_value, NSTATES, NINPUTS, NHORIZON, verbose);
56 // Set bound constraints
57 status = tiny_set_bound_constraints(solver, x_min, x_max, u_min, u_max);
58
59 tiny_codegen(solver, std_fs::absolute(output_dir_relative).string().c_str(), verbose);
60
61 return 0;
62}
63
64} /* extern "C" */

Callers

nothing calls this directly

Calls 4

tiny_setupFunction · 0.85
tiny_codegenFunction · 0.85
asDiagonalMethod · 0.80

Tested by

no test coverage detected