A sparse MPC solver for walking motion generation.
qp.h
Go to the documentation of this file.
1 
8 #ifndef QP_H
9 #define QP_H
10 
11 /****************************************
12  * TEMPLATES
13  ****************************************/
14 #include "smpc_common.h"
15 #include "state_handling.h"
16 
17 
18 /****************************************
19  * TEMPLATES
20  ****************************************/
21 
32 template <class PP>
34  const PP &ppar,
35  const double *x_coord,
36  const double *y_coord,
37  const double *init_state,
38  const bool tilde_state,
39  double* X)
40 {
41  double *control = &X[SMPC_NUM_STATE_VAR*ppar.N];
42  double *cur_state = X;
43  double X_tilde[6] = {
44  init_state[0], init_state[1], init_state[2],
45  init_state[3], init_state[4], init_state[5]};
46  if (!tilde_state)
47  {
48  state_handling::orig_to_tilde (ppar.h_initial, X_tilde);
49  }
50  const double *prev_state = X_tilde;
51 
52 
53  for (int i = 0; i < ppar.N; ++i)
54  {
55  //------------------------------------
56  /* inv(Cp*B). This is a [2 x 2] diagonal matrix (which is invertible if T^3/6-h*T is
57  * not equal to zero). The two elements on the main diagonal are equal, and only one of them
58  * is stored, which is equal to
59  1/(T^3/6 - h*T)
60  */
61  double iCpB = 1/(ppar.spar[i].B[0]);
62 
63  /* inv(Cp*B)*Cp*A. This is a [2 x 6] matrix with the following structure
64  iCpB_CpA = [a b c 0 0 0;
65  0 0 0 a b c];
66 
67  a = iCpB
68  b = iCpB*T
69  c = iCpB*T^2/2
70  * Only a,b and c are stored.
71  */
72  double iCpB_CpA[3] = {iCpB, iCpB*ppar.spar[i].A3, iCpB*ppar.spar[i].A6};
73  //------------------------------------
74 
75 
76  control[0] = -iCpB_CpA[0]*prev_state[0] - iCpB_CpA[1]*prev_state[1] - iCpB_CpA[2]*prev_state[2] + iCpB*x_coord[i];
77  control[1] = -iCpB_CpA[0]*prev_state[3] - iCpB_CpA[1]*prev_state[4] - iCpB_CpA[2]*prev_state[5] + iCpB*y_coord[i];
78 
79  cur_state[0] = prev_state[0] + ppar.spar[i].A3*prev_state[1] + ppar.spar[i].A6*prev_state[2] + ppar.spar[i].B[0]*control[0];
80  cur_state[1] = prev_state[1] + ppar.spar[i].A3*prev_state[2] + ppar.spar[i].B[1]*control[0];
81  cur_state[2] = prev_state[2] + ppar.spar[i].B[2]*control[0];
82  cur_state[3] = prev_state[3] + ppar.spar[i].A3*prev_state[4] + ppar.spar[i].A6*prev_state[5] + ppar.spar[i].B[0]*control[1];
83  cur_state[4] = prev_state[4] + ppar.spar[i].A3*prev_state[5] + ppar.spar[i].B[1]*control[1];
84  cur_state[5] = prev_state[5] + ppar.spar[i].B[2]*control[1];
85 
86 
87  prev_state = &X[SMPC_NUM_STATE_VAR*i];
88  cur_state = &X[SMPC_NUM_STATE_VAR*(i+1)];
89  control = &control[SMPC_NUM_CONTROL_VAR];
90  }
91 }
92 
93 #endif /*QP_H*/
94 
#define SMPC_NUM_STATE_VAR
Number of state variables.
Definition: smpc_solver.h:24
void form_init_fp_tilde(const PP &ppar, const double *x_coord, const double *y_coord, const double *init_state, const bool tilde_state, double *X)
Generates an initial feasible point.
Definition: qp.h:33
#define SMPC_NUM_CONTROL_VAR
Number of control variables.
Definition: smpc_solver.h:26
void orig_to_tilde(const double h, double *state)
Converts state from original variables to X_tilde.