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);
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);
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);
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);
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);
320 Phi[
t].data.segment(task.start, task.length) = big_Phi.
data.segment(
tasks[task.id]->start,
tasks[task.id]->length);
327 if (t_in >=
T || t_in < -1)
329 ThrowPretty(
"Requested t=" << t_in <<
" out of range, needs to be 0 =< t < " <<
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.");
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.");
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.");
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.");
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.");
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);
427 if (_prob->GetFlags() &
KIN_J)
433 if (_prob->GetFlags() &
KIN_H)
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)
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.");