14typedef std::pair<double, point3_t>
coefs_t;
33template <
typename Path>
35 const double T,
const double weightDistance,
36 bool useVelCost =
true);
41 c.second = point3_t::Zero();
50 std::vector<bezier_t::point_t> pts;
51 pts.push_back(pData.
c0_);
52 pts.push_back((pData.
dc0_ * T / n) + pData.
c0_);
54 (n * n * pData.
c0_ - n * pData.
c0_ + 2 * n * pData.
dc0_ * T -
55 2 * pData.
dc0_ * T + pData.
ddc0_ * T * T) /
57 pts.push_back((n * n * pData.
c0_ - n * pData.
c0_ + 3 * n * pData.
dc0_ * T -
58 3 * pData.
dc0_ * T + 3 * pData.
ddc0_ * T * T) /
68 pts.push_back(pData.
c1_);
77 std::vector<bezier_t::point_t> pts;
78 pts.push_back(pData.
c0_);
88 pts.push_back((n * n * pData.
c1_ - n * pData.
c1_ - 3 * n * pData.
dc1_ * T +
89 3 * pData.
dc1_ * T + 3 * pData.
ddc1_ * T * T) /
91 pts.push_back((n * n * pData.
c1_ - n * pData.
c1_ - 2 * n * pData.
dc1_ * T +
92 2 * pData.
dc1_ * T + pData.
ddc1_ * T * T) /
94 pts.push_back((-pData.
dc1_ * T / n) + pData.
c1_);
95 pts.push_back(pData.
c1_);
100 const ProblemData& pData,
const std::vector<waypoint_t>& wps_acc,
101 const std::vector<waypoint_t>& wps_vel,
const VectorX& acc_bounds,
103 const std::vector<waypoint_t>& wps_jerk = std::vector<waypoint_t>(),
106 "Acceleration bounds should have the same dimension as the points");
108 "Velocity bounds should have the same dimension as the points");
109 assert(jerk_bounds.size() ==
DIM_POINT &&
110 "Jerk bounds should have the same dimension as the points");
111 const int DIM_VAR =
dimVar(pData);
115 for (std::vector<waypoint_t>::const_iterator wpcit = wps_acc.begin();
116 wpcit != wps_acc.end(); ++wpcit) {
117 if (wpcit->first.isZero(std::numeric_limits<double>::epsilon()))
120 for (std::vector<waypoint_t>::const_iterator wpcit = wps_vel.begin();
121 wpcit != wps_vel.end(); ++wpcit) {
122 if (wpcit->first.isZero(std::numeric_limits<double>::epsilon()))
125 for (std::vector<waypoint_t>::const_iterator wpcit = wps_jerk.begin();
126 wpcit != wps_jerk.end(); ++wpcit) {
127 if (wpcit->first.isZero(std::numeric_limits<double>::epsilon()))
133 (wps_acc.size() - empty_acc + wps_vel.size() - empty_vel +
134 wps_jerk.size() - empty_jerk)) +
138 b = VectorX::Zero(A.rows());
142 for (std::vector<waypoint_t>::const_iterator wpcit = wps_acc.begin();
143 wpcit != wps_acc.end(); ++wpcit) {
144 if (!wpcit->first.isZero(std::numeric_limits<double>::epsilon())) {
151 for (std::vector<waypoint_t>::const_iterator wpcit = wps_acc.begin();
152 wpcit != wps_acc.end(); ++wpcit) {
153 if (!wpcit->first.isZero(std::numeric_limits<double>::epsilon())) {
161 for (std::vector<waypoint_t>::const_iterator wpcit = wps_vel.begin();
162 wpcit != wps_vel.end(); ++wpcit) {
163 if (!wpcit->first.isZero(std::numeric_limits<double>::epsilon())) {
170 for (std::vector<waypoint_t>::const_iterator wpcit = wps_vel.begin();
171 wpcit != wps_vel.end(); ++wpcit) {
172 if (!wpcit->first.isZero(std::numeric_limits<double>::epsilon())) {
180 for (std::vector<waypoint_t>::const_iterator wpcit = wps_jerk.begin();
181 wpcit != wps_jerk.end(); ++wpcit) {
182 if (!wpcit->first.isZero(std::numeric_limits<double>::epsilon())) {
189 for (std::vector<waypoint_t>::const_iterator wpcit = wps_jerk.begin();
190 wpcit != wps_jerk.end(); ++wpcit) {
191 if (!wpcit->first.isZero(std::numeric_limits<double>::epsilon())) {
201 MatrixXX mxz = MatrixXX::Zero(DIM_VAR, DIM_VAR);
203 VectorX nxz = VectorX::Zero(DIM_VAR);
204 while (j < (DIM_VAR)) {
206 nxz[j] = -std::min(pData.
c0_[2], pData.
c1_[2]);
209 A.block(i *
DIM_POINT, 0, DIM_VAR, DIM_VAR) = mxz;
214 assert((i *
DIM_POINT + DIM_VAR) == A.rows() &&
215 "Constraints matrix were not correctly initialized");
225 size_t numPoints,
const ProblemData& pData,
double T,
226 std::vector<point3_t> pts_path) {
227 assert(numPoints == pts_path.size() &&
228 "Pts_path size must be equal to numPoints");
229 double step = 1. / (double)(numPoints - 1);
235 for (
size_t i = 0; i < numPoints; ++i) {
242 g += ((c_wp.
second - pk).transpose() * c_wp.
first).transpose();
244 double norm = H.norm();
247 return std::make_pair(H, g);
250template <
typename Path>
252 size_t numPoints,
const ProblemData& pData,
double T,
const Path& path) {
253 double step = 1. / (double)(numPoints - 1);
254 std::vector<point3_t> pts_path;
255 for (
size_t i = 0; i < numPoints; ++i)
256 pts_path.push_back(path(((
double)i * step)));
265 else if (
dimVar(pData) == 9) {
266 wps[4] = res.
x.segment<3>(0);
267 wps[5] = res.
x.segment<3>(3);
268 wps[6] = res.
x.segment<3>(6);
269 }
else if (
dimVar(pData) == 15) {
270 wps[4] = res.
x.segment<3>(0);
271 wps[5] = res.
x.segment<3>(3);
272 wps[6] = res.
x.segment<3>(6);
273 wps[7] = res.
x.segment<3>(9);
274 wps[8] = res.
x.segment<3>(12);
278 std::cout <<
"bezier curve created, size = " << res.
c_of_t_.size_
284 double step = 1. / (numPoints - 1);
285 std::vector<waypoint_t> cks;
287 for (
int i = 0; i < numPoints; ++i) {
291 g = VectorX::Zero(
dimVar(pData));
292 for (std::vector<waypoint_t>::const_iterator ckcit = cks.begin();
293 ckcit != cks.end(); ++ckcit) {
296 for (
int i = 0; i < (
dimVar(pData) / 3); ++i) {
297 H.block<3, 3>(i * 3, i * 3) +=
298 Matrix3::Identity() * ckcit->first(0, i * 3) * ckcit->first(0, i * 3);
299 g.segment<3>(i * 3) +=
300 ckcit->second.segment<3>(0) * ckcit->first(0, i * 3);
316 double step = 1. / (numPoints - 1);
317 std::vector<waypoint_t> cks;
319 for (
int i = 0; i < numPoints; ++i) {
324 g = VectorX::Zero(
dimVar(pData));
325 for (std::vector<waypoint_t>::const_iterator ckcit = cks.begin();
326 ckcit != cks.end(); ++ckcit) {
327 H += (ckcit->first.transpose() * ckcit->first);
328 g += ckcit->first.transpose() * ckcit->second;
341 double step = 1. / (numPoints - 1);
343 std::vector<waypoint_t> cks;
345 for (
int i = 0; i < numPoints; ++i) {
349 g = VectorX::Zero(
dimVar(pData));
350 for (std::vector<waypoint_t>::const_iterator ckcit = cks.begin();
351 ckcit != cks.end(); ++ckcit) {
352 H += (ckcit->first.transpose() * ckcit->first);
353 g += ckcit->first.transpose() * ckcit->second;
366 std::vector<bezier_t::point_t> pi) {
371 Vector3 jerk_bounds(10000, 10000,
373 Vector3 acc_bounds(10000, 10000, 10000);
374 Vector3 vel_bounds(10000, 10000, 10000);
378 b, wps_jerk, jerk_bounds);
379 return std::make_pair(A, b);
382template <
typename Path>
384 const ProblemData& pData,
const Path& path,
const double T,
385 const double weightDistance,
bool ,
386 std::vector<bezier_t::point_t> pi) {
387 assert(weightDistance >= 0. && weightDistance <= 1. &&
388 "WeightDistance must be between 0 and 1");
389 double weightSmooth = 1. - weightDistance;
390 const int DIM_VAR =
dimVar(pData);
395 std::pair<MatrixXX, VectorX> Hg_smooth, Hg_rrt;
397 if (weightDistance > 0)
400 Hg_rrt.first = MatrixXX::Zero(DIM_VAR, DIM_VAR);
401 Hg_rrt.second = VectorX::Zero(DIM_VAR);
412 H = MatrixXX::Zero(DIM_VAR, DIM_VAR);
413 g = VectorX::Zero(DIM_VAR);
419 return std::make_pair(
H,
g);
422template <
typename Path>
426 if (
verbose) std::cout <<
"solve end effector, T = " <<
T << std::endl;
429 std::pair<MatrixXX, VectorX>
Hg =
432 std::cout <<
"End eff A = " << std::endl <<
Ab.first << std::endl;
433 std::cout <<
"End eff b = " << std::endl <<
Ab.second << std::endl;
434 std::cout <<
"End eff H = " << std::endl <<
Hg.first << std::endl;
435 std::cout <<
"End eff g = " << std::endl <<
Hg.second << std::endl;
436 std::cout <<
"Dim Var = " <<
dimVar(
pData) << std::endl;
437 std::cout <<
"Dim H = " <<
Hg.first.rows() <<
" x " <<
Hg.first.cols()
439 std::cout <<
"Dim g = " <<
Hg.second.rows() << std::endl;
440 std::cout <<
"Dim A = " <<
Ab.first.rows() <<
" x " <<
Ab.first.cols()
442 std::cout <<
"Dim b = " <<
Ab.first.rows() << std::endl;
449 std::cout <<
"Init = " << std::endl <<
init.transpose() << std::endl;
454 if (
resQp.success_) {
462 std::cout <<
"Solved, success = " <<
res.success_
463 <<
" x = " <<
res.x.transpose() << std::endl;
464 std::cout <<
"Final cost : " <<
resQp.cost_ << std::endl;
Definition common_solve_methods.hh:15
std::vector< bezier_t::point_t > computeConstantWaypointsGoalPredef(const ProblemData &pData, double T)
Definition solve_end_effector.hh:74
centroidal_dynamics::VectorX VectorX
Definition definitions.hh:24
const int DIM_POINT
Definition solve_end_effector.hh:15
std::vector< waypoint_t > computeAccelerationWaypoints(const ProblemData &pData, const double T, std::vector< bezier_t::point_t > pi=std::vector< bezier_t::point_t >())
computeWwaypoints compute the constant waypoints of ddc(t) defined by the constraints on initial and ...
Definition waypoints_definition.cpp:365
ResultDataCOMTraj solveEndEffector(const ProblemData &pData, const Path &path, const double T, const double weightDistance, bool useVelCost=true)
solveEndEffector Tries to produce a trajectory represented as a bezier curve that satisfy position,...
Definition solve_end_effector.hh:423
BEZIER_COM_TRAJ_DLLAPI ResultData solve(Cref_matrixXX A, Cref_vectorX b, Cref_matrixXX H, Cref_vectorX g, Cref_vectorX initGuess, Cref_vectorX minBounds, Cref_vectorX maxBounds, const solvers::SolverType solver=solvers::SOLVER_QUADPROG)
solve x' h x + 2 g' x, subject to A*x <= b using quadprog
centroidal_dynamics::Vector3 Vector3
Definition definitions.hh:22
Vector3 point3_t
Definition definitions.hh:40
waypoint_t evaluateAccelerationCurveWaypointAtTime(const ProblemData &pData, const double T, const std::vector< point_t > &pi, double t)
evaluateCurveAtTime compute the expression of the point on the curve c at t, defined by the waypoint ...
Definition waypoints_definition.cpp:211
void computeJerkCostFunctionDiscretized(int numPoints, const ProblemData &pData, double T, MatrixXX &H, VectorX &g)
Definition solve_end_effector.hh:339
void computeAccelerationCostFunctionDiscretized(int numPoints, const ProblemData &pData, double T, MatrixXX &H, VectorX &g)
Definition solve_end_effector.hh:312
waypoint_t evaluateCurveWaypointAtTime(const ProblemData &pData, const std::vector< point_t > &pi, double t)
evaluateCurveAtTime compute the expression of the point on the curve c at t, defined by the waypoint ...
Definition waypoints_definition.cpp:138
std::pair< double, point3_t > coefs_t
Definition definitions.hh:62
std::pair< MatrixXX, VectorX > computeVelocityCost(const ProblemData &pData, double T, std::vector< bezier_t::point_t > pi=std::vector< bezier_t::point_t >())
computeVelocityCost the matrices H and g defining a cost that minimise the integral of the squared ve...
Definition waypoints_definition.cpp:479
waypoint_t evaluateJerkCurveWaypointAtTime(const ProblemData &pData, const double T, const std::vector< point_t > &pi, double t)
evaluateCurveAtTime compute the expression of the point on the curve c at t, defined by the waypoint ...
Definition waypoints_definition.cpp:246
void computeConstraintsMatrix(const ProblemData &pData, const std::vector< waypoint_t > &wps_acc, const std::vector< waypoint_t > &wps_vel, const VectorX &acc_bounds, const VectorX &vel_bounds, MatrixXX &A, VectorX &b, const std::vector< waypoint_t > &wps_jerk=std::vector< waypoint_t >(), const VectorX &jerk_bounds=VectorX(DIM_POINT))
Definition solve_end_effector.hh:99
ndcurves::bezier_curve< double, double, true, point_t > bezier_t
Definition definitions.hh:55
std::pair< MatrixXX, VectorX > computeDistanceCostFunction(size_t numPoints, const ProblemData &pData, double T, std::vector< point3_t > pts_path)
Definition solve_end_effector.hh:224
std::vector< bezier_t::point_t > computeConstantWaypointsInitPredef(const ProblemData &pData, double T)
Definition solve_end_effector.hh:47
const bool verbose
Definition solve_end_effector.hh:17
void computeC_of_T(const ProblemData &pData, double T, ResultDataCOMTraj &res)
Definition solve_end_effector.hh:261
waypoint_t evaluateVelocityCurveWaypointAtTime(const ProblemData &pData, const double T, const std::vector< point_t > &pi, double t)
evaluateCurveAtTime compute the expression of the point on the curve c at t, defined by the waypoint ...
Definition waypoints_definition.cpp:173
coefs_t initCoefs()
Definition solve_end_effector.hh:38
void computeVelCostFunctionDiscretized(int numPoints, const ProblemData &pData, double T, MatrixXX &H, VectorX &g)
Definition solve_end_effector.hh:282
int dimVar(const ProblemData &pData)
Definition waypoints_definition.cpp:30
std::pair< MatrixXX, VectorX > computeEndEffectorCost(const ProblemData &pData, const Path &path, const double T, const double weightDistance, bool, std::vector< bezier_t::point_t > pi)
Definition solve_end_effector.hh:383
std::vector< waypoint_t > computeVelocityWaypoints(const ProblemData &pData, const double T, std::vector< bezier_t::point_t > pi=std::vector< bezier_t::point_t >())
computeWwaypoints compute the constant waypoints of dc(t) defined by the constraints on initial and f...
Definition waypoints_definition.cpp:335
std::pair< MatrixXX, VectorX > computeEndEffectorConstraints(const ProblemData &pData, const double T, std::vector< bezier_t::point_t > pi)
Definition solve_end_effector.hh:364
Eigen::Matrix< value_type, Eigen::Dynamic, Eigen::Dynamic > MatrixXX
Definition definitions.hh:21
std::vector< waypoint_t > computeJerkWaypoints(const ProblemData &pData, const double T, std::vector< bezier_t::point_t > pi=std::vector< bezier_t::point_t >())
computeWwaypoints compute the constant waypoints of dddc(t) defined by the constraints on initial and...
Definition waypoints_definition.cpp:395
std::vector< point_t > computeConstantWaypoints(const ProblemData &pData, double T)
computeConstantWaypoints compute the constant waypoints of c(t) defined by the constraints on initial...
Definition waypoints_definition.cpp:286
Defines all the inputs of the problem: Initial and terminal constraints, as well as selected cost fun...
Definition data.hh:92
point_t ddc1_
Definition data.hh:107
point_t dc0_
Definition data.hh:107
point_t ddc0_
Definition data.hh:107
point_t dc1_
Definition data.hh:107
point_t c0_
Definition data.hh:107
point_t c1_
Definition data.hh:107
Specialized ResultData that computes the Bezier curves corresponding to the computed trajectory.
Definition data.hh:121
bezier_t c_of_t_
Definition data.hh:130
VectorX second
Definition utils.hh:27
MatrixXX first
Definition utils.hh:26
Struct used to return the results of the trajectory generation problem.
Definition solver-abstract.hpp:52
VectorXd x
Definition solver-abstract.hpp:70
bool success_
Definition solver-abstract.hpp:68