Robowflex  v0.1
Making MoveIt Easy
robowflex::darts::TSR Class Reference

A Task Space Region (TSR). TSRs are workspace regions that impose a constraints on a robot. They are composed of a pose (in some reference frame) and tolerances on position and rotation. initialize() must be called once all parameters are set. More...

#include <tsr.h>

Classes

class  Specification
 The specification of a TSR. More...
 

Public Member Functions

Constructor and Initialization
 TSR (const WorldPtr &world, const Specification &spec)
 Constructor. More...
 
 ~TSR ()
 Destructor. Disables IK on node if created. More...
 
void setWorld (const WorldPtr &world)
 Set the world used by this TSR. More...
 
void clear ()
 Clears the initialization of this TSR. More...
 
void initialize ()
 Initialize this TSR. Creates IK node attached to body node in world. More...
 
DoF Indexing
void useGroup (const std::string &name)
 Use the joints in a robot's group. Robot used is the target frame's structure. More...
 
void useIndices (const std::vector< std::size_t > &indices)
 Use DoF indices for TSR computation. More...
 
robowflex::RobotPose getTransformToFrame () const
 Gets the transformation from the specification's base to the TSR's frame. More...
 
void useWorldIndices (const std::vector< std::pair< std::size_t, std::size_t >> &indices)
 Use World DoF indices for TSR computation. World indices are pairs of skeleton index and DoF index. More...
 
void setWorldIndices (const std::vector< std::pair< std::size_t, std::size_t >> &indices)
 Output world indices. TSR information for *WorldState methods uses this set of world indices. World indices are pairs of skeleton index and DoF index. More...
 
std::vector< std::pair< std::size_t, std::size_t > > computeWorldIndices () const
 Compute the set of world indices used based on the underlying active indices. More...
 
std::size_t getSkeletonIndex ()
 Get the skeleton index for the target frame's structure. More...
 
const std::vector< std::size_t > & getIndices () const
 Get the set of indices used for TSR computation. More...
 
const std::vector< std::pair< std::size_t, std::size_t > > & getWorldIndices () const
 Get the set of output world indices used. More...
 
void toBijection (Eigen::Ref< Eigen::VectorXd > world, const Eigen::Ref< const Eigen::VectorXd > &state) const
 From a configuration of controlled indices, map that configuration into a world configuration. That is, map state into world according to the set indices and world indices. More...
 
void fromBijection (Eigen::Ref< Eigen::VectorXd > state, const Eigen::Ref< const Eigen::VectorXd > &world) const
 From a world configuration, map that configuration into a controlled DoF configuration. That is, map world into state according to the set indices and world indices. More...
 
Getters
std::size_t getDimension () const
 Get the error dimension of this TSR. More...
 
std::size_t getNumDofs () const
 Get the number of controlled DoF for this TSR. More...
 
std::size_t getNumWorldDofs () const
 Get the number of world DoF for this TSR. More...
 
Specification and Updates
SpecificationgetSpecification ()
 Get the specification for this TSR. More...
 
void updatePose ()
 If the pose of the specification is updated, call this to update underlying IK solver. More...
 
void updateBounds ()
 If the bounds of the specification are updated, call this to update underlying IK solver. More...
 
void updateSolver ()
 If the solver parameters of the specification are updated, call this to update underlying IK solver. More...
 
Error / Function Computation
void getErrorWorldRaw (Eigen::Ref< Eigen::VectorXd > error) const
 Get the current error given the world state, with all values. More...
 
void getErrorWorld (Eigen::Ref< Eigen::VectorXd > error) const
 Get the current error given the world state. More...
 
void getErrorWorldState (const Eigen::Ref< const Eigen::VectorXd > &world, Eigen::Ref< Eigen::VectorXd > error) const
 Get the error given a provided world configuration. More...
 
void getError (const Eigen::Ref< const Eigen::VectorXd > &state, Eigen::Ref< Eigen::VectorXd > error) const
 Get the error given a configuration of the controlled DoF. More...
 
Jacobian Computation
void getJacobianWorld (Eigen::Ref< Eigen::MatrixXd > jacobian) const
 Get the current Jacobian given the world state. More...
 
void getJacobianWorldState (const Eigen::Ref< const Eigen::VectorXd > &world, Eigen::Ref< Eigen::MatrixXd > jacobian) const
 Get the Jacobian given a provided world configuration. More...
 
void getJacobian (const Eigen::Ref< const Eigen::VectorXd > &state, Eigen::Ref< Eigen::MatrixXd > jacobian) const
 Get the Jacobian given a configuration of the controlled DoF. More...
 
Distance Computation
double distanceWorld () const
 Get the current distance to satisfaction given the world state. More...
 
double distanceWorldState (const Eigen::Ref< const Eigen::VectorXd > &world) const
 Get the distance to satisfaction given a provided world configuration. More...
 
double distance (const Eigen::Ref< const Eigen::VectorXd > &state) const
 Get the distance to satisfaction given a configuration of the controlled DoF. More...
 
Solving for Satisfying Configurations
bool solveWorld ()
 Solve for a satisfying configuration given the current state of the world. More...
 
bool solveWorldState (Eigen::Ref< Eigen::VectorXd > world)
 Solve for a satisfying configuration given an initial world configuration. More...
 
bool solve (Eigen::Ref< Eigen::VectorXd > state)
 Solve for a satisfying configuration given an initial configuration of the controlled DoF. More...
 
bool solveGradientWorld ()
 Solve using gradient descent for a satisfying configuration given the current state of the world. More...
 
bool solveGradientWorldState (Eigen::Ref< Eigen::VectorXd > world)
 Solve using gradient descent for a satisfying configuration given an initial world configuration. More...
 
bool solveGradient (Eigen::Ref< Eigen::VectorXd > state)
 Solve using gradient descent for a satisfying configuration given an initial configuration of the controlled DoF. More...
 
Getting and Setting Position
void setPositionsWorldState (const Eigen::Ref< const Eigen::VectorXd > &world) const
 Set the positions of the world given a world configuration. More...
 
void setPositions (const Eigen::Ref< const Eigen::VectorXd > &state) const
 Set the positions of the world given a configuration. More...
 
void getPositionsWorldState (Eigen::Ref< Eigen::VectorXd > world) const
 Get the positions of the world into a world configuration. More...
 
void getPositions (Eigen::Ref< Eigen::VectorXd > state) const
 Get the positions of the world given into a configuration. More...
 

Private Member Functions

void computeBijection ()
 Compute the mapping from world indices to controlled DoF indices. More...
 

Private Attributes

WorldPtr world_
 Underlying world. More...
 
Specification spec_
 TSR specification. More...
 
std::size_t skel_index_
 Index of controlled skeleton. More...
 
std::vector< std::size_tindices_
 Controlled indices. More...
 
std::vector< std::pair< std::size_t, std::size_t > > world_indices_
 World indices. More...
 
std::vector< std::size_tbijection_
 
std::shared_ptr< dart::dynamics::SimpleFrame > frame_ {nullptr}
 Target frame of TSR. More...
 
dart::dynamics::BodyNode * tnd_ {nullptr}
 Target body node. More...
 
std::shared_ptr< dart::dynamics::InverseKinematics > ik_ {nullptr}
 Inverse kinematics module. More...
 
dart::dynamics::InverseKinematics::TaskSpaceRegion * tsr_ {nullptr}
 TSR. More...
 

Detailed Description

A Task Space Region (TSR). TSRs are workspace regions that impose a constraints on a robot. They are composed of a pose (in some reference frame) and tolerances on position and rotation. initialize() must be called once all parameters are set.

In the TSR, there are controlled DoF (through useIndices()) and world DoF (through useWorldIndices()). The controlled DoF are the DoF inside the structure the TSR's target frame is. These are the DoF that are used as part of the error, Jacobian, and other computations. However, the world might be using more DoF, especially if it is a multi-robot system. The world's DoF are given through useWorldIndices(). The *WorldState allow you to pass a configuration for the entire world (where each entry in that configuration corresponds to the indices given) and have the input / output be mapped appropriately to the controlled DoF.

Note, the TSR creates an IK node in the underlying Dart skeleton for the provided world. If you have multiple TSRs for the same target frame these will overwrite each other, unless you use a clone of the World.

Definition at line 62 of file tsr.h.

Constructor & Destructor Documentation

◆ TSR()

TSR::TSR ( const WorldPtr world,
const Specification spec 
)

Constructor.

Parameters
[in]worldWorld to apply TSR to.
[in]specSpecification for TSR.

TSR

Definition at line 465 of file tsr.cpp.

465  : world_(world), spec_(spec)
466 {
467 }
WorldPtr world_
Underlying world.
Definition: tsr.h:692
Specification spec_
TSR specification.
Definition: tsr.h:693

◆ ~TSR()

TSR::~TSR ( )

Destructor. Disables IK on node if created.

Definition at line 469 of file tsr.cpp.

470 {
471  clear();
472 }
void clear()
Clears the initialization of this TSR.
Definition: tsr.cpp:474

Member Function Documentation

◆ clear()

void TSR::clear ( void  )

Clears the initialization of this TSR.

Definition at line 474 of file tsr.cpp.

475 {
476  if (tnd_ and ik_)
477  tnd_->clearIK();
478 
479  frame_ = nullptr;
480  ik_ = nullptr;
481  tnd_ = nullptr;
482  tsr_ = nullptr;
483 }
dart::dynamics::InverseKinematics::TaskSpaceRegion * tsr_
TSR.
Definition: tsr.h:705
std::shared_ptr< dart::dynamics::SimpleFrame > frame_
Target frame of TSR.
Definition: tsr.h:702
dart::dynamics::BodyNode * tnd_
Target body node.
Definition: tsr.h:703
std::shared_ptr< dart::dynamics::InverseKinematics > ik_
Inverse kinematics module.
Definition: tsr.h:704

◆ computeBijection()

void TSR::computeBijection ( )
private

Compute the mapping from world indices to controlled DoF indices.

Definition at line 897 of file tsr.cpp.

898 {
899  if (world_indices_.empty())
900  return;
901 
903 
904  bool same = world_indices_.size() == indices_.size();
905  for (std::size_t i = 0; i < indices_.size(); ++i)
906  {
908  for (std::size_t j = 0; j < world_indices_.size(); ++j)
909  {
910  auto entry = world_indices_[j];
911  if (entry.first == getSkeletonIndex() and entry.second == indices_[i])
912  {
913  bijection_[i] = j;
914  same &= i == j;
915  break;
916  }
917  }
918  }
919 
920  if (same)
921  bijection_.clear();
922 }
std::vector< std::size_t > indices_
Controlled indices.
Definition: tsr.h:696
std::vector< std::pair< std::size_t, std::size_t > > world_indices_
World indices.
Definition: tsr.h:697
std::vector< std::size_t > bijection_
Definition: tsr.h:698
std::size_t getSkeletonIndex()
Get the skeleton index for the target frame's structure.
Definition: tsr.cpp:531
T clear(T... args)
T empty(T... args)
T resize(T... args)
T size(T... args)

◆ computeWorldIndices()

std::vector< std::pair< std::size_t, std::size_t > > TSR::computeWorldIndices ( ) const

Compute the set of world indices used based on the underlying active indices.

Returns
World indices corresponding to this TSR's current indices.

Definition at line 544 of file tsr.cpp.

545 {
547  for (const auto &index : indices_)
548  wi.emplace_back(skel_index_, index);
549 
550  return wi;
551 }
std::size_t skel_index_
Index of controlled skeleton.
Definition: tsr.h:695
T emplace_back(T... args)

◆ distance()

double TSR::distance ( const Eigen::Ref< const Eigen::VectorXd > &  state) const

Get the distance to satisfaction given a configuration of the controlled DoF.

Parameters
[in]stateControlled DoF configuration.
Returns
Distance to TSR satisfaction.

Definition at line 685 of file tsr.cpp.

686 {
687  Eigen::VectorXd x(getDimension());
688  getError(state, x);
689  return x.norm();
690 }
std::size_t getDimension() const
Get the error dimension of this TSR.
Definition: tsr.cpp:558
void getError(const Eigen::Ref< const Eigen::VectorXd > &state, Eigen::Ref< Eigen::VectorXd > error) const
Get the error given a configuration of the controlled DoF.
Definition: tsr.cpp:621

◆ distanceWorld()

double TSR::distanceWorld ( ) const

Get the current distance to satisfaction given the world state.

Returns
Distance to TSR satisfaction.

Definition at line 671 of file tsr.cpp.

672 {
673  Eigen::VectorXd x(getDimension());
674  getErrorWorld(x);
675  return x.norm();
676 }
void getErrorWorld(Eigen::Ref< Eigen::VectorXd > error) const
Get the current error given the world state.
Definition: tsr.cpp:592

◆ distanceWorldState()

double TSR::distanceWorldState ( const Eigen::Ref< const Eigen::VectorXd > &  world) const

Get the distance to satisfaction given a provided world configuration.

Parameters
[in]worldWorld configuration (from world indices).
Returns
Distance to TSR satisfaction.

Definition at line 678 of file tsr.cpp.

679 {
680  Eigen::VectorXd x(getDimension());
681  getErrorWorldState(world, x);
682  return x.norm();
683 }
void getErrorWorldState(const Eigen::Ref< const Eigen::VectorXd > &world, Eigen::Ref< Eigen::VectorXd > error) const
Get the error given a provided world configuration.
Definition: tsr.cpp:608

◆ fromBijection()

void TSR::fromBijection ( Eigen::Ref< Eigen::VectorXd >  state,
const Eigen::Ref< const Eigen::VectorXd > &  world 
) const

From a world configuration, map that configuration into a controlled DoF configuration. That is, map world into state according to the set indices and world indices.

Parameters
[out]stateOutput configuration.
[in]worldInput world configuration.

Definition at line 886 of file tsr.cpp.

888 {
889  if (bijection_.empty())
890  state = world;
891  else
892  for (std::size_t i = 0; i < bijection_.size(); ++i)
893  if (bijection_[i] < world_indices_.size())
894  state[i] = world[bijection_[i]];
895 }

◆ getDimension()

std::size_t TSR::getDimension ( ) const

Get the error dimension of this TSR.

Returns
The error dimension of the TSR.

Definition at line 558 of file tsr.cpp.

559 {
560  return spec_.dimension;
561 }
std::size_t dimension
Number of constrained dimensions.
Definition: tsr.h:102

◆ getError()

void TSR::getError ( const Eigen::Ref< const Eigen::VectorXd > &  state,
Eigen::Ref< Eigen::VectorXd >  error 
) const

Get the error given a configuration of the controlled DoF.

Parameters
[in]stateControlled DoF configuration.
[out]errorError value.

Definition at line 621 of file tsr.cpp.

622 {
623  setPositions(state);
624  getErrorWorld(error);
625 }
void setPositions(const Eigen::Ref< const Eigen::VectorXd > &state) const
Set the positions of the world given a configuration.
Definition: tsr.cpp:789

◆ getErrorWorld()

void TSR::getErrorWorld ( Eigen::Ref< Eigen::VectorXd >  error) const

Get the current error given the world state.

Parameters
[out]errorError value.

Definition at line 592 of file tsr.cpp.

593 {
594  world_->lock();
595 
596  auto tsr_error = tsr_->computeError();
597 
598  std::size_t j = 0;
599  for (std::size_t i = 0; i < 6; ++i)
600  {
601  if (spec_.indices[i])
602  error[j++] = tsr_error[i];
603  }
604 
605  world_->unlock();
606 }
std::vector< bool > indices
Vector of active constraints. If an index is true, that constraint is active. Ordered by X-,...
Definition: tsr.h:107

◆ getErrorWorldRaw()

void TSR::getErrorWorldRaw ( Eigen::Ref< Eigen::VectorXd >  error) const

Get the current error given the world state, with all values.

Parameters
[out]errorError value for all TSRs.

Definition at line 585 of file tsr.cpp.

586 {
587  world_->lock();
588  error = tsr_->computeError();
589  world_->unlock();
590 }

◆ getErrorWorldState()

void TSR::getErrorWorldState ( const Eigen::Ref< const Eigen::VectorXd > &  world,
Eigen::Ref< Eigen::VectorXd >  error 
) const

Get the error given a provided world configuration.

Parameters
[in]worldWorld configuration (from world indices).
[out]errorError value.

Definition at line 608 of file tsr.cpp.

610 {
611  if (bijection_.empty())
612  getError(world, error);
613  else
614  {
615  Eigen::VectorXd state(getNumDofs());
616  fromBijection(state, world);
617  getError(state, error);
618  }
619 }
std::size_t getNumDofs() const
Get the number of controlled DoF for this TSR.
Definition: tsr.cpp:563
void fromBijection(Eigen::Ref< Eigen::VectorXd > state, const Eigen::Ref< const Eigen::VectorXd > &world) const
From a world configuration, map that configuration into a controlled DoF configuration....
Definition: tsr.cpp:886

◆ getIndices()

const std::vector< std::size_t > & TSR::getIndices ( ) const

Get the set of indices used for TSR computation.

Definition at line 539 of file tsr.cpp.

540 {
541  return indices_;
542 }

◆ getJacobian()

void TSR::getJacobian ( const Eigen::Ref< const Eigen::VectorXd > &  state,
Eigen::Ref< Eigen::MatrixXd >  jacobian 
) const

Get the Jacobian given a configuration of the controlled DoF.

Parameters
[in]stateControlled DoF configuration.
[out]jacobianJacobian value.

Definition at line 662 of file tsr.cpp.

664 {
665  world_->lock();
666  setPositions(state);
667  getJacobianWorld(jacobian);
668  world_->unlock();
669 }
void getJacobianWorld(Eigen::Ref< Eigen::MatrixXd > jacobian) const
Get the current Jacobian given the world state.
Definition: tsr.cpp:627

◆ getJacobianWorld()

void TSR::getJacobianWorld ( Eigen::Ref< Eigen::MatrixXd >  jacobian) const

Get the current Jacobian given the world state.

Parameters
[out]jacobianJacobian value.

Definition at line 627 of file tsr.cpp.

628 {
629  world_->lock();
630 
631  auto tjac = ik_->computeJacobian();
632 
633  std::size_t j = 0;
634  for (std::size_t i = 0; i < 6; ++i)
635  {
636  if (spec_.indices[i])
637  jacobian.row(j++) = tjac.row(i);
638  }
639 
640  world_->unlock();
641 }

◆ getJacobianWorldState()

void TSR::getJacobianWorldState ( const Eigen::Ref< const Eigen::VectorXd > &  world,
Eigen::Ref< Eigen::MatrixXd >  jacobian 
) const

Get the Jacobian given a provided world configuration.

Parameters
[in]worldWorld configuration (from world indices).
[out]jacobianJacobian value.

Definition at line 643 of file tsr.cpp.

645 {
646  if (bijection_.empty())
647  getJacobian(world, jacobian);
648  else
649  {
650  Eigen::VectorXd state(getNumDofs());
651  fromBijection(state, world);
652 
653  Eigen::VectorXd tjac(getDimension(), getNumDofs());
654  getJacobian(state, tjac);
655 
656  for (std::size_t i = 0; i < bijection_.size(); ++i)
657  if (bijection_[i] < world_indices_.size())
658  jacobian.col(bijection_[i]) = tjac.col(i);
659  }
660 }
void getJacobian(const Eigen::Ref< const Eigen::VectorXd > &state, Eigen::Ref< Eigen::MatrixXd > jacobian) const
Get the Jacobian given a configuration of the controlled DoF.
Definition: tsr.cpp:662

◆ getNumDofs()

std::size_t TSR::getNumDofs ( ) const

Get the number of controlled DoF for this TSR.

Returns
The number of DoF for this TSR.

Definition at line 563 of file tsr.cpp.

564 {
565  return indices_.size();
566 }

◆ getNumWorldDofs()

std::size_t TSR::getNumWorldDofs ( ) const

Get the number of world DoF for this TSR.

Returns
The number of world DoF for this TSR.

Definition at line 568 of file tsr.cpp.

569 {
570  return world_indices_.size();
571 }

◆ getPositions()

void TSR::getPositions ( Eigen::Ref< Eigen::VectorXd >  state) const

Get the positions of the world given into a configuration.

Parameters
[out]stateControlled DoF configuration.

Definition at line 803 of file tsr.cpp.

804 {
805  world_->lock();
806  state = ik_->getPositions();
807  world_->unlock();
808 }

◆ getPositionsWorldState()

void TSR::getPositionsWorldState ( Eigen::Ref< Eigen::VectorXd >  world) const

Get the positions of the world into a world configuration.

Parameters
[out]worldWorld configuration.

Definition at line 796 of file tsr.cpp.

797 {
798  Eigen::VectorXd state(getNumDofs());
799  getPositions(state);
800  toBijection(world, state);
801 }
void toBijection(Eigen::Ref< Eigen::VectorXd > world, const Eigen::Ref< const Eigen::VectorXd > &state) const
From a configuration of controlled indices, map that configuration into a world configuration....
Definition: tsr.cpp:876
void getPositions(Eigen::Ref< Eigen::VectorXd > state) const
Get the positions of the world given into a configuration.
Definition: tsr.cpp:803

◆ getSkeletonIndex()

std::size_t TSR::getSkeletonIndex ( )

Get the skeleton index for the target frame's structure.

Returns
The index of the skeleton this TSR is targeting.

Definition at line 531 of file tsr.cpp.

532 {
533  if (not tnd_)
534  initialize();
535 
536  return skel_index_;
537 }
void initialize()
Initialize this TSR. Creates IK node attached to body node in world.
Definition: tsr.cpp:839

◆ getSpecification()

TSR::Specification & TSR::getSpecification ( )

Get the specification for this TSR.

Returns
The TSR's specification.

Definition at line 810 of file tsr.cpp.

811 {
812  return spec_;
813 }

◆ getTransformToFrame()

robowflex::RobotPose TSR::getTransformToFrame ( ) const

Gets the transformation from the specification's base to the TSR's frame.

Returns
RobotPose representing the transform.

Definition at line 573 of file tsr.cpp.

574 {
575  const auto &sim = world_->getSim();
576  const auto &bskl = sim->getSkeleton(spec_.base.structure);
577  auto *bnd = bskl->getBodyNode(spec_.base.frame);
578 
579  if (not tnd_)
580  throw std::runtime_error("Target body node is not initialized");
581 
582  return tnd_->getTransform(bnd);
583 }
std::string structure
Structure target frame is in.
Definition: tsr.h:76
std::string frame
Name of target frame.
Definition: tsr.h:77
struct robowflex::darts::TSR::Specification::@4 base
Base frame.

◆ getWorldIndices()

const std::vector< std::pair< std::size_t, std::size_t > > & TSR::getWorldIndices ( ) const

Get the set of output world indices used.

Definition at line 553 of file tsr.cpp.

554 {
555  return world_indices_;
556 }

◆ initialize()

void TSR::initialize ( )

Initialize this TSR. Creates IK node attached to body node in world.

Definition at line 839 of file tsr.cpp.

840 {
841  const auto &sim = world_->getSim();
842  const auto &tskl = sim->getSkeleton(spec_.target.structure);
843  if (not tskl)
844  throw std::runtime_error("Target skeleton " + spec_.target.structure + " in TSR does not exist!");
845  skel_index_ = world_->getSkeletonIndex(tskl);
846 
847  const auto &bskl = sim->getSkeleton(spec_.base.structure);
848  if (not bskl)
849  throw std::runtime_error("Base skeleton " + spec_.base.structure + " in TSR does not exist!");
850 
851  tnd_ = tskl->getBodyNode(spec_.target.frame);
852  ik_ = tnd_->getIK(true);
853  frame_ = ik_->getTarget();
854 
856  {
857  auto *bnd = bskl->getBodyNode(spec_.base.frame);
858  frame_ = frame_->clone(bnd);
859  }
860 
861  ik_->setTarget(frame_);
862 
863  tsr_ = &ik_->setErrorMethod<dart::dynamics::InverseKinematics::TaskSpaceRegion>();
864  tsr_->setComputeFromCenter(false);
865 
866  updatePose();
867  updateBounds();
868  updateSolver();
869 
870  if (indices_.empty())
871  indices_ = ik_->getDofs();
872  else
873  ik_->setDofs(indices_);
874 }
ROBOWFLEX_EIGEN struct robowflex::darts::TSR::Specification::@3 target
Target frame.
void updateBounds()
If the bounds of the specification are updated, call this to update underlying IK solver.
Definition: tsr.cpp:821
void updateSolver()
If the solver parameters of the specification are updated, call this to update underlying IK solver.
Definition: tsr.cpp:830
void updatePose()
If the pose of the specification is updated, call this to update underlying IK solver.
Definition: tsr.cpp:815
static const std::string ROOT_FRAME
Definition: tsr.h:31

◆ setPositions()

void TSR::setPositions ( const Eigen::Ref< const Eigen::VectorXd > &  state) const

Set the positions of the world given a configuration.

Parameters
[in]stateControlled DoF configuration.

Definition at line 789 of file tsr.cpp.

790 {
791  world_->lock();
792  ik_->setPositions(state);
793  world_->unlock();
794 }

◆ setPositionsWorldState()

void TSR::setPositionsWorldState ( const Eigen::Ref< const Eigen::VectorXd > &  world) const

Set the positions of the world given a world configuration.

Parameters
[in]worldWorld configuration.

Definition at line 782 of file tsr.cpp.

783 {
784  Eigen::VectorXd state(getNumDofs());
785  fromBijection(state, world);
786  setPositions(state);
787 }

◆ setWorld()

void TSR::setWorld ( const WorldPtr world)

Set the world used by this TSR.

Parameters
[in]worldNew world to use.

Definition at line 485 of file tsr.cpp.

486 {
487  clear();
488  world_ = world;
489  initialize();
490 }

◆ setWorldIndices()

void TSR::setWorldIndices ( const std::vector< std::pair< std::size_t, std::size_t >> &  indices)

Output world indices. TSR information for *WorldState methods uses this set of world indices. World indices are pairs of skeleton index and DoF index.

Parameters
[in]indicesIndices to use.

Definition at line 525 of file tsr.cpp.

526 {
527  world_indices_ = indices;
529 }
void computeBijection()
Compute the mapping from world indices to controlled DoF indices.
Definition: tsr.cpp:897

◆ solve()

bool TSR::solve ( Eigen::Ref< Eigen::VectorXd >  state)

Solve for a satisfying configuration given an initial configuration of the controlled DoF.

Parameters
[in]stateControlled DoF configuration.
Returns
True on success, false on failure.

Definition at line 718 of file tsr.cpp.

719 {
720  world_->lock();
721 
722  setPositions(state);
723  bool r = solveWorld();
724  getPositions(state);
725 
726  world_->unlock();
727  return r;
728 }
bool solveWorld()
Solve for a satisfying configuration given the current state of the world.
Definition: tsr.cpp:692

◆ solveGradient()

bool TSR::solveGradient ( Eigen::Ref< Eigen::VectorXd >  state)

Solve using gradient descent for a satisfying configuration given an initial configuration of the controlled DoF.

Parameters
[in]stateControlled DoF configuration.
Returns
True on success, false on failure.

Definition at line 754 of file tsr.cpp.

755 {
756  world_->lock();
757 
758  unsigned int iter = 0;
759  double norm = 0;
760  Eigen::VectorXd f(getDimension());
761  Eigen::MatrixXd j(getDimension(), getNumDofs());
762 
763  const double squared_tolerance = spec_.tolerance * spec_.tolerance;
764 
765  setPositions(state);
766  getErrorWorld(f);
767 
768  while ((norm = f.norm()) > squared_tolerance && iter++ < spec_.maxIter)
769  {
770  getJacobianWorld(j);
771  state -= j.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(f);
772 
773  setPositions(state);
774  getErrorWorld(f);
775  }
776 
777  world_->unlock();
778 
779  return norm < squared_tolerance;
780 }
std::size_t maxIter
Maximum iterations for solver.
Definition: tsr.h:109
double tolerance
Tolerance on solution for solver.
Definition: tsr.h:110

◆ solveGradientWorld()

bool TSR::solveGradientWorld ( )

Solve using gradient descent for a satisfying configuration given the current state of the world.

Returns
True on success, false on failure.

Definition at line 730 of file tsr.cpp.

731 {
732  world_->lock();
733 
734  Eigen::VectorXd state = ik_->getPositions();
735  bool r = solveGradient(state);
736  setPositions(state);
737 
738  world_->unlock();
739  return r;
740 }
bool solveGradient(Eigen::Ref< Eigen::VectorXd > state)
Solve using gradient descent for a satisfying configuration given an initial configuration of the con...
Definition: tsr.cpp:754

◆ solveGradientWorldState()

bool TSR::solveGradientWorldState ( Eigen::Ref< Eigen::VectorXd >  world)

Solve using gradient descent for a satisfying configuration given an initial world configuration.

Parameters
[in]worldWorld configuration (from world indices).
Returns
True on success, false on failure.

Definition at line 742 of file tsr.cpp.

743 {
744  if (bijection_.empty())
745  return solveGradient(world);
746 
747  Eigen::VectorXd state(getNumDofs());
748  fromBijection(state, world);
749  bool r = solveGradient(state);
750  toBijection(world, state);
751  return r;
752 }

◆ solveWorld()

bool TSR::solveWorld ( )

Solve for a satisfying configuration given the current state of the world.

Returns
True on success, false on failure.

Definition at line 692 of file tsr.cpp.

693 {
694  if (not ik_)
695  {
696  RBX_ERROR("TSR: Solve called before initialize!");
697  return false;
698  }
699 
700  world_->lock();
701  bool r = ik_->solveAndApply();
702  world_->unlock();
703  return r;
704 }
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102

◆ solveWorldState()

bool TSR::solveWorldState ( Eigen::Ref< Eigen::VectorXd >  world)

Solve for a satisfying configuration given an initial world configuration.

Parameters
[in]worldWorld configuration (from world indices).
Returns
True on success, false on failure.

Definition at line 706 of file tsr.cpp.

707 {
708  if (bijection_.empty())
709  return solve(world);
710 
711  Eigen::VectorXd state(getNumDofs());
712  fromBijection(state, world);
713  bool r = solve(state);
714  toBijection(world, state);
715  return r;
716 }
bool solve(Eigen::Ref< Eigen::VectorXd > state)
Solve for a satisfying configuration given an initial configuration of the controlled DoF.
Definition: tsr.cpp:718

◆ toBijection()

void TSR::toBijection ( Eigen::Ref< Eigen::VectorXd >  world,
const Eigen::Ref< const Eigen::VectorXd > &  state 
) const

From a configuration of controlled indices, map that configuration into a world configuration. That is, map state into world according to the set indices and world indices.

Parameters
[out]worldOutput world configuration.
[in]stateInput configuration.

Definition at line 876 of file tsr.cpp.

877 {
878  if (bijection_.empty())
879  world = state;
880  else
881  for (std::size_t i = 0; i < bijection_.size(); ++i)
882  if (bijection_[i] < world_indices_.size())
883  world[bijection_[i]] = state[i];
884 }

◆ updateBounds()

void TSR::updateBounds ( )

If the bounds of the specification are updated, call this to update underlying IK solver.

Definition at line 821 of file tsr.cpp.

822 {
823  if (tsr_)
824  {
825  tsr_->setLinearBounds(spec_.position.lower, spec_.position.upper);
826  tsr_->setAngularBounds(spec_.orientation.lower, spec_.orientation.upper);
827  }
828 }
Eigen::Vector3d lower
Lower position tolerance.
Definition: tsr.h:92
struct robowflex::darts::TSR::Specification::@5 position
Position tolerances.
struct robowflex::darts::TSR::Specification::@6 orientation
Orientation tolerances.
ROBOWFLEX_EIGEN Eigen::Vector3d upper
Upper position tolerance.
Definition: tsr.h:91

◆ updatePose()

void TSR::updatePose ( )

If the pose of the specification is updated, call this to update underlying IK solver.

Definition at line 815 of file tsr.cpp.

816 {
817  if (frame_)
818  frame_->setRelativeTransform(spec_.pose);
819 }
RobotPose pose
Pose of TSR.
Definition: tsr.h:86

◆ updateSolver()

void TSR::updateSolver ( )

If the solver parameters of the specification are updated, call this to update underlying IK solver.

Definition at line 830 of file tsr.cpp.

831 {
832  if (ik_)
833  {
834  ik_->getSolver()->setTolerance(spec_.tolerance);
835  ik_->getSolver()->setNumMaxIterations(spec_.maxIter);
836  }
837 }

◆ useGroup()

void TSR::useGroup ( const std::string name)

Use the joints in a robot's group. Robot used is the target frame's structure.

Parameters
[in]nameName of group to use.

Definition at line 492 of file tsr.cpp.

493 {
494  auto robot = world_->getRobot(spec_.target.structure);
495  if (not robot)
496  throw std::runtime_error("Target robot does exist in world!");
497 
498  useIndices(robot->getGroupIndices(name));
499 }
void useIndices(const std::vector< std::size_t > &indices)
Use DoF indices for TSR computation.
Definition: tsr.cpp:501
Functions for loading and animating robots in Blender.

◆ useIndices()

void TSR::useIndices ( const std::vector< std::size_t > &  indices)

Use DoF indices for TSR computation.

Parameters
[in]indicesIndices to use.

Definition at line 501 of file tsr.cpp.

502 {
503  indices_ = indices;
504  if (ik_)
505  {
506  ik_->setDofs(indices_);
507  indices_ = ik_->getDofs();
508  }
509 
511 }

◆ useWorldIndices()

void TSR::useWorldIndices ( const std::vector< std::pair< std::size_t, std::size_t >> &  indices)

Use World DoF indices for TSR computation. World indices are pairs of skeleton index and DoF index.

Parameters
[in]indicesIndices to use.

Definition at line 513 of file tsr.cpp.

514 {
516  for (const auto &index : indices)
517  {
518  if (index.first == getSkeletonIndex())
519  use.emplace_back(index.second);
520  }
521 
522  useIndices(use);
523 }

Member Data Documentation

◆ bijection_

std::vector<std::size_t> robowflex::darts::TSR::bijection_
private

Mapping between controlled to world indices. The ith entry contains the mapping of state[i] = world[bijection_[i]]

Definition at line 698 of file tsr.h.

◆ frame_

std::shared_ptr<dart::dynamics::SimpleFrame> robowflex::darts::TSR::frame_ {nullptr}
private

Target frame of TSR.

Definition at line 702 of file tsr.h.

◆ ik_

std::shared_ptr<dart::dynamics::InverseKinematics> robowflex::darts::TSR::ik_ {nullptr}
private

Inverse kinematics module.

Definition at line 704 of file tsr.h.

◆ indices_

std::vector<std::size_t> robowflex::darts::TSR::indices_
private

Controlled indices.

Definition at line 696 of file tsr.h.

◆ skel_index_

std::size_t robowflex::darts::TSR::skel_index_
private

Index of controlled skeleton.

Definition at line 695 of file tsr.h.

◆ spec_

Specification robowflex::darts::TSR::spec_
private

TSR specification.

Definition at line 693 of file tsr.h.

◆ tnd_

dart::dynamics::BodyNode* robowflex::darts::TSR::tnd_ {nullptr}
private

Target body node.

Definition at line 703 of file tsr.h.

◆ tsr_

dart::dynamics::InverseKinematics::TaskSpaceRegion* robowflex::darts::TSR::tsr_ {nullptr}
private

TSR.

Definition at line 705 of file tsr.h.

◆ world_

WorldPtr robowflex::darts::TSR::world_
private

Underlying world.

Definition at line 692 of file tsr.h.

◆ world_indices_

std::vector<std::pair<std::size_t, std::size_t> > robowflex::darts::TSR::world_indices_
private

World indices.

Definition at line 697 of file tsr.h.


The documentation for this class was generated from the following files: