40 const double gain_position_,
41 const double gain_velocity_,
42 const double gain_acceleration_,
43 const double gain_jerk_,
45 const bool obj_computation_on_,
47 problem_parameters (N_, gain_position_, gain_velocity_, gain_acceleration_, gain_jerk_),
54 grad =
new double[2*
N];
63 Q[0] = gain_position_/2;
64 Q[1] = gain_velocity_/2;
65 Q[2] = gain_acceleration_/2;
100 const double h_initial_,
102 const double* zref_x_,
103 const double* zref_y_,
131 for (
int i = 0; i <
N; i++)
158 double phi_X_logbar = 1.0;
163 for (
int i = 0; i < 2*
N; i++)
166 double lb_diff = -
lb[i] +
X[j];
167 double ub_diff =
ub[i] -
X[j];
172 phi_X_logbar += log(lb_diff * ub_diff);
179 const double grad_el =
X[j]*
gain_position +
g[i] + kappa * (ub_diff - lb_diff);
185 const double i2hess_el = 1/(
gain_position + kappa * (ub_diff*ub_diff + lb_diff*lb_diff));
199 return (-kappa * phi_X_logbar);
211 double phi_X_pos = 0;
212 double phi_X_vel = 0;
213 double phi_X_acc = 0;
214 double phi_X_jerk = 0;
222 const double X_copy[6] = {
X[i],
X[i+1],
X[i+2],
X[i+3],
X[i+4],
X[i+5]};
225 phi_X_pos += X_copy[0]*X_copy[0] + X_copy[3]*X_copy[3];
226 phi_X_vel += X_copy[1]*X_copy[1] + X_copy[4]*X_copy[4];
227 phi_X_acc += X_copy[2]*X_copy[2] + X_copy[5]*X_copy[5];
230 phi_X_gX +=
g[j]*X_copy[0] +
g[j+1]*X_copy[3];
235 phi_X_jerk +=
X[i] *
X[i] +
X[i+1] *
X[i+1];
238 return (
Q[0]*phi_X_pos +
Q[1]*phi_X_vel +
Q[2]*phi_X_acc +
P*phi_X_jerk + phi_X_gX);
249 double min_alpha = 1.0;
252 for (
int i = 0; i < 2*
N; i++)
257 const double tmp_alpha = (
lb[i]-
X[i*3])/
dX[i*3];
258 if (tmp_alpha < min_alpha)
260 min_alpha = tmp_alpha;
264 else if (
dX[i*3] > 0)
266 const double tmp_alpha = (
ub[i]-
X[i*3])/
dX[i*3];
267 if (tmp_alpha < min_alpha)
269 min_alpha = tmp_alpha;
276 while (alpha > min_alpha)
312 res_pos +=
grad[j] *
dX[i]
316 res_vel +=
X[i+1] *
dX[i+1]
319 res_acc +=
X[i+2] *
dX[i+2]
324 res_jerk +=
X[i] *
dX[i] +
X[i+1] *
dX[i+1];
352 double res_logbar = 1.0;
356 X[j] + alpha *
dX[j],
357 X[j+1] + alpha *
dX[j+1],
358 X[j+2] + alpha *
dX[j+2],
359 X[j+3] + alpha *
dX[j+3],
360 X[j+4] + alpha *
dX[j+4],
361 X[j+5] + alpha *
dX[j+5],
365 res_logbar += log((-
lb[i] + X_tmp[0]) * (
ub[i] - X_tmp[0])
366 * (-
lb[i+1] + X_tmp[3]) * (
ub[i+1] - X_tmp[3]));
369 res_gX +=
g[i] * X_tmp[0] +
g[i+1] * X_tmp[3];
372 res_pos += X_tmp[0]*X_tmp[0] + X_tmp[3]*X_tmp[3];
373 res_vel += X_tmp[1]*X_tmp[1] + X_tmp[4]*X_tmp[4];
374 res_acc += X_tmp[2]*X_tmp[2] + X_tmp[5]*X_tmp[5];
380 X[i] + alpha *
dX[i],
381 X[i+1] + alpha *
dX[i+1]
384 res_jerk += X_tmp[0] * X_tmp[0] + X_tmp[1] * X_tmp[1];
387 return (res_gX +
Q[0]*res_pos +
Q[1]*res_vel +
Q[2]*res_acc +
P*res_jerk - kappa * res_logbar);
405 const double bs_alpha_,
406 const double bs_beta_,
407 const unsigned int max_iter_,
408 const double tol_out_)
436 double duality_gap = 2*
N*kappa;
459 duality_gap = 2*
N*kappa;
470 double decrement_pos = 0;
471 double decrement_vel = 0;
472 double decrement_acc = 0;
473 double decrement_jerk = 0;
479 decrement_vel +=
dX[j+1] *
dX[j+1]
482 decrement_acc +=
dX[j+2] *
dX[j+2]
487 decrement_jerk +=
dX[i] *
dX[i]
490 return (decrement_pos + decrement_vel/
i2Q[1] + decrement_acc/
i2Q[2] + decrement_jerk/
i2P);
545 double bs_kappa = kappa;
554 if (
form_phi_X_tmp (bs_kappa, alpha) <= phi_X + alpha * bs_alpha_grad_dX)
573 X[i] += alpha *
dX[i];
574 X[i+1] += alpha *
dX[i+1];
575 X[i+2] += alpha *
dX[i+2];
576 X[i+3] += alpha *
dX[i+3];
577 X[i+4] += alpha *
dX[i+4];
578 X[i+5] += alpha *
dX[i+5];
579 X[i+6] += alpha *
dX[i+6];
580 X[i+7] += alpha *
dX[i+7];
604 const double *x_coord,
605 const double *y_coord,
606 const double *init_state,
607 const bool tilde_state,
611 form_init_fp_tilde<problem_parameters>(*
this, x_coord, y_coord, init_state, tilde_state,
X);
614 double *cur_state =
X;
615 for (
int i=0; i<
N; i++)
634 double obj_pos = 0.0;
635 double obj_vel = 0.0;
636 double obj_acc = 0.0;
637 double obj_jerk = 0.0;
639 double obj_ref = 0.0;
646 const double X_copy[6] = {
X[i],
X[i+1],
X[i+2],
X[i+3],
X[i+4],
X[i+5]};
649 obj_pos += X_copy[0]*X_copy[0] + X_copy[3]*X_copy[3];
650 obj_vel += X_copy[1]*X_copy[1] + X_copy[4]*X_copy[4];
651 obj_acc += X_copy[2]*X_copy[2] + X_copy[5]*X_copy[5];
654 obj_gX +=
g[j]*X_copy[0] +
g[j+1]*X_copy[3];
656 if (add_constant_term)
665 obj_jerk +=
X[i] *
X[i] +
X[i+1] *
X[i+1];
unsigned int ext_loop_counter
#define SMPC_NUM_STATE_VAR
Number of state variables.
double Q[3]
Diagonal elements of H.
double * i2hess
Inverted hessian: non-repeating diagonal elements 1:3:N*SMPC_NUM_STATE_VAR, 2*N in total.
bool solve_onestep(const double, vector< double > &)
One step of interior point method.
void set_state_parameters(const double *, const double *, const double, const double *)
Initializes quadratic problem.
const double * ub
lower and upper bounds
A set of problem parameters.
double form_grad_i2hess_logbar(const double)
Compute gradient of phi (partially), varying elements of i2hess, logarithmic barrier part of phi,...
unsigned int int_loop_counter
Use objective function, which includes logarithmic barrier term.
#define SMPC_NUM_VAR
Total number of variables.
double init_alpha()
tolerance of the outer loop
void set_ip_parameters(const double, const double, const double, const double, const unsigned int, const double)
Set parameters of interior-point method.
unsigned int max_iter
backtracking search parameter beta
void set_parameters(const double *, const double *, const double, const double *, const double *, const double *, const double *, const double *)
Initializes quadratic problem.
Use original objective function (no logarithmic barrier term).
double * i2hess_grad
Inverted hessian * gradient (N*SMPC_NUM_VAR vector)
void tilde_to_bar(const double sinA, const double cosA, double *state)
Converts state from X_tilde to X_bar.
void solve(vector< double > &)
Solve QP using interior-point method.
IP::chol_solve chol
An instance of IP::chol_solve class.
backtrackingSearchType
Type of the backtracking search.
#define SMPC_NUM_CONTROL_VAR
Number of control variables.
double tol_out
maximum number of internal loop iterations (in total)
double mu
logarithmic barrier parameter
double form_bs_alpha_obj_dX()
Forms bs_alpha * (objective') * dX.
double bs_beta
backtracking search parameter alpha
double * grad
2*N gradient vector, only the elements that correspond to the ZMP positions are computed,...
backtrackingSearchType bs_type
void form_g(const double *, const double *)
Forms vector g.
double compute_obj(const bool)
Computes value of the objective function.
double form_phi_X_tmp(const double, const double)
Forms phi(X+alpha*dX)
double * g
2*N non-zero elements of vector g.
double form_phi_X()
Compute phi_X for initial point, phi_X must already store logarithmic barrier term.
double P
Diagonal elements of H.
const double * lb
lower and upper bounds
void solve(const problem_parameters &, const double *, const double *, const double *, double *)
Determines feasible descent direction.
void form_init_fp(const double *, const double *, const double *, const bool, double *)
Generates an initial feasible point. First we perform a change of variable to X_tilde generate a feas...
double bs_alpha
multiplier of t, >1.
qp_ip(const int N_, const double, const double, const double, const double, const double, const bool, const backtrackingSearchType)
Constructor: initialization of the constant parameters.
Disable backtracking search.