A sparse MPC solver for walking motion generation (old version).
solver/chol_solve_ip.cpp
Go to the documentation of this file.
00001 
00009 /****************************************
00010  * INCLUDES 
00011  ****************************************/
00012 
00013 #include "chol_solve_ip.h"
00014 
00015 
00016 /****************************************
00017  * FUNCTIONS 
00018  ****************************************/
00019 
00020 //==============================================
00021 // constructors / destructors
00022 
00028 chol_solve_ip::chol_solve_ip (const int N) : ecL(N)
00029 {
00030     w = new double[N*SMPC_NUM_STATE_VAR];
00031 }
00032 
00033 
00034 chol_solve_ip::~chol_solve_ip()
00035 {
00036     if (w != NULL)
00037         delete w;
00038 }
00039 //==============================================
00040 
00041 
00051 void chol_solve_ip::solve(
00052         const problem_parameters& ppar, 
00053         const double *i2hess_grad,
00054         const double *i2hess,
00055         const double *x, 
00056         double *dx)
00057 {
00058     double *s_w = w;
00059     int i,j;
00060     double i2Q[2] = {ppar.i2Q[1], ppar.i2Q[2]};
00061 
00062 
00063     // generate L
00064     ecL.form (ppar, i2hess);
00065 
00066     // obtain s = E * x;
00067     E.form_Ex (ppar, i2hess_grad, s_w);
00068 
00069     // obtain w
00070     ecL.solve_forward(ppar.N, s_w);
00071     ecL.solve_backward(ppar.N, s_w);
00072 
00073     // E' * w
00074     E.form_ETx (ppar, s_w, dx);
00075 
00076     
00077     // dx = -iH*(grad + E'*w)
00078     //
00079     // dx   -( -i2hess_grad  + inv(H) *   dx   ) 
00080     for (i = 0,j = 0; i < ppar.N*2; i++)
00081     {
00082         // dx for state variables
00083         dx[j] = i2hess_grad[j] - i2hess[i] * dx[j]; 
00084         j++;
00085         dx[j] = i2hess_grad[j] - i2Q[0] * dx[j]; 
00086         j++;
00087         dx[j] = i2hess_grad[j] - i2Q[1] * dx[j]; 
00088         j++;
00089     }
00090     for (i = ppar.N*SMPC_NUM_STATE_VAR; i < ppar.N*SMPC_NUM_VAR; i++)
00091     {
00092         // dx for control variables
00093         dx[i] = i2hess_grad[i] - ppar.i2P * dx[i];
00094     }
00095 }