33 #include <exotica_core/task_initializer.h> 41 TaskInitializer task(init);
42 auto it = prob->GetTaskMaps().find(task.Task);
43 if (it == prob->GetTaskMaps().end())
ThrowPretty(
"Task map '" << task.Task <<
"' has not been defined!");
45 tasks.push_back(it->second);
75 if (prob->GetFlags() &
KIN_H) hessian.setConstant(
length_jacobian, Eigen::MatrixXd::Zero(prob->N, prob->N));
81 TaskInitializer task(inits[i]);
82 if (task.Goal.rows() == 0)
86 else if (task.Goal.rows() ==
tasks[i]->length)
92 ThrowPretty(
"Invalid task goal size! Expecting " <<
tasks[i]->length <<
" got " << task.Goal.rows());
94 if (task.Rho.rows() == 0)
98 else if (task.Rho.rows() == 1)
100 rho(i) = task.Rho(0);
104 ThrowPretty(
"Invalid task rho size! Expecting 1 got " << task.Rho.rows());
113 for (
int i = 0; i < task.length_jacobian; ++i)
115 S(i + task.start_jacobian, i + task.start_jacobian) = rho(task.id);
117 if (rho(task.id) != 0.0)
tasks[task.id]->is_used =
true;
125 Phi.data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
126 jacobian.middleRows(task.start_jacobian, task.length_jacobian) = big_jacobian.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
127 hessian.segment(task.start_jacobian, task.length_jacobian) = big_hessian.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
136 Phi.data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
137 jacobian.middleRows(task.start_jacobian, task.length_jacobian) = big_jacobian.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
146 Phi.data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
153 for (
size_t i = 0; i <
indexing.size(); ++i)
155 if (
tasks[i]->GetObjectName() == task_name)
162 ThrowPretty(
"Cannot set Goal. Task Map '" << task_name <<
"' does not exist.");
167 for (
size_t i = 0; i <
indexing.size(); ++i)
169 if (
tasks[i]->GetObjectName() == task_name)
176 ThrowPretty(
"Cannot set rho. Task Map '" << task_name <<
"' does not exist.");
181 for (
size_t i = 0; i <
indexing.size(); ++i)
183 if (
tasks[i]->GetObjectName() == task_name)
188 ThrowPretty(
"Cannot get Goal. Task Map '" << task_name <<
"' does not exist.");
193 for (
size_t i = 0; i <
indexing.size(); ++i)
195 if (
tasks[i]->GetObjectName() == task_name)
200 ThrowPretty(
"Cannot get rho. Task Map '" << task_name <<
"' does not exist.");
205 for (
size_t i = 0; i <
indexing.size(); ++i)
207 if (
tasks[i]->GetObjectName() == task_name)
213 ThrowPretty(
"Cannot get S. Task map '" << task_name <<
"' does not exist.");
218 for (
size_t i = 0; i <
indexing.size(); ++i)
220 if (
tasks[i]->GetObjectName() == task_name)
225 ThrowPretty(
"Cannot get task error. Task map '" << task_name <<
"' does not exist.");
236 for (
int t = 0; t < T; ++t)
240 for (
int i = 0; i < task.length_jacobian; ++i)
242 S[t](i + task.start_jacobian, i + task.start_jacobian) = rho[t](task.id);
244 if (rho[t](task.id) != 0.0)
tasks[task.id]->is_used =
true;
259 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
260 dPhi_dx[t].middleRows(task.start_jacobian, task.length_jacobian) = big_dPhi_dx.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
261 dPhi_du[t].middleRows(task.start_jacobian, task.length_jacobian) = big_dPhi_du.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
262 ddPhi_ddx[t].segment(task.start_jacobian, task.length_jacobian) = big_ddPhi_ddx.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
263 ddPhi_ddu[t].segment(task.start_jacobian, task.length_jacobian) = big_ddPhi_ddu.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
264 ddPhi_dxdu[t].segment(task.start_jacobian, task.length_jacobian) = big_ddPhi_dxdu.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
266 ydiff[t] = Phi[t] -
y[t];
276 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
277 dPhi_dx[t].middleRows(task.start_jacobian, task.length_jacobian) = big_dPhi_dx.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
278 dPhi_du[t].middleRows(task.start_jacobian, task.length_jacobian) = big_dPhi_du.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
280 ydiff[t] = Phi[t] -
y[t];
287 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
288 jacobian[t].middleRows(task.start_jacobian, task.length_jacobian) = big_jacobian.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
289 hessian[t].segment(task.start_jacobian, task.length_jacobian) = big_hessian.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
291 ydiff[t] = Phi[t] -
y[t];
298 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
299 jacobian[t].middleRows(task.start_jacobian, task.length_jacobian) = big_jacobian.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
301 ydiff[t] = Phi[t] -
y[t];
308 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
310 ydiff[t] = Phi[t] -
y[t];
315 if (t_in >= T || t_in < -1)
317 ThrowPretty(
"Requested t=" << t_in <<
" out of range, needs to be 0 =< t < " << T);
327 ValidateTimeIndex(t);
328 for (
size_t i = 0; i <
indexing.size(); ++i)
330 if (
tasks[i]->GetObjectName() == task_name)
337 ThrowPretty(
"Cannot set Goal. Task map '" << task_name <<
"' does not exist.");
342 ValidateTimeIndex(t);
343 for (
size_t i = 0; i <
indexing.size(); ++i)
345 if (
tasks[i]->GetObjectName() == task_name)
350 ThrowPretty(
"Cannot get Goal. Task map '" << task_name <<
"' does not exist.");
355 ValidateTimeIndex(t);
356 for (
size_t i = 0; i <
indexing.size(); ++i)
358 if (
tasks[i]->GetObjectName() == task_name)
365 ThrowPretty(
"Cannot set rho. Task map '" << task_name <<
"' does not exist.");
370 ValidateTimeIndex(t);
371 for (
size_t i = 0; i <
indexing.size(); ++i)
373 if (
tasks[i]->GetObjectName() == task_name)
378 ThrowPretty(
"Cannot get rho. Task map '" << task_name <<
"' does not exist.");
383 ValidateTimeIndex(t);
384 for (
size_t i = 0; i <
indexing.size(); ++i)
386 if (
tasks[i]->GetObjectName() == task_name)
391 ThrowPretty(
"Cannot get ydiff. Task map '" << task_name <<
"' does not exist.");
396 ValidateTimeIndex(t);
397 for (
size_t i = 0; i <
indexing.size(); ++i)
399 if (
tasks[i]->GetObjectName() == task_name)
405 ThrowPretty(
"Cannot get S. Task map '" << task_name <<
"' does not exist.");
411 Phi.assign(_T, _Phi);
413 rho.assign(T, Eigen::VectorXd::Ones(
num_tasks));
415 if (_prob->GetFlags() &
KIN_J)
418 dPhi_dx.assign(T, Eigen::MatrixXd(
length_jacobian, _prob->GetScene()->get_num_state_derivative()));
419 dPhi_du.assign(T, Eigen::MatrixXd(
length_jacobian, _prob->GetScene()->get_num_controls()));
421 if (_prob->GetFlags() &
KIN_H)
423 hessian.assign(T, Hessian::Constant(
length_jacobian, Eigen::MatrixXd::Zero(_prob->N, _prob->N)));
424 ddPhi_ddx.assign(T, Hessian::Constant(
length_jacobian, Eigen::MatrixXd::Zero(_prob->GetScene()->get_num_state_derivative(), _prob->GetScene()->get_num_state_derivative())));
425 ddPhi_ddu.assign(T, Hessian::Constant(
length_jacobian, Eigen::MatrixXd::Zero(_prob->GetScene()->get_num_controls(), _prob->GetScene()->get_num_controls())));
426 ddPhi_dxdu.assign(T, Hessian::Constant(
length_jacobian, Eigen::MatrixXd::Zero(_prob->GetScene()->get_num_state_derivative(), _prob->GetScene()->get_num_controls())));
435 if (task.Goal.rows() == 0)
439 else if (task.Goal.rows() ==
tasks[i]->length * T)
441 for (
int t = 0; t < T; ++t)
446 else if (task.Goal.rows() ==
tasks[i]->length)
448 for (
int t = 0; t < T; ++t)
455 ThrowPretty(
"Invalid task goal size! Expecting " <<
tasks[i]->length * T <<
", " <<
tasks[i]->length <<
", or 1 and got " << task.Goal.rows());
457 if (task.Rho.rows() == 0)
461 else if (task.Rho.rows() == T)
463 for (
int t = 0; t < T; ++t)
465 rho[t](i) = task.Rho(t);
468 else if (task.Rho.rows() == 1)
470 for (
int t = 0; t < T; ++t)
472 rho[t](i) = task.Rho(0);
477 ThrowPretty(
"Invalid task rho size! Expecting " << T <<
" (or 1) and got " << task.Rho.rows());
493 TaskInitializer task(inits[i]);
494 if (task.Goal.rows() == 0)
498 else if (task.Goal.rows() ==
tasks[i]->length)
504 ThrowPretty(
"Invalid task goal size! Expecting " <<
tasks[i]->length <<
" got " << task.Goal.rows());
506 if (task.Rho.rows() == 0)
510 else if (task.Rho.rows() == 1)
512 rho(i) = task.Rho(0);
516 ThrowPretty(
"Invalid task rho size! Expecting 1 got " << task.Rho.rows());
525 for (
int i = 0; i < task.length_jacobian; ++i)
527 S(i + task.start_jacobian, i + task.start_jacobian) = rho(task.id);
529 if (rho(task.id) != 0.0)
tasks[task.id]->is_used =
true;
537 Phi.data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
541 for (
unsigned int i = 0; i < ydiff.size(); ++i)
542 if (std::abs(ydiff[i]) <
tolerance) ydiff[i] = 0.0;
547 for (
size_t i = 0; i <
indexing.size(); ++i)
549 if (
tasks[i]->GetObjectName() == task_name)
556 ThrowPretty(
"Cannot set Goal. Task Map '" << task_name <<
"' does not exist.");
561 for (
size_t i = 0; i <
indexing.size(); ++i)
563 if (
tasks[i]->GetObjectName() == task_name)
570 ThrowPretty(
"Cannot set rho. Task Map '" << task_name <<
"' does not exist.");
575 for (
size_t i = 0; i <
indexing.size(); ++i)
577 if (
tasks[i]->GetObjectName() == task_name)
582 ThrowPretty(
"Cannot get Goal. Task Map '" << task_name <<
"' does not exist.");
587 for (
size_t i = 0; i <
indexing.size(); ++i)
589 if (
tasks[i]->GetObjectName() == task_name)
594 ThrowPretty(
"Cannot get rho. Task Map '" << task_name <<
"' does not exist.");
std::vector< TaskVectorEntry > map
Eigen::VectorXd GetTaskError(const std::string &task_name, int t) const
double GetRho(const std::string &task_name, int t) const
Eigen::VectorXd GetGoal(const std::string &task_name, int t) const
Eigen::VectorXd GetGoal(const std::string &task_name) const
void ValidateTimeIndex(int &t_in) const
void SetZero(const int n)
double GetRho(const std::string &task_name) const
Eigen::VectorXd GetTaskError(const std::string &task_name) const
virtual void Initialize(const std::vector< exotica::Initializer > &inits, std::shared_ptr< PlanningProblem > prob, TaskSpaceVector &Phi)
void SetRho(const std::string &task_name, const double rho_in, int t)
virtual void Initialize(const std::vector< exotica::Initializer > &inits, std::shared_ptr< PlanningProblem > prob, TaskSpaceVector &Phi)
void Update(const TaskSpaceVector &big_Phi, Eigen::MatrixXdRefConst big_dPhi_dx, Eigen::MatrixXdRefConst big_dPhi_du, HessianRefConst big_ddPhi_ddx, HessianRefConst big_ddPhi_ddu, HessianRefConst big_ddPhi_dxdu, int t)
const Eigen::Ref< const Eigen::MatrixXd > & MatrixXdRefConst
Eigen::internal::ref_selector< Hessian >::type HessianRefConst
void SetRho(const std::string &task_name, const double rho)
std::vector< TaskInitializer > task_initializers_
static std::vector< TaskVectorEntry > reindex(const std::vector< TaskVectorEntry > &_map, int _old_start, int _new_start)
virtual void Initialize(const std::vector< exotica::Initializer > &inits, std::shared_ptr< PlanningProblem > prob, TaskSpaceVector &Phi)
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
void SetGoal(const std::string &task_name, Eigen::VectorXdRefConst goal, int t)
Eigen::VectorXd GetGoal(const std::string &task_name) const
double GetRho(const std::string &task_name) const
void ReinitializeVariables(int _T, std::shared_ptr< PlanningProblem > _prob, const TaskSpaceVector &_Phi)
Eigen::MatrixXd GetS(const std::string &task_name) const
Eigen::MatrixXd GetS(const std::string &task_name, int t) const
std::vector< TaskIndexing > indexing
std::shared_ptr< PlanningProblem > PlanningProblemPtr
void Update(const TaskSpaceVector &big_Phi, Eigen::MatrixXdRefConst big_jacobian, HessianRefConst big_hessian)
void AppendVector(std::vector< Val > &orig, const std::vector< Val > &extra)
virtual void Initialize(const std::vector< exotica::Initializer > &inits, std::shared_ptr< PlanningProblem > prob, TaskSpaceVector &Phi)
void SetGoal(const std::string &task_name, Eigen::VectorXdRefConst goal)
void SetGoal(const std::string &task_name, Eigen::VectorXdRefConst goal)
void Update(const TaskSpaceVector &big_Phi)
void SetRho(const std::string &task_name, const double rho_in)