36 virtual void lockJoint(
unsigned int q_nr,
unsigned int ndof)
38 q_nr += m_qrange.
start;
39 project(m_scene->m_Wq,
Range(q_nr, ndof), m_qrange).setZero();
42 virtual void lockJoint(
unsigned int q_nr,
unsigned int ndof,
double *qdot)
44 q_nr += m_qrange.
start;
45 project(m_scene->m_Wq,
Range(q_nr, ndof), m_qrange).setZero();
49 for (
unsigned int i = 0; i < ndof; ++i, ++q_nr) {
50 m_scene->m_ydot -= m_scene->m_A.col(q_nr) * qdot[i];
87 ConstraintMap::iterator constraint_it;
88 while ((constraint_it = constraints.begin()) != constraints.end()) {
89 delete constraint_it->second;
90 constraints.erase(constraint_it);
92 ObjectMap::iterator object_it;
93 while ((object_it = objects.begin()) != objects.end()) {
94 delete object_it->second;
95 objects.erase(object_it);
117 const std::string &baseFrame)
125 if (baseFrameIndex < 0)
127 std::pair<ObjectMap::iterator, bool>
result;
130 result = objects.insert(ObjectMap::value_type(
132 new Object_struct(
object,
141 ObjectMap::iterator base_it;
142 for (base_it = objects.begin(); base_it != objects.end(); base_it++) {
143 if (base_it->second->object == base)
146 if (base_it == objects.end())
148 result = objects.insert(ObjectMap::value_type(
150 new Object_struct(
object,
155 base_it->second->coordinaterange)));
160 m_nqTotal +=
object->getNrOfCoordinates();
167 std::pair<ObjectMap::iterator, bool>
result = objects.insert(
168 ObjectMap::value_type(name,
169 new Object_struct(
object,
177 m_nuTotal +=
object->getNrOfCoordinates();
185 const std::string &object1,
186 const std::string &object2,
187 const std::string &ee1,
188 const std::string &ee2)
191 ObjectMap::iterator object1_it = objects.find(object1);
192 ObjectMap::iterator object2_it = objects.find(object2);
193 if (object1_it == objects.end() || object2_it == objects.end())
195 int ee1_index = object1_it->second->object->addEndEffector(ee1);
196 int ee2_index = object2_it->second->object->addEndEffector(ee2);
197 if (ee1_index < 0 || ee2_index < 0)
199 std::pair<ConstraintMap::iterator, bool>
result = constraints.insert(ConstraintMap::value_type(
201 new ConstraintSet_struct(
task,
206 Range(m_ncTotal,
task->getNrOfConstraints()),
207 Range(6 * m_nsets, 6))));
210 m_ncTotal +=
task->getNrOfConstraints();
217 if (m_solver ==
NULL) {
227 if (m_cache ==
NULL) {
239 if (m_ncTotal == 0 || m_nqTotal == 0 || m_nsets == 0)
261 for (ObjectMap::iterator it = objects.begin(); it != objects.end(); ++it) {
262 Object_struct *os = it->second;
264 os->object->initCache(m_cache);
265 if (os->constraintrange.count > 0)
271 m_ytask.resize(m_ncTotal);
275 for (ConstraintMap::iterator it = constraints.begin(); it != constraints.end(); ++it) {
277 ConstraintSet_struct *cs = it->second;
279 getConstraintPose(cs->task, cs, external_pose);
280 result &= cs->task->initialise(external_pose);
281 cs->task->initCache(m_cache);
282 for (
int i = 0; i < cs->constraintrange.count; i++, cnt++) {
283 m_ytask[cnt] = toggle;
286 project(m_Cf, cs->constraintrange, cs->featurerange) = cs->task->getCf();
289 if (m_solver !=
NULL)
290 m_solver->
init(m_nqTotal, m_ncTotal, m_ytask);
300 ConstraintSet_struct *cs = (ConstraintSet_struct *)_param;
302 assert(constraint == cs->task);
303 Object_struct *ob1 = cs->object1->second;
304 Object_struct *ob2 = cs->object2->second;
307 (ob1->base->getPose(ob1->baseFrameIndex) * ob1->object->getPose(cs->ee1index)).Inverse() *
308 (ob2->base->getPose(ob2->baseFrameIndex) * ob2->object->getPose(cs->ee2index));
314 unsigned int numsubstep,
333 ts.
cache = (cache) ? 1 : 0;
335 ts.
numstep = (numsubstep & 0xFF);
336 bool autosubstep = (numsubstep == 0) ?
true :
false;
339 double timesubstep = timestep / numsubstep;
340 double timeleft = timestep;
342 if (timeleft == 0.0) {
344 for (ObjectMap::iterator it = objects.begin(); it != objects.end(); ++it) {
345 it->second->object->pushCache(ts);
348 for (ConstraintMap::iterator it = constraints.begin(); it != constraints.end(); ++it) {
349 it->second->task->pushCache(ts);
361 while (numsubstep > 0) {
363 for (ObjectMap::iterator it = objects.begin(); it != objects.end(); ++it) {
364 Object_struct *os = it->second;
367 if (os->constraintrange.count > 0) {
369 os->constraintrange) = ((
ControlledObject *)(os->object))->getControlOutput();
374 if (os->jointrange.count > 0) {
376 m_Wq, os->jointrange, os->jointrange) = ((
ControlledObject *)(os->object))->getWq();
390 for (ConstraintMap::iterator it = constraints.begin(); it != constraints.end(); ++it) {
391 ConstraintSet_struct *cs = it->second;
392 Object_struct *ob1 = cs->object1->second;
393 Object_struct *ob2 = cs->object2->second;
395 if (ob1->base->updated() || ob1->object->updated() || ob2->base->updated() ||
396 ob2->object->updated()) {
399 getConstraintPose(cs->task, cs, external_pose);
400 cs->task->initialise(external_pose);
402 cs->task->updateControlOutput(ts);
403 project(m_ydot, cs->constraintrange) = cs->task->getControlOutput();
404 if (!ts.
substep || cs->task->substep()) {
405 project(m_Wy, cs->constraintrange) = (cs->task)->getWy();
409 project(m_Jf, cs->featurerange, cs->featurerange) = cs->task->getJf();
412 Eigen::Block<e_matrix> Jf_part =
project(m_Jf, cs->featurerange, cs->featurerange);
414 ob1->base->getPose(ob1->baseFrameIndex) * ob1->object->getPose(cs->ee1index));
419 project(m_Jf, cs->featurerange, cs->featurerange), m_Uf, m_Sf, m_Vf, m_tempf);
420 for (
unsigned int i = 0; i < 6; ++i)
422 m_Uf.col(i).setConstant(0.0);
424 m_Uf.col(i) *= (1 / m_Sf(i));
425 project(m_Jf_inv, cs->featurerange, cs->featurerange).noalias() = m_Vf * m_Uf.transpose();
433 ob1->jointrange) = (((
ControlledObject *)(ob1->object))->getJq(cs->ee1index));
435 Eigen::Block<e_matrix> Jq_part =
project(m_Jq, cs->featurerange, ob1->jointrange);
436 changeBase(Jq_part, ob1->base->getPose(ob1->baseFrameIndex));
438 if (ob1->base->getNrOfCoordinates() != 0) {
440 project(m_Ju, cs->featurerange, ob1->coordinaterange) = ob1->base->getJu(
441 ob1->baseFrameIndex);
455 if (ob1->object == ob2->object) {
459 changeBase(JqTemp, ob2->base->getPose(ob2->baseFrameIndex));
461 project(m_Jq, cs->featurerange, ob2->jointrange) -= JqTemp;
464 project(m_Jq, cs->featurerange, ob2->jointrange) = -(
467 Eigen::Block<e_matrix> Jq_part =
project(m_Jq, cs->featurerange, ob2->jointrange);
468 changeBase(Jq_part, ob2->base->getPose(ob2->baseFrameIndex));
470 if (ob2->base->getNrOfCoordinates() != 0) {
473 if (ob2->base == ob1->base || ob2->base == ob1->object) {
474 project(m_Ju, cs->featurerange, ob2->coordinaterange) -= ob2->base->getJu(
475 ob2->baseFrameIndex);
478 project(m_Ju, cs->featurerange, ob2->coordinaterange) = -ob2->base->getJu(
479 ob2->baseFrameIndex);
485 if (ob2->object == ob1->base || ob2->object == ob1->object) {
486 project(m_Ju, cs->featurerange, ob2->coordinaterange) -=
490 project(m_Ju, cs->featurerange, ob2->coordinaterange) =
497 m_Atemp.noalias() = m_Cf * m_Jf_inv;
498 m_A.noalias() = m_Cq - (m_Atemp * m_Jq);
500 m_B.noalias() = m_Atemp * m_Ju;
501 m_ydot.noalias() += m_B * m_xdot;
505 if (!m_solver->
solve(m_A, m_Wy, m_ydot, m_Wq, m_qdot, nlcoef))
509 for (ObjectMap::iterator it = objects.begin(); it != objects.end(); ++it) {
510 Object_struct *os = it->second;
515 for (ConstraintMap::iterator it = constraints.begin(); it != constraints.end(); ++it) {
516 ConstraintSet_struct *cs = it->second;
517 Object_struct *ob1 = cs->object1->second;
518 Object_struct *ob2 = cs->object2->second;
521 if (ob1->jointrange.count > 0)
522 external_vel.noalias() += (
project(m_Jq, cs->featurerange, ob1->jointrange) *
523 project(m_qdot, ob1->jointrange));
524 if (ob2->jointrange.count > 0)
525 external_vel.noalias() += (
project(m_Jq, cs->featurerange, ob2->jointrange) *
526 project(m_qdot, ob2->jointrange));
527 if (ob1->coordinaterange.count > 0)
528 external_vel.noalias() += (
project(m_Ju, cs->featurerange, ob1->coordinaterange) *
529 project(m_xdot, ob1->coordinaterange));
530 if (ob2->coordinaterange.count > 0)
531 external_vel.noalias() += (
project(m_Ju, cs->featurerange, ob2->coordinaterange) *
532 project(m_xdot, ob2->coordinaterange));
535 e_vector6 estimated_chidot =
project(m_Jf_inv, cs->featurerange, cs->featurerange) *
537 cs->task->setJointVelocity(estimated_chidot);
544 timesubstep = timeleft;
547 double maxsubstep = nlcoef * m_maxstep;
548 if (maxsubstep < m_minstep)
549 maxsubstep = m_minstep;
550 if (timesubstep > maxsubstep)
551 timesubstep = maxsubstep;
552 for (ObjectMap::iterator it = objects.begin(); it != objects.end(); ++it) {
553 Object_struct *os = it->second;
557 for (ConstraintMap::iterator it = constraints.begin(); it != constraints.end(); ++it) {
558 ConstraintSet_struct *cs = it->second;
559 cs->task->getMaxTimestep(timesubstep);
562 maxsubstep = 2.0 *
floor(timestep / 2.0 / timesubstep - 0.66666);
563 timesubstep = (maxsubstep < 0.0) ? timestep : timestep / (2.0 + maxsubstep);
564 if (timesubstep >= timeleft - (m_minstep / 2.0)) {
565 timesubstep = timeleft;
571 timeleft -= timesubstep;
574 if (numsubstep > 1) {
587 ObjectMap::iterator it;
590 for (it = objects.begin(); it != objects.end(); ++it) {
593 lockCallback.
setRange(os->jointrange);
604 if (!m_solver->
solve(m_A, m_Wy, m_ydot, m_Wq, m_qdot, nlcoef))
609 for (it = objects.begin(); it != objects.end(); ++it) {
618 for (ObjectMap::iterator it = objects.begin(); it != objects.end(); ++it) {
619 it->second->object->updateKinematics(ts);
622 it->second->object->updated(
false);
625 for (ConstraintMap::iterator it = constraints.begin(); it != constraints.end(); ++it) {
626 ConstraintSet_struct *cs = it->second;
628 getConstraintPose(cs->task, cs, external_pose);
629 cs->task->modelUpdate(external_pose, ts);
631 cs->task->updateKinematics(ts);
represents a frame transformation in 3D space (rotation + translation)
virtual const unsigned int getNrOfCoordinates()
virtual const ObjectType getType()
virtual int addEndEffector(const std::string &name)
virtual void lockJoint(unsigned int q_nr, unsigned int ndof, double *qdot)
void setRange(Range &range)
virtual void lockJoint(unsigned int q_nr, unsigned int ndof)
bool addSolver(Solver *_solver)
bool setParam(SceneParam paramId, double value)
bool addConstraintSet(const std::string &name, ConstraintSet *task, const std::string &object1, const std::string &object2, const std::string &ee1="", const std::string &ee2="")
bool update(double timestamp, double timestep, unsigned int numsubstep=1, bool reiterate=false, bool cache=true, bool interpolate=true)
bool addCache(Cache *_cache)
bool addObject(const std::string &name, Object *object, UncontrolledObject *base=&Object::world, const std::string &baseFrame="")
virtual bool init(unsigned int nq, unsigned int nc, const std::vector< bool > &gc)=0
virtual bool solve(const e_matrix &A, const e_vector &Wy, const e_vector &ydot, const e_matrix &Wq, e_vector &qdot, e_scalar &nlcoef)=0
virtual const unsigned int getNrOfCoordinates()
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.
int svd_eigen_HH(const Eigen::MatrixBase< MatrixA > &A, Eigen::MatrixBase< MatrixUV > &U, Eigen::MatrixBase< VectorS > &S, Eigen::MatrixBase< MatrixUV > &V, Eigen::MatrixBase< VectorS > &tmp, int maxiter=150)
struct blender::compositor::@172::@174 task
void setCacheTimestamp(Timestamp ×tamp)
static int changeBase(Eigen::MatrixBase< Derived > &J, const Frame &T)
Eigen::Block< MatrixType > project(MatrixType &m, Range r)
ccl_device_inline float2 floor(const float2 &a)