A sparse MPC solver for walking motion generation (old version).
solver/state_handling.cpp
Go to the documentation of this file.
00001 
00009 /****************************************
00010  * INCLUDES 
00011  ****************************************/
00012 
00013 #include "state_handling.h"
00014 
00015 
00016 
00017 /****************************************
00018  * FUNCTIONS 
00019  ****************************************/
00020 
00021 namespace state_handling
00022 {
00030     void tilde_to_bar (const double sinA, const double cosA, double *state)
00031     {
00032         double tmp =  cosA*state[0] + sinA*state[3];
00033         state[3]   = -sinA*state[0] + cosA*state[3];
00034         state[0]   = tmp;
00035     }
00036 
00044     void bar_to_tilde (const double sinA, const double cosA, double *state)
00045     {
00046         double tmp = cosA*state[0] - sinA*state[3];
00047         state[3]   = sinA*state[0] + cosA*state[3];
00048         state[0]   = tmp;
00049     }
00050 
00051 
00058     void tilde_to_orig (const double h, double *state)
00059     {
00060         state[0] = state[0] + h * state[2];
00061         state[3] = state[3] + h * state[5];
00062     }
00063 
00070     void orig_to_tilde (const double h, double *state)
00071     {
00072         state[0] = state[0] - h * state[2];
00073         state[3] = state[3] - h * state[5];
00074     }
00075 
00076 
00085     void get_state_tilde (const problem_parameters& sp, const double *X, const int ind, double *state)
00086     {
00087         int index;
00088         if (ind >= sp.N)
00089         {
00090             index = sp.N - 1;
00091         }
00092         else
00093         {
00094             index = ind;
00095         }
00096 
00097         for (int i = 0; i < SMPC_NUM_STATE_VAR; i++)
00098         {
00099             state[i] = X[index*SMPC_NUM_STATE_VAR + i];
00100         }
00101 
00102         state_handling::bar_to_tilde (sp.spar[index].sin, sp.spar[index].cos, state);
00103     }
00104 
00105 
00114     void get_state (const problem_parameters& sp, const double *X, const int ind, double *state)
00115     {
00116         int index;
00117         if (ind >= sp.N)
00118         {
00119             index = sp.N - 1;
00120         }
00121         else
00122         {
00123             index = ind;
00124         }
00125         get_state_tilde (sp, X, ind, state);
00126         state_handling::tilde_to_orig (sp.spar[index].h, state);
00127     }
00128 
00129 
00138     void get_controls (const int preview_window_size, const double *X, const int ind, double *controls)
00139     {
00140         int index;
00141         if (ind >= preview_window_size)
00142         {
00143             index = preview_window_size-1;
00144         }
00145         else
00146         {
00147             index = ind;
00148         }
00149         controls[0] = X[preview_window_size*SMPC_NUM_STATE_VAR + index*SMPC_NUM_CONTROL_VAR + 0];
00150         controls[1] = X[preview_window_size*SMPC_NUM_STATE_VAR + index*SMPC_NUM_CONTROL_VAR + 1];
00151     }
00152 }