A sparse MPC solver for walking motion generation.
as_matrix_E.cpp
Go to the documentation of this file.
1 
9 /****************************************
10  * INCLUDES
11  ****************************************/
12 
13 #include "as_matrix_E.h"
14 
15 
16 
17 /****************************************
18  * FUNCTIONS
19  ****************************************/
20 namespace AS
21 {
29  void matrix_E::form_Ex (const problem_parameters& ppar, const double *x, double *result)
30  {
31  const double *control = &x[ppar.N*SMPC_NUM_STATE_VAR];
32  // a pointer to 6 current elements of result
33  double *res = result;
34  // a pointer to 6 current state variables
35  const double *xc = x;
36  const double *xcp = NULL;
37 
38 
39  state_parameters stp = ppar.spar[0];
40 
41  // result = -I * x + B * u
42  res[0] = -xc[0] + stp.B[0] * control[0];
43  res[1] = -xc[1] + stp.B[1] * control[0];
44  res[2] = -xc[2] + stp.B[2] * control[0];
45  res[3] = -xc[3] + stp.B[0] * control[1];
46  res[4] = -xc[4] + stp.B[1] * control[1];
47  res[5] = -xc[5] + stp.B[2] * control[1];
48 
49 
50  for (int i = 1; i < ppar.N; i++)
51  {
52  // next control variables
53  control = &control[SMPC_NUM_CONTROL_VAR];
54  res = &res[SMPC_NUM_STATE_VAR];
55  xcp = xc;
56  xc = &xc[SMPC_NUM_STATE_VAR];
57 
58  stp = ppar.spar[i];
59 
60  // result = -I * x + B * u + A * xp
61  res[0] = -xc[0] + stp.B[0] * control[0] + xcp[0] + stp.A3 * xcp[1] + stp.A6 * xcp[2];
62  res[1] = -xc[1] + stp.B[1] * control[0] + xcp[1] + stp.A3 * xcp[2];
63  res[2] = -xc[2] + stp.B[2] * control[0] + xcp[2];
64  res[3] = -xc[3] + stp.B[0] * control[1] + xcp[3] + stp.A3 * xcp[4] + stp.A6 * xcp[5];
65  res[4] = -xc[4] + stp.B[1] * control[1] + xcp[4] + stp.A3 * xcp[5];
66  res[5] = -xc[5] + stp.B[2] * control[1] + xcp[5];
67  }
68  }
69 
70 
78  void matrix_E::form_i2HETx (const problem_parameters& ppar, const double *x, double *result)
79  {
80  double i2Q[3] = {ppar.i2Q[0], ppar.i2Q[1], ppar.i2Q[2]};
81  int i;
82 
83  // a pointer to 6 current elements of result
84  double *res = result;
85  double *control_res = &result[ppar.N*SMPC_NUM_STATE_VAR];
86  // a pointer to 6 current elements of nu
87  const double *xc = x;
88  const double *xcn = &xc[SMPC_NUM_STATE_VAR];
89 
90  for (i = 0; i < ppar.N-1; i++)
91  {
92  double A3 = ppar.spar[i+1].A3;
93  double A6 = ppar.spar[i+1].A6;
94 
95 
96  // result = i2H * [-I' A'] * x
97  res[0] = -i2Q[0] * (-xc[0] + xcn[0]);
98  res[1] = -i2Q[1] * (-xc[1] + A3 * xcn[0] + xcn[1]);
99  res[2] = -i2Q[2] * (-xc[2] + A6 * xcn[0] + A3 * xcn[1] + xcn[2]);
100  res[3] = -i2Q[0] * (-xc[3] + xcn[3]);
101  res[4] = -i2Q[1] * (-xc[4] + A3 * xcn[3] + xcn[4]);
102  res[5] = -i2Q[2] * (-xc[5] + A6 * xcn[3] + A3 * xcn[4] + xcn[5]);
103 
104 
105  // result = i2H * B' * x
106  state_parameters stp = ppar.spar[i];
107  control_res[0] = -ppar.i2P * (stp.B[0] * xc[0] + stp.B[1] * xc[1] + stp.B[2] * xc[2]);
108  control_res[1] = -ppar.i2P * (stp.B[0] * xc[3] + stp.B[1] * xc[4] + stp.B[2] * xc[5]);
109 
110 
111  res = &res[SMPC_NUM_STATE_VAR];
112  control_res = &control_res[SMPC_NUM_CONTROL_VAR];
113  xc = xcn;
114  xcn = &xcn[SMPC_NUM_STATE_VAR];
115  }
116 
117 
118  // result = i2H * [-I' A'] * x
119  res[0] = -(-i2Q[0] * xc[0]);
120  res[1] = -(-i2Q[1] * xc[1]);
121  res[2] = -(-i2Q[2] * xc[2]);
122  res[3] = -(-i2Q[0] * xc[3]);
123  res[4] = -(-i2Q[1] * xc[4]);
124  res[5] = -(-i2Q[2] * xc[5]);
125 
126 
127  // result = i2H * B' * x
128  state_parameters stp = ppar.spar[i];
129  control_res[0] = -ppar.i2P * (stp.B[0] * xc[0] + stp.B[1] * xc[1] + stp.B[2] * xc[2]);
130  control_res[1] = -ppar.i2P * (stp.B[0] * xc[3] + stp.B[1] * xc[4] + stp.B[2] * xc[5]);
131  }
132 }
#define SMPC_NUM_STATE_VAR
Number of state variables.
Definition: smpc_solver.h:24
void form_i2HETx(const problem_parameters &, const double *, double *)
Forms i2H * E' * x.
Definition: as_matrix_E.cpp:78
void form_Ex(const problem_parameters &, const double *, double *)
Forms E*x.
Definition: as_matrix_E.cpp:29
A set of problem parameters.
#define SMPC_NUM_CONTROL_VAR
Number of control variables.
Definition: smpc_solver.h:26
state_parameters * spar