A sparse MPC solver for walking motion generation (old version).
include/smpc_solver.h
Go to the documentation of this file.
00001 
00010 #ifndef SMPC_SOLVER_H
00011 #define SMPC_SOLVER_H
00012 
00013 class qp_solver;
00014 
00015 
00018 
00020 #define SMPC_NUM_STATE_VAR 6
00021 
00022 #define SMPC_NUM_CONTROL_VAR 2
00023 
00024 #define SMPC_NUM_VAR 8
00025 
00026 namespace smpc
00027 {
00028     class solver;
00029 
00030 
00031 
00035     class state
00036     {
00037         public:
00048             double state_vector[SMPC_NUM_STATE_VAR];
00049 
00050 
00054             state();
00055 
00056             // -------------------------------
00057 
00058 
00062             double &x  () {return state_vector[0];};
00066             double &vx () {return state_vector[1];};
00070             double &ax () {return state_vector[2];};
00071 
00075             double &y  () {return state_vector[3];};
00079             double &vy () {return state_vector[4];};
00083             double &ay () {return state_vector[5];};
00084 
00085 
00086             // -------------------------------
00087             
00088            
00094             virtual void get_next_state (const solver &smpc_solver) = 0;
00095 
00096 
00104             virtual void get_state (const solver &smpc_solver, const int ind) = 0;
00105 
00106 
00107             // -------------------------------
00108 
00109 
00117             void set (double x_, double y_);
00118 
00119 
00130             void set (double x_, double vx_, double ax_,
00131                      double y_, double vy_, double ay_);
00132     };
00133 
00134 
00146     class state_orig : public state
00147     {
00148         public:
00149             state_orig () : state () {};
00150 
00153             void get_next_state (const solver &smpc_solver);
00154             void get_state (const solver &smpc_solver, const int ind);
00156     };
00157 
00158     
00171     class state_tilde : public state
00172     {
00173         public:
00174             state_tilde () : state () {};
00175 
00178             void get_next_state (const solver &smpc_solver);
00179             void get_state (const solver &smpc_solver, const int ind);
00181     };
00182 
00183 
00187     class control
00188     {
00189         public:
00196             double control_vector[SMPC_NUM_CONTROL_VAR];
00197 
00198 
00199             control();
00200 
00201             // -------------------------------
00202 
00203 
00207             double &jx () {return control_vector[0];};
00211             double &jy () {return control_vector[1];};
00212 
00213 
00214             // -------------------------------
00215 
00216 
00223             void get_first_controls (const solver &smpc_solver);
00224 
00225 
00234             void get_controls (const solver &smpc_solver, const int ind);
00235     };
00236 
00237 
00238 
00239 
00243     class solver
00244     {
00245         public:
00246 
00247 
00248             // -------------------------------
00249 
00250 
00260             solver (
00261                     const int N, 
00262                     const double Alpha = 150.0, 
00263                     const double Beta = 2000.0, 
00264                     const double Gamma = 1.0,
00265                     const double regularization = 0.01,
00266                     const double tol = 1e-7);
00267 
00268 
00285             solver (
00286                     const int N, 
00287                     const int max_iter, // no default to avoid ambiguity
00288                     const double Alpha = 150.0, 
00289                     const double Beta = 2000.0, 
00290                     const double Gamma = 1.0,
00291                     const double regularization = 0.01,
00292                     const double tol = 1e-3,
00293                     const double tol_out = 1e-2,
00294                     const double t = 100,
00295                     const double mu = 15,
00296                     const double bs_alpha = 0.01,
00297                     const double bs_beta = 0.5);
00298 
00299 
00300             ~solver();
00301 
00302             // -------------------------------
00303 
00304             
00311             void enable_fexceptions();
00312 
00313 
00314             // -------------------------------
00315 
00316 
00328             void set_parameters (
00329                     const double* T,
00330                     const double* h,
00331                     const double h_initial,
00332                     const double* angle,
00333                     const double* zref_x,
00334                     const double* zref_y,
00335                     const double* lb,
00336                     const double* ub);
00337 
00338 
00346             void form_init_fp (
00347                     const double *x_coord,
00348                     const double *y_coord,
00349                     const state_orig &init_state,
00350                     double* X);
00351 
00352 
00359             int solve ();
00360        
00361 
00362             // -------------------------------
00363 
00367             qp_solver *qp_sol;
00368     };
00369 }
00371 
00372 #endif /*SMPC_SOLVER_H*/