A sparse MPC solver for walking motion generation.
rect_constraint.cpp
Go to the documentation of this file.
1 
9 /****************************************
10  * INCLUDES
11  ****************************************/
12 
13 #include "rect_constraint.h"
14 
15 /****************************************
16  * FUNCTIONS
17  ****************************************/
18 
38 {
39  D[0] = 1.0; D[4] = 0.0;
40  D[1] = 0.0; D[5] = 1.0;
41  D[2] = -1.0; D[6] = 0.0;
42  D[3] = 0.0; D[7] = -1.0;
43 
44  d[0] = d_[0];
45  d[1] = d_[1];
46  d[2] = d_[2];
47  d[3] = d_[3];
48 
49  d_orig[0] = d[0];
50  d_orig[1] = d[1];
51  d_orig[2] = d[2];
52  d_orig[3] = d[3];
53 
54  Constraints2Vert(); // determine coordinates of vertices
55 }
56 
57 
58 
70 void RectangularConstraint_ZMP::rotate_translate(const double ca, const double sa, const double x, const double y)
71 {
72  // D = D*R'
73  D[0] = ca; D[4] = sa;
74  D[1] = -sa; D[5] = ca;
75  D[2] = -ca; D[6] = -sa;
76  D[3] = sa; D[7] = -ca;
77 
78  // d = d - D*p
79  d[0] = d_orig[0] + D[0]*x + D[4]*y;
80  d[1] = d_orig[1] + D[1]*x + D[5]*y;
81  d[2] = d_orig[2] + D[2]*x + D[6]*y;
82  d[3] = d_orig[3] + D[3]*x + D[7]*y;
83 
84  Constraints2Vert(); // determine coordinates of vertices
85 }
86 
87 
88 
100 {
101  double det;
102 
103  // Indexes of ctr.D
104  // 0 4
105  // 1 5
106  // 2 6
107  // 3 7
108 
109  // D d inv (D)
110  // |0 4| 0 1/det * | 7 -4|
111  // |3 7| 3 |-3 0|
112  det = D[0]*D[7] - D[3]*D[4];
113  vert(0,0) = D[7]/det*d[0] - D[4]/det*d[3];
114  vert(0,1) = -D[3]/det*d[0] + D[0]/det*d[3];
115 
116  // |0 4| 0 | 5 -4|
117  // |1 5| 1 |-1 0|
118  det = D[0]*D[5] - D[4]*D[1];
119  vert(1,0) = D[5]/det*d[0] - D[4]/det*d[1];
120  vert(1,1) = -D[1]/det*d[0] + D[0]/det*d[1];
121 
122  // |1 5| 1 | 6 -5|
123  // |2 6| 2 |-2 1|
124  det = D[1]*D[6] - D[5]*D[2];
125  vert(2,0) = D[6]/det*d[1] - D[5]/det*d[2];
126  vert(2,1) = -D[2]/det*d[1] + D[1]/det*d[2];
127 
128  // |2 6| 2 | 7 -6|
129  // |3 7| 3 |-3 2|
130  det = D[2]*D[7] - D[3]*D[6];
131  vert(3,0) = D[7]/det*d[2] - D[6]/det*d[3];
132  vert(3,1) = -D[3]/det*d[2] + D[2]/det*d[3];
133 }
134 
MatrixXd vert
Absolute coordinates of vertices.
double D[4 *2]
Matrix of the constraints D*z <= d (where z is a 2D point).
double d_orig[4]
Size of the support polygon for a single support (no rotation / translation).
void Constraints2Vert()
Computes the vertices of a polygon from the constraints (D*x <= d)
RectangularConstraint_ZMP(const double *)
A constructor.
void rotate_translate(const double, const double, const double, const double)
translates from [0;0] to "p" and rotates from 0 to "angle". The 0 initial angle implies that D = [eye...