1
+ #include < iostream>
2
+
3
+ #include " orlqp/symbolic/util.hpp"
4
+ #include " orlqp/SymbolicQPProblem.hpp"
5
+
6
+ using namespace orlqp ;
7
+
8
+ int main (void )
9
+ {
10
+
11
+ // Params
12
+ const int nodes_per_step = 4 ;
13
+ const int num_steps = 3 ;
14
+ const int num_nodes = nodes_per_step * num_steps;
15
+
16
+ /* Objective Function */
17
+
18
+ const int num_states = num_nodes * 4 ;
19
+ auto q = createSymbolVector (num_states, " q" );
20
+ auto q_ref = createSymbolVector (num_states, " Qr" ); // const
21
+ auto w_target = createSymbolVector (num_states, " Wtar" ); // const
22
+ GinacEx J_target;
23
+ for (int i = 0 ; i < num_states; i++)
24
+ {
25
+ J_target += w_target[i] * (q[i] - q_ref[i]) * (q[i] - q_ref[i]);
26
+ }
27
+
28
+ auto sx = createSymbolVector (num_steps, " sx" );
29
+ auto sx_ref = createSymbolVector (num_steps, " Sxr" ); // const
30
+ auto w_stepx = createSymbolVector (num_states, " Wstpx" ); // const
31
+ GinacEx J_stepx;
32
+ for (int i = 0 ; i < num_steps; i++)
33
+ {
34
+ J_stepx += w_stepx[i] * (sx[i] - sx_ref[i]) * (sx[i] - sx_ref[i]);
35
+ }
36
+
37
+ auto sy = createSymbolVector (num_steps, " sy" );
38
+ auto rho_step = createSymbolVector (num_nodes, " rho_s" );
39
+ auto sy_ref = createSymbolVector (num_steps, " Syr" ); // const
40
+ auto w_stepy = createSymbolVector (num_nodes, " Wstpy" ); // const
41
+ GinacEx J_stepy;
42
+ for (int i = 0 ; i < num_nodes; i++)
43
+ {
44
+ J_stepy += w_stepy[i] * rho_step[i] * rho_step[i];
45
+ }
46
+
47
+ const int num_controls = num_nodes * 2 ;
48
+ auto u = createSymbolVector (num_controls, " u" );
49
+ auto p_foot = createSymbolVector (2 , " Pft" ); // const
50
+ GinacMatrix u_ref (num_controls, 1 );
51
+ for (int i = 0 ; i < num_nodes; i++)
52
+ {
53
+ const int step_i = std::floor (i / nodes_per_step);
54
+ GinacEx sum_sx, sum_sy;
55
+ for (int j = 0 ; j < step_i; j++)
56
+ {
57
+ sum_sx += sx[j];
58
+ sum_sy += sy[j];
59
+ }
60
+ u_ref[2 * i - 1 ] = p_foot[0 ] + sum_sx;
61
+ u_ref[2 * i] = p_foot[1 ] + sum_sy;
62
+ }
63
+ auto w_effort = createSymbolVector (num_controls, " Weff" ); // const
64
+ GinacEx J_effort;
65
+ for (int i = 0 ; i < num_controls; i++)
66
+ {
67
+ J_effort += w_effort[i] * (u[i] - u_ref[i]) * (u[i] - u_ref[i]);
68
+ }
69
+
70
+ auto rho_avoid = createSymbolVector (num_nodes, " rho_a" );
71
+ auto w_avoid = createSymbolVector (num_nodes, " Wavd" ); // const
72
+ GinacEx J_avoid;
73
+ for (int i = 0 ; i < num_nodes; i++)
74
+ {
75
+ J_avoid += w_avoid[i] * rho_avoid[i] * rho_avoid[i];
76
+ }
77
+
78
+ auto rho_input = createSymbolVector (num_nodes, " rho_i" );
79
+ auto w_input = createSymbolVector (num_nodes, " Winp" ); // const
80
+ GinacEx J_input;
81
+ for (int i = 0 ; i < num_nodes; i++)
82
+ {
83
+ J_input += w_input[i] * rho_input[i] * rho_input[i];
84
+ }
85
+
86
+ GinacEx J = J_target + J_stepx + J_stepy + J_effort + J_avoid + J_input;
87
+
88
+ /* Constraints + Bounds */
89
+ /* TODO */
90
+
91
+ SymbolVector x = combineSymbolVectors ({q, u, sx, sy, rho_step, rho_avoid, rho_input});
92
+ SymbolVector c = combineSymbolVectors ({q_ref, sx_ref, sy_ref, p_foot, w_target, w_stepx, w_stepy, w_effort, w_avoid, w_input});
93
+
94
+ /* Symbolic QP Problem */
95
+ /* TODO */
96
+
97
+ GinacMatrix hessian = calculateExpressionHessian (J, x);
98
+ GinacMatrix gradient = calculateExpressionGradient (J, x);
99
+
100
+ return 0 ;
101
+ }
0 commit comments