Skip to content

Commit

Permalink
[exotica_core] Add UnconstrainedEndPoseProblem::GetHessian
Browse files Browse the repository at this point in the history
Implements analytical Hessian for UnconstrainedEndPoseProblem
  • Loading branch information
wxmerkt committed Dec 8, 2021
1 parent 559b728 commit be580d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class UnconstrainedEndPoseProblem : public PlanningProblem, public Instantiable<

double GetScalarCost() const;
Eigen::RowVectorXd GetScalarJacobian() const;
Eigen::MatrixXd GetHessian() const;

/**
* @brief GetScalarTaskCost get weighted sum-of-squares of cost vector
Expand Down
21 changes: 21 additions & 0 deletions exotica_core/src/problems/unconstrained_end_pose_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ Eigen::RowVectorXd UnconstrainedEndPoseProblem::GetScalarJacobian() const
return cost.jacobian.transpose() * cost.S * cost.ydiff * 2.0;
}

Eigen::MatrixXd UnconstrainedEndPoseProblem::GetHessian() const
{
Eigen::MatrixXd general_cost_hessian = Eigen::MatrixXd::Zero(N, N);

// Contract task-map Hessian
if (flags_ & KIN_H)
{
Eigen::RowVectorXd ydiffTS = cost.ydiff.transpose() * cost.S; // (1*m)
for (int i = 0; i < cost.length_jacobian; ++i) // length m
{
general_cost_hessian.noalias() += ydiffTS(i) * cost.hessian(i);
}
}
else
{
std::cerr << "[UnconstrainedEndPoseProblem::GetHessian] Hessian requested but DerivativeOrder < 2" << std::endl;
}

return 2. * general_cost_hessian;
}

double UnconstrainedEndPoseProblem::GetScalarTaskCost(const std::string& task_name) const
{
const Eigen::VectorXd ydiff = cost.GetTaskError(task_name);
Expand Down
1 change: 1 addition & 0 deletions exotica_python/src/pyexotica.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ PYBIND11_MODULE(_pyexotica, module)
unconstrained_end_pose_problem.def_property("q_nominal", &UnconstrainedEndPoseProblem::GetNominalPose, &UnconstrainedEndPoseProblem::SetNominalPose);
unconstrained_end_pose_problem.def("get_scalar_cost", &UnconstrainedEndPoseProblem::GetScalarCost);
unconstrained_end_pose_problem.def("get_scalar_jacobian", &UnconstrainedEndPoseProblem::GetScalarJacobian);
unconstrained_end_pose_problem.def("get_hessian", &UnconstrainedEndPoseProblem::GetHessian);
unconstrained_end_pose_problem.def("get_scalar_task_cost", &UnconstrainedEndPoseProblem::GetScalarTaskCost);
unconstrained_end_pose_problem.def_readonly("cost", &UnconstrainedEndPoseProblem::cost);

Expand Down

0 comments on commit be580d1

Please sign in to comment.