Drake
Drake C++ Documentation
KinematicsVector< Id, KinematicsValue > Class Template Reference

Detailed Description

template<class Id, class KinematicsValue>
class drake::geometry::KinematicsVector< Id, KinematicsValue >

A KinematicsVector is a container class used to report kinematics data for registered frames and geometries (keyed by unique FrameId/GeometryId values) to SceneGraph where the set of keys (FrameId/GeometryId) is usually constant and the values (kinematics data) are varying.

It is an internal class and one should never interact with it directly. The template aliases FramePoseVector and GeometryConfigurationVector that instantiate KinematicsVector should be used instead.

template <typename T>
class MySystem : public LeafSystem<T> {
public:
MySystem() {
...
this->DeclareAbstractOutputPort(
&AllocInConstructorSystem::CalcFramePoseOutput);
...
}
private:
void CalcFramePoseOutput(const Context<T>& context,
geometry::FramePoseVector<T>* poses) const {
poses->clear();
for (int i = 0; i < static_cast<int>(frame_ids_.size()); ++i) {
poses->set_value(frame_ids_[i], poses_[i]);
}
}
std::vector<FrameId> frame_ids_;
std::vector<RigidTransform<T>> poses_;
};

If a System only ever emits a single frame/geometry (or small-constant-number of frames/geometries), then there's a shorter alternative way to write a Calc method, using an initializer_list:

void CalcFramePoseOutput(const Context<T>& context,
geometry::FramePoseVector<T>* poses) const {
const RigidTransform<T>& pose = ...;
*poses = {{frame_id_, pose}};
}

N.B. When the systems framework calls the Calc method, the value pointed to by poses is in an unspecified state. The implementation of Calc must always ensure that poses contains the correct value upon return, no matter what value it started with. The easy ways to do this are to call either poses->clear() or the assignment operator *poses = ....

Template Parameters
IdThe key used to locate the kinematics data. Can be FrameId or GeometryId.
KinematicsValueThe underlying data type of the kinematics data (e.g., pose, configuration, or velocity).

The FramePoseVector and GeometryConfigurationVector classes are aliases of the KinematicsVector instantiated on specific data types (RigidTransform and VectorX respectively). Each of these data types are templated on Eigen scalars. All supported combinations of data type and scalar type are already available to link against in the containing library. No other values for KinematicsValue are supported.

Currently, the following data types with the following scalar types are supported:

Alias Instantiation Scalar types
FramePoseVector<Scalar> KinematicsVector<FrameId,RigidTransform<Scalar>> double/AutoDiffXd/Expression
GeometryConfigurationVector<Scalar> KinematicsVector<GeometryId, VectorX<Scalar>> double/AutoDiffXd/Expression

#include <drake/geometry/kinematics_vector.h>

Public Member Functions

 KinematicsVector ()
 Initializes the vector with no data . More...
 
 KinematicsVector (std::initializer_list< std::pair< const Id, KinematicsValue >> init)
 Initializes the vector using the given the keys and their corresponding kinematics values. More...
 
 ~KinematicsVector ()
 
KinematicsVectoroperator= (std::initializer_list< std::pair< const Id, KinematicsValue >> init)
 Resets the vector to the given keys and kinematics values . More...
 
void clear ()
 Clears all values, resetting the size to zero. More...
 
void set_value (Id id, const KinematicsValue &value)
 Sets the kinematics value for the given id. More...
 
int size () const
 Returns number of ids(). More...
 
const KinematicsValue & value (Id id) const
 Returns the value associated with the given id. More...
 
bool has_id (Id id) const
 Reports true if the given id is a member of this data. More...
 
std::vector< Id > ids () const
 Provides a range object for all of the existing ids in the vector. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 KinematicsVector (const KinematicsVector &)=default
 
KinematicsVectoroperator= (const KinematicsVector &)=default
 
 KinematicsVector (KinematicsVector &&)=default
 
KinematicsVectoroperator= (KinematicsVector &&)=default
 

Constructor & Destructor Documentation

◆ KinematicsVector() [1/4]

KinematicsVector ( const KinematicsVector< Id, KinematicsValue > &  )
default

◆ KinematicsVector() [2/4]

KinematicsVector ( KinematicsVector< Id, KinematicsValue > &&  )
default

◆ KinematicsVector() [3/4]

Initializes the vector with no data .

◆ KinematicsVector() [4/4]

KinematicsVector ( std::initializer_list< std::pair< const Id, KinematicsValue >>  init)

Initializes the vector using the given the keys and their corresponding kinematics values.

◆ ~KinematicsVector()

Member Function Documentation

◆ clear()

void clear ( )

Clears all values, resetting the size to zero.

◆ has_id()

bool has_id ( Id  id) const

Reports true if the given id is a member of this data.

◆ ids()

std::vector<Id> ids ( ) const

Provides a range object for all of the existing ids in the vector.

This is intended to be used as:

for (Id id : this_vector.ids()) {
...
// Obtain the KinematicsValue of an id by `this_vector.value(id)`
...
}

◆ operator=() [1/3]

KinematicsVector& operator= ( KinematicsVector< Id, KinematicsValue > &&  )
default

◆ operator=() [2/3]

KinematicsVector& operator= ( const KinematicsVector< Id, KinematicsValue > &  )
default

◆ operator=() [3/3]

KinematicsVector& operator= ( std::initializer_list< std::pair< const Id, KinematicsValue >>  init)

Resets the vector to the given keys and kinematics values .

◆ set_value()

void set_value ( Id  id,
const KinematicsValue &  value 
)

Sets the kinematics value for the given id.

◆ size()

int size ( ) const

Returns number of ids().

◆ value()

const KinematicsValue& value ( Id  id) const

Returns the value associated with the given id.

Exceptions
std::exceptionif id is not in the specified set of ids.

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