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)
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.");
230 for (
size_t i = 0; i <
indexing.size(); ++i)
232 if (
tasks[i]->GetObjectName() == task_name)
237 ThrowPretty(
"Cannot get task Jacobian. Task map '" << task_name <<
"' does not exist.");
248 for (
int t = 0;
t < T; ++
t)
252 for (
int i = 0; i < task.length_jacobian; ++i)
254 S[
t](i + task.start_jacobian, i + task.start_jacobian) = rho[
t](task.id);
256 if (rho[
t](task.id) != 0.0)
tasks[task.id]->is_used =
true;
271 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
272 dPhi_dx[t].middleRows(task.start_jacobian, task.length_jacobian) = big_dPhi_dx.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
273 dPhi_du[t].middleRows(task.start_jacobian, task.length_jacobian) = big_dPhi_du.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
274 ddPhi_ddx[t].segment(task.start_jacobian, task.length_jacobian) = big_ddPhi_ddx.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
275 ddPhi_ddu[t].segment(task.start_jacobian, task.length_jacobian) = big_ddPhi_ddu.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
276 ddPhi_dxdu[t].segment(task.start_jacobian, task.length_jacobian) = big_ddPhi_dxdu.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
278 ydiff[t] = Phi[t] -
y[t];
288 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
289 dPhi_dx[t].middleRows(task.start_jacobian, task.length_jacobian) = big_dPhi_dx.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
290 dPhi_du[t].middleRows(task.start_jacobian, task.length_jacobian) = big_dPhi_du.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
292 ydiff[t] = Phi[t] -
y[t];
299 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
300 jacobian[t].middleRows(task.start_jacobian, task.length_jacobian) = big_jacobian.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
301 hessian[t].segment(task.start_jacobian, task.length_jacobian) = big_hessian.segment(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
303 ydiff[t] = Phi[t] -
y[t];
310 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
311 jacobian[t].middleRows(task.start_jacobian, task.length_jacobian) = big_jacobian.middleRows(
tasks[task.id]->start_jacobian,
tasks[task.id]->length_jacobian);
313 ydiff[t] = Phi[t] -
y[t];
320 Phi[t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
322 ydiff[t] = Phi[t] -
y[t];
327 if (t_in >= T || t_in < -1)
329 ThrowPretty(
"Requested t=" << t_in <<
" out of range, needs to be 0 =< t < " << T);
339 ValidateTimeIndex(t);
340 for (
size_t i = 0; i <
indexing.size(); ++i)
342 if (
tasks[i]->GetObjectName() == task_name)
349 ThrowPretty(
"Cannot set Goal. Task map '" << task_name <<
"' does not exist.");
354 ValidateTimeIndex(t);
355 for (
size_t i = 0; i <
indexing.size(); ++i)
357 if (
tasks[i]->GetObjectName() == task_name)
362 ThrowPretty(
"Cannot get Goal. Task map '" << task_name <<
"' does not exist.");
367 ValidateTimeIndex(t);
368 for (
size_t i = 0; i <
indexing.size(); ++i)
370 if (
tasks[i]->GetObjectName() == task_name)
377 ThrowPretty(
"Cannot set rho. Task map '" << task_name <<
"' does not exist.");
382 ValidateTimeIndex(t);
383 for (
size_t i = 0; i <
indexing.size(); ++i)
385 if (
tasks[i]->GetObjectName() == task_name)
390 ThrowPretty(
"Cannot get rho. Task map '" << task_name <<
"' does not exist.");
395 ValidateTimeIndex(t);
396 for (
size_t i = 0; i <
indexing.size(); ++i)
398 if (
tasks[i]->GetObjectName() == task_name)
403 ThrowPretty(
"Cannot get ydiff. Task map '" << task_name <<
"' does not exist.");
408 ValidateTimeIndex(t);
409 for (
size_t i = 0; i <
indexing.size(); ++i)
411 if (
tasks[i]->GetObjectName() == task_name)
417 ThrowPretty(
"Cannot get S. Task map '" << task_name <<
"' does not exist.");
423 Phi.assign(_T, _Phi);
425 rho.assign(T, Eigen::VectorXd::Ones(
num_tasks));
427 if (_prob->GetFlags() &
KIN_J)
430 dPhi_dx.assign(T, Eigen::MatrixXd(
length_jacobian, _prob->GetScene()->get_num_state_derivative()));
431 dPhi_du.assign(T, Eigen::MatrixXd(
length_jacobian, _prob->GetScene()->get_num_controls()));
433 if (_prob->GetFlags() &
KIN_H)
435 hessian.assign(T, Hessian::Constant(
length_jacobian, Eigen::MatrixXd::Zero(_prob->N, _prob->N)));
436 ddPhi_ddx.assign(T, Hessian::Constant(
length_jacobian, Eigen::MatrixXd::Zero(_prob->GetScene()->get_num_state_derivative(), _prob->GetScene()->get_num_state_derivative())));
437 ddPhi_ddu.assign(T, Hessian::Constant(
length_jacobian, Eigen::MatrixXd::Zero(_prob->GetScene()->get_num_controls(), _prob->GetScene()->get_num_controls())));
438 ddPhi_dxdu.assign(T, Hessian::Constant(
length_jacobian, Eigen::MatrixXd::Zero(_prob->GetScene()->get_num_state_derivative(), _prob->GetScene()->get_num_controls())));
447 if (task.Goal.rows() == 0)
451 else if (task.Goal.rows() ==
tasks[i]->length * T)
453 for (
int t = 0;
t < T; ++
t)
458 else if (task.Goal.rows() ==
tasks[i]->length)
460 for (
int t = 0;
t < T; ++
t)
469 if (task.Rho.rows() == 0)
473 else if (task.Rho.rows() == T)
475 for (
int t = 0;
t < T; ++
t)
477 rho[
t](i) = task.Rho(
t);
480 else if (task.Rho.rows() == 1)
482 for (
int t = 0;
t < T; ++
t)
484 rho[
t](i) = task.Rho(0);
489 ThrowPretty(
"Invalid task rho size! Expecting " << T <<
" (or 1) and got " << task.Rho.rows());
505 TaskInitializer task(inits[i]);
506 if (task.Goal.rows() == 0)
510 else if (task.Goal.rows() ==
tasks[i]->length)
518 if (task.Rho.rows() == 0)
522 else if (task.Rho.rows() == 1)
524 rho(i) = task.Rho(0);
528 ThrowPretty(
"Invalid task rho size! Expecting 1 got " << task.Rho.rows());
537 for (
int i = 0; i < task.length_jacobian; ++i)
539 S(i + task.start_jacobian, i + task.start_jacobian) = rho(task.id);
541 if (rho(task.id) != 0.0)
tasks[task.id]->is_used =
true;
549 Phi.data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
553 for (
unsigned int i = 0; i < ydiff.size(); ++i)
554 if (std::abs(ydiff[i]) <
tolerance) ydiff[i] = 0.0;
559 for (
size_t i = 0; i <
indexing.size(); ++i)
561 if (
tasks[i]->GetObjectName() == task_name)
568 ThrowPretty(
"Cannot set Goal. Task Map '" << task_name <<
"' does not exist.");
573 for (
size_t i = 0; i <
indexing.size(); ++i)
575 if (
tasks[i]->GetObjectName() == task_name)
582 ThrowPretty(
"Cannot set rho. 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 Goal. Task Map '" << task_name <<
"' does not exist.");
599 for (
size_t i = 0; i <
indexing.size(); ++i)
601 if (
tasks[i]->GetObjectName() == task_name)
606 ThrowPretty(
"Cannot get rho. Task Map '" << task_name <<
"' does not exist.");
std::vector< TaskVectorEntry > map
Eigen::MatrixXd GetS(const std::string &task_name) const
void init(const M_string &remappings)
Eigen::MatrixXd GetS(const std::string &task_name, int t) const
void SetZero(const int n)
double GetRho(const std::string &task_name) const
virtual void Initialize(const std::vector< exotica::Initializer > &inits, std::shared_ptr< PlanningProblem > prob, TaskSpaceVector &Phi)
Eigen::VectorXd GetGoal(const std::string &task_name) const
geometry_msgs::TransformStamped t
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
Eigen::MatrixXd GetTaskJacobian(const std::string &task_name) const
void SetRho(const std::string &task_name, const double rho)
double GetRho(const std::string &task_name, int t) const
std::vector< TaskInitializer > task_initializers_
static std::vector< TaskVectorEntry > reindex(const std::vector< TaskVectorEntry > &_map, int _old_start, int _new_start)
Eigen::VectorXd GetGoal(const std::string &task_name, int t) const
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 GetTaskError(const std::string &task_name) const
void ReinitializeVariables(int _T, std::shared_ptr< PlanningProblem > _prob, const TaskSpaceVector &_Phi)
Eigen::VectorXd GetTaskError(const std::string &task_name, int t) const
double GetRho(const std::string &task_name) const
std::vector< TaskIndexing > indexing
void ValidateTimeIndex(int &t_in) const
std::shared_ptr< PlanningProblem > PlanningProblemPtr
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
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)
Eigen::VectorXd GetGoal(const std::string &task_name) const
void SetRho(const std::string &task_name, const double rho_in)