24 #include <IpIpoptApplication.hpp>
27 #include <iCub/utils.h>
69 for (Ipopt::Index i=0; i<(int)
dim; i++)
88 double pitch_cog=
chain(0).getMin()+
offset+delta/2.0;
90 double _tanh=tanh(c*(
q[0]-pitch_cog));
96 dfPitch=0.5*c*(1.0-_tanh*_tanh);
112 for (
size_t i=0; i<
n; i++)
133 void set_scaling(
double _obj_scaling,
double _x_scaling,
double _g_scaling)
148 bool get_nlp_info(Ipopt::Index&
n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
149 Ipopt::Index& nnz_h_lag, IndexStyleEnum& index_style)
override
155 index_style=TNLP::C_STYLE;
162 Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u)
override
164 for (Ipopt::Index i=0; i<
n; i++)
166 x_l[i]=
chain(i).getMin();
167 x_u[i]=
chain(i).getMax();
180 Ipopt::Number* z_L, Ipopt::Number* z_U, Ipopt::Index m,
181 bool init_lambda, Ipopt::Number* lambda)
override
183 for (Ipopt::Index i=0; i<
n; i++)
190 bool eval_f(Ipopt::Index
n,
const Ipopt::Number*
x,
bool new_x,
191 Ipopt::Number& obj_value)
override
195 for (Ipopt::Index i=0; i<
n; i++)
208 Ipopt::Number* grad_f)
override
210 for (Ipopt::Index i=0; i<
n; i++)
217 bool eval_g(Ipopt::Index
n,
const Ipopt::Number*
x,
bool new_x, Ipopt::Index m,
218 Ipopt::Number* g)
override
231 Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow,
232 Ipopt::Index *jCol, Ipopt::Number* values)
override
236 iRow[0]=0; jCol[0]=0;
237 iRow[1]=0; jCol[1]=1;
238 iRow[2]=0; jCol[2]=2;
240 iRow[3]=1; jCol[3]=0;
241 iRow[4]=1; jCol[4]=1;
243 iRow[5]=2; jCol[5]=0;
244 iRow[6]=2; jCol[6]=1;
251 for (Ipopt::Index i=0; i<
n; i++)
272 bool eval_h(Ipopt::Index
n,
const Ipopt::Number *
x,
bool new_x,
273 Ipopt::Number obj_factor, Ipopt::Index m,
const Ipopt::Number *lambda,
274 bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow,
275 Ipopt::Index *jCol, Ipopt::Number *values)
override
282 Ipopt::Index
n, Ipopt::Number* x_scaling,
283 bool& use_g_scaling, Ipopt::Index m,
284 Ipopt::Number* g_scaling)
override
288 for (Ipopt::Index i=0; i<
n; i++)
291 for (Ipopt::Index j=0; j<m; j++)
294 use_x_scaling=use_g_scaling=
true;
301 const Ipopt::Number*
x,
const Ipopt::Number* z_L,
302 const Ipopt::Number* z_U, Ipopt::Index m,
const Ipopt::Number* g,
303 const Ipopt::Number* lambda, Ipopt::Number obj_value,
304 const Ipopt::IpoptData* ip_data, Ipopt::IpoptCalculatedQuantities* ip_cq)
override
306 for (Ipopt::Index i=0; i<
n; i++)
315 Vector gDir_=SE3inv(
chain.
getH(2,
true)).submatrix(0,2,0,2)*gDir;
334 Ipopt::SmartPtr<HeadCenter_NLP> nlp;
339 nlp->setGravityDirection(gDir);
341 static_cast<Ipopt::IpoptApplication*
>(
App)->OptimizeTNLP(GetRawPtr(nlp));
342 return nlp->get_qd();
Vector solve(const Vector &q0, Vector &xd, const Vector &gDir)
HeadCenter_NLP(iKinChain &c, const Vector &_q0, Vector &_xd)
bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value) override
bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u) override
bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g) override
bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values) override
void computeQuantities(const Ipopt::Number *x)
bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f) override
bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, IndexStyleEnum &index_style) override
void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq) override
virtual ~HeadCenter_NLP()
void setGravityDirection(const Vector &gDir)
bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values) override
void set_bound_inf(double lower, double upper)
void set_scaling(double _obj_scaling, double _x_scaling, double _g_scaling)
bool get_scaling_parameters(Ipopt::Number &obj_scaling, bool &use_x_scaling, Ipopt::Index n, Ipopt::Number *x_scaling, bool &use_g_scaling, Ipopt::Index m, Ipopt::Number *g_scaling) override
bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda) override
A Base class for defining a Serial Link Chain.
yarp::sig::Matrix getH(const unsigned int i, const bool allLink=false)
Returns the rigid roto-translation matrix from the root reference frame to the ith frame in Denavit-H...
yarp::sig::Matrix GeoJacobian(const unsigned int i)
Returns the geometric Jacobian of the ith link.
yarp::sig::Matrix AnaJacobian(const unsigned int i, unsigned int col)
Returns the analitical Jacobian of the ith link.
yarp::sig::Vector setAng(const yarp::sig::Vector &q)
Sets the free joint angles to values of q[i].
unsigned int getDOF() const
Returns the current number of Chain's DOF.
double dot(const yarp::sig::Matrix &A, int colA, const yarp::sig::Matrix &B, int colB)
Returns the dot product between two vectors given in the form: matrix(:,col).
double norm(const yarp::sig::Matrix &M, int col)
Returns the norm of the vector given in the form: matrix(:,col).
double sat(const double val, const double min, const double max)
constexpr double CTRL_PI
The PI constant.
bool lower(Value &a, Value &b)