Cheetah Software  1.0
spatial Namespace Reference

Enumerations

enum  JointType { JointType::Prismatic, JointType::Revolute, JointType::FloatingBase, JointType::Nothing }
 

Functions

template<typename T >
SXform< T > spatialRotation (CoordinateAxis axis, T theta)
 
template<typename T >
auto motionCrossMatrix (const Eigen::MatrixBase< T > &v)
 
template<typename T >
auto forceCrossMatrix (const Eigen::MatrixBase< T > &v)
 
template<typename T >
auto motionCrossProduct (const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b)
 
template<typename T >
auto forceCrossProduct (const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b)
 
template<typename T >
auto sxformToHomogeneous (const Eigen::MatrixBase< T > &X)
 
template<typename T >
auto homogeneousToSXform (const Eigen::MatrixBase< T > &H)
 
template<typename T , typename T2 >
auto createSXform (const Eigen::MatrixBase< T > &R, const Eigen::MatrixBase< T2 > &r)
 
template<typename T >
auto rotationFromSXform (const Eigen::MatrixBase< T > &X)
 
template<typename T >
auto translationFromSXform (const Eigen::MatrixBase< T > &X)
 
template<typename T >
auto invertSXform (const Eigen::MatrixBase< T > &X)
 
template<typename T >
SVec< T > jointMotionSubspace (JointType joint, CoordinateAxis axis)
 
template<typename T >
Mat6< T > jointXform (JointType joint, CoordinateAxis axis, T q)
 
template<typename T >
Mat3< typename T::Scalar > rotInertiaOfBox (typename T::Scalar mass, const Eigen::MatrixBase< T > &dims)
 
template<typename T , typename T2 >
auto spatialToLinearVelocity (const Eigen::MatrixBase< T > &v, const Eigen::MatrixBase< T2 > &x)
 
template<typename T >
auto spatialToAngularVelocity (const Eigen::MatrixBase< T > &v)
 
template<typename T , typename T2 >
auto spatialToLinearAcceleration (const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T2 > &v)
 
template<typename T , typename T2 , typename T3 >
auto spatialToLinearAcceleration (const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T2 > &v, const Eigen::MatrixBase< T3 > &x)
 
template<typename T , typename T2 >
auto sXFormPoint (const Eigen::MatrixBase< T > &X, const Eigen::MatrixBase< T2 > &p)
 
template<typename T , typename T2 >
auto forceToSpatialForce (const Eigen::MatrixBase< T > &f, const Eigen::MatrixBase< T2 > &p)
 

Enumeration Type Documentation

enum spatial::JointType
strong

Function Documentation

template<typename T , typename T2 >
auto spatial::createSXform ( const Eigen::MatrixBase< T > &  R,
const Eigen::MatrixBase< T2 > &  r 
)

Create spatial coordinate transformation from rotation and translation

Definition at line 140 of file spatial.h.

References ori::vectorToSkewMat(), and ori::X.

141  {
142  static_assert(T::ColsAtCompileTime == 3 && T::RowsAtCompileTime == 3,
143  "Must have 3x3 matrix");
144  static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 3,
145  "Must have 3x1 matrix");
147  X.template topLeftCorner<3, 3>() = R;
148  X.template bottomRightCorner<3, 3>() = R;
149  X.template bottomLeftCorner<3, 3>() = -R * vectorToSkewMat(r);
150  return X;
151 }
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
Mat3< typename T::Scalar > vectorToSkewMat(const Eigen::MatrixBase< T > &v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
auto spatial::forceCrossMatrix ( const Eigen::MatrixBase< T > &  v)

Compute spatial force cross product matrix. Prefer forceCrossProduct when possible

Definition at line 60 of file spatial.h.

References f().

60  {
62  f << 0, -v(2), v(1), 0, -v(5), v(4), v(2), 0, -v(0), v(5), 0, -v(3), -v(1),
63  v(0), 0, -v(4), v(3), 0, 0, 0, 0, 0, -v(2), v(1), 0, 0, 0, v(2), 0, -v(0),
64  0, 0, 0, -v(1), v(0), 0;
65  return f;
66 }
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
auto spatial::forceCrossProduct ( const Eigen::MatrixBase< T > &  a,
const Eigen::MatrixBase< T > &  b 
)

Compute spatial force cross product. Faster than the matrix multiplication version

Definition at line 91 of file spatial.h.

92  {
93  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
94  "Must have 6x1 vector");
96  mv << b(2) * a(1) - b(1) * a(2) - b(4) * a(5) + b(5) * a(4),
97  b(0) * a(2) - b(2) * a(0) + b(3) * a(5) - b(5) * a(3),
98  b(1) * a(0) - b(0) * a(1) - b(3) * a(4) + b(4) * a(3),
99  b(5) * a(1) - b(4) * a(2), b(3) * a(2) - b(5) * a(0),
100  b(4) * a(0) - b(3) * a(1);
101  return mv;
102 }
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62

+ Here is the caller graph for this function:

template<typename T , typename T2 >
auto spatial::forceToSpatialForce ( const Eigen::MatrixBase< T > &  f,
const Eigen::MatrixBase< T2 > &  p 
)

Convert a force at a point to a spatial force

Parameters
f: force
p: point

Definition at line 348 of file spatial.h.

349  {
350  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 3,
351  "Must have 3x1 vector");
352  static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 3,
353  "Must have 3x1 vector");
355  fs.template topLeftCorner<3, 1>() = p.cross(f);
356  fs.template bottomLeftCorner<3, 1>() = f;
357  return fs;
358 }
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
MX f(const MX &x, const MX &u)

+ Here is the caller graph for this function:

template<typename T >
auto spatial::homogeneousToSXform ( const Eigen::MatrixBase< T > &  H)

Convert a homogeneous coordinate transformation to a spatial one

Definition at line 124 of file spatial.h.

References ori::vectorToSkewMat(), and ori::X.

124  {
125  static_assert(T::ColsAtCompileTime == 4 && T::RowsAtCompileTime == 4,
126  "Must have 4x4 matrix");
127  Mat3<typename T::Scalar> R = H.template topLeftCorner<3, 3>();
128  Vec3<typename T::Scalar> translate = H.template topRightCorner<3, 1>();
130  X.template topLeftCorner<3, 3>() = R;
131  X.template bottomLeftCorner<3, 3>() = vectorToSkewMat(translate) * R;
132  X.template bottomRightCorner<3, 3>() = R;
133  return X;
134 }
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
Mat3< typename T::Scalar > vectorToSkewMat(const Eigen::MatrixBase< T > &v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
auto spatial::invertSXform ( const Eigen::MatrixBase< T > &  X)

Invert a spatial transformation (much faster than matrix inverse)

Definition at line 181 of file spatial.h.

References createSXform(), ori::matToSkewVec(), and rotationFromSXform().

181  {
182  static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
183  "Must have 6x6 matrix");
186  -matToSkewVec(R.transpose() * X.template bottomLeftCorner<3, 3>());
187  SXform<typename T::Scalar> Xinv = createSXform(R.transpose(), -R * r);
188  return Xinv;
189 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
typename Eigen::Matrix< T, 6, 6 > SXform
Definition: cppTypes.h:66
auto createSXform(const Eigen::MatrixBase< T > &R, const Eigen::MatrixBase< T2 > &r)
Definition: spatial.h:140
Vec3< typename T::Scalar > matToSkewVec(const Eigen::MatrixBase< T > &m)
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18
auto rotationFromSXform(const Eigen::MatrixBase< T > &X)
Definition: spatial.h:157

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
SVec<T> spatial::jointMotionSubspace ( JointType  joint,
CoordinateAxis  axis 
)

Compute joint motion subspace vector

Definition at line 195 of file spatial.h.

References Prismatic, and Revolute.

195  {
196  Vec3<T> v(0, 0, 0);
197  SVec<T> phi = SVec<T>::Zero();
198  if (axis == CoordinateAxis::X)
199  v(0) = 1;
200  else if (axis == CoordinateAxis::Y)
201  v(1) = 1;
202  else
203  v(2) = 1;
204 
205  if (joint == JointType::Prismatic)
206  phi.template bottomLeftCorner<3, 1>() = v;
207  else if (joint == JointType::Revolute)
208  phi.template topLeftCorner<3, 1>() = v;
209  else
210  throw std::runtime_error("Unknown motion subspace");
211 
212  return phi;
213 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
template<typename T >
Mat6<T> spatial::jointXform ( JointType  joint,
CoordinateAxis  axis,
q 
)

Compute joint transformation

Definition at line 219 of file spatial.h.

References createSXform(), Prismatic, Revolute, spatialRotation(), and ori::X.

219  {
220  Mat6<T> X = Mat6<T>::Zero();
221  if (joint == JointType::Revolute) {
222  X = spatialRotation(axis, q);
223  } else if (joint == JointType::Prismatic) {
224  Vec3<T> v(0, 0, 0);
225  if (axis == CoordinateAxis::X)
226  v(0) = q;
227  else if (axis == CoordinateAxis::Y)
228  v(1) = q;
229  else if (axis == CoordinateAxis::Z)
230  v(2) = q;
231 
233  } else {
234  throw std::runtime_error("Unknown joint xform\n");
235  }
236  return X;
237 }
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
SXform< T > spatialRotation(CoordinateAxis axis, T theta)
Definition: spatial.h:28
auto createSXform(const Eigen::MatrixBase< T > &R, const Eigen::MatrixBase< T2 > &r)
Definition: spatial.h:140
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
auto spatial::motionCrossMatrix ( const Eigen::MatrixBase< T > &  v)

Compute the spatial motion cross product matrix. Prefer motionCrossProduct when possible.

Definition at line 43 of file spatial.h.

43  {
44  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
45  "Must have 6x1 vector");
47  m << 0, -v(2), v(1), 0, 0, 0, v(2), 0, -v(0), 0, 0, 0, -v(1), v(0), 0, 0, 0,
48  0,
49 
50  0, -v(5), v(4), 0, -v(2), v(1), v(5), 0, -v(3), v(2), 0, -v(0), -v(4),
51  v(3), 0, -v(1), v(0), 0;
52  return m;
53 }
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70

+ Here is the caller graph for this function:

template<typename T >
auto spatial::motionCrossProduct ( const Eigen::MatrixBase< T > &  a,
const Eigen::MatrixBase< T > &  b 
)

Compute spatial motion cross product. Faster than the matrix multiplication version

Definition at line 73 of file spatial.h.

74  {
75  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
76  "Must have 6x1 vector");
78  mv << a(1) * b(2) - a(2) * b(1), a(2) * b(0) - a(0) * b(2),
79  a(0) * b(1) - a(1) * b(0),
80  a(1) * b(5) - a(2) * b(4) + a(4) * b(2) - a(5) * b(1),
81  a(2) * b(3) - a(0) * b(5) - a(3) * b(2) + a(5) * b(0),
82  a(0) * b(4) - a(1) * b(3) + a(3) * b(1) - a(4) * b(0);
83  return mv;
84 }
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62

+ Here is the caller graph for this function:

template<typename T >
auto spatial::rotationFromSXform ( const Eigen::MatrixBase< T > &  X)

Get rotation matrix from spatial transformation

Definition at line 157 of file spatial.h.

157  {
158  static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
159  "Must have 6x6 matrix");
160  RotMat<typename T::Scalar> R = X.template topLeftCorner<3, 3>();
161  return R;
162 }
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18

+ Here is the caller graph for this function:

template<typename T >
Mat3<typename T::Scalar> spatial::rotInertiaOfBox ( typename T::Scalar  mass,
const Eigen::MatrixBase< T > &  dims 
)

Construct the rotational inertia of a uniform density box with a given mass.

Parameters
massMass of the box
dimsDimensions of the box

Definition at line 245 of file spatial.h.

246  {
247  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 3,
248  "Must have 3x1 vector");
250  Mat3<typename T::Scalar>::Identity() * dims.norm() * dims.norm();
251  for (int i = 0; i < 3; i++) I(i, i) -= dims(i) * dims(i);
252  I = I * mass / 12;
253  return I;
254 }
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54

+ Here is the caller graph for this function:

template<typename T >
SXform<T> spatial::spatialRotation ( CoordinateAxis  axis,
theta 
)

Calculate the spatial coordinate transform from A to B where B is rotate by theta about axis.

Definition at line 28 of file spatial.h.

References ori::coordinateRotation(), and ori::X.

28  {
29  static_assert(std::is_floating_point<T>::value,
30  "must use floating point value");
31  RotMat<T> R = coordinateRotation(axis, theta);
33  X.template topLeftCorner<3, 3>() = R;
34  X.template bottomRightCorner<3, 3>() = R;
35  return X;
36 }
Mat3< T > coordinateRotation(CoordinateAxis axis, T theta)
typename Eigen::Matrix< T, 6, 6 > SXform
Definition: cppTypes.h:66
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
auto spatial::spatialToAngularVelocity ( const Eigen::MatrixBase< T > &  v)

Convert from spatial velocity to angular velocity.

Definition at line 277 of file spatial.h.

277  {
278  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
279  "Must have 6x1 vector");
280  Vec3<typename T::Scalar> vsAng = v.template topLeftCorner<3, 1>();
281  return vsAng;
282 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
template<typename T , typename T2 >
auto spatial::spatialToLinearAcceleration ( const Eigen::MatrixBase< T > &  a,
const Eigen::MatrixBase< T2 > &  v 
)

Compute the classical lienear accleeration of a frame given its spatial acceleration and velocity

Definition at line 289 of file spatial.h.

290  {
291  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
292  "Must have 6x1 vector");
293  static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 6,
294  "Must have 6x1 vector");
295 
297  // classical accleration = spatial linear acc + omega x v
298  acc = a.template tail<3>() + v.template head<3>().cross(v.template tail<3>());
299  return acc;
300 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26

+ Here is the caller graph for this function:

template<typename T , typename T2 , typename T3 >
auto spatial::spatialToLinearAcceleration ( const Eigen::MatrixBase< T > &  a,
const Eigen::MatrixBase< T2 > &  v,
const Eigen::MatrixBase< T3 > &  x 
)

Compute the classical lienear acceleration of a frame given its spatial acceleration and velocity

Definition at line 307 of file spatial.h.

References spatialToLinearVelocity().

309  {
310  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
311  "Must have 6x1 vector");
312  static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 6,
313  "Must have 6x1 vector");
314  static_assert(T3::ColsAtCompileTime == 1 && T3::RowsAtCompileTime == 3,
315  "Must have 3x1 vector");
316 
319 
320  // classical accleration = spatial linear acc + omega x v
321  Vec3<typename T::Scalar> acc = alin_x + v.template head<3>().cross(vlin_x);
322  return acc;
323 }
auto spatialToLinearVelocity(const Eigen::MatrixBase< T > &v, const Eigen::MatrixBase< T2 > &x)
Definition: spatial.h:261
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26

+ Here is the call graph for this function:

template<typename T , typename T2 >
auto spatial::spatialToLinearVelocity ( const Eigen::MatrixBase< T > &  v,
const Eigen::MatrixBase< T2 > &  x 
)

Convert from spatial velocity to linear velocity. Uses spatial velocity at the given point.

Definition at line 261 of file spatial.h.

262  {
263  static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
264  "Must have 6x1 vector");
265  static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 3,
266  "Must have 3x1 vector");
267  Vec3<typename T::Scalar> vsAng = v.template topLeftCorner<3, 1>();
268  Vec3<typename T::Scalar> vsLin = v.template bottomLeftCorner<3, 1>();
269  Vec3<typename T::Scalar> vLinear = vsLin + vsAng.cross(x);
270  return vLinear;
271 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26

+ Here is the caller graph for this function:

template<typename T , typename T2 >
auto spatial::sXFormPoint ( const Eigen::MatrixBase< T > &  X,
const Eigen::MatrixBase< T2 > &  p 
)

Apply spatial transformation to a point.

Definition at line 329 of file spatial.h.

References rotationFromSXform(), and translationFromSXform().

330  {
331  static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
332  "Must have 6x6 vector");
333  static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 3,
334  "Must have 3x1 vector");
335 
338  Vec3<typename T::Scalar> Xp = R * (p - r);
339  return Xp;
340 }
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
auto translationFromSXform(const Eigen::MatrixBase< T > &X)
Definition: spatial.h:168
auto rotationFromSXform(const Eigen::MatrixBase< T > &X)
Definition: spatial.h:157

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
auto spatial::sxformToHomogeneous ( const Eigen::MatrixBase< T > &  X)

Convert a spatial transform to a homogeneous coordinate transformation

Definition at line 108 of file spatial.h.

References ori::matToSkewVec().

108  {
109  static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
110  "Must have 6x6 matrix");
112  RotMat<typename T::Scalar> R = X.template topLeftCorner<3, 3>();
113  Mat3<typename T::Scalar> skewR = X.template bottomLeftCorner<3, 3>();
114  H.template topLeftCorner<3, 3>() = R;
115  H.template topRightCorner<3, 1>() = matToSkewVec(skewR * R.transpose());
116  H(3, 3) = 1;
117  return H;
118 }
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, 4, 4 > Mat4
Definition: cppTypes.h:94
Vec3< typename T::Scalar > matToSkewVec(const Eigen::MatrixBase< T > &m)
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
auto spatial::translationFromSXform ( const Eigen::MatrixBase< T > &  X)

Get translation vector from spatial transformation

Definition at line 168 of file spatial.h.

References ori::matToSkewVec(), and rotationFromSXform().

168  {
169  static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
170  "Must have 6x6 matrix");
173  -matToSkewVec(R.transpose() * X.template bottomLeftCorner<3, 3>());
174  return r;
175 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
Vec3< typename T::Scalar > matToSkewVec(const Eigen::MatrixBase< T > &m)
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18
auto rotationFromSXform(const Eigen::MatrixBase< T > &X)
Definition: spatial.h:157

+ Here is the call graph for this function:

+ Here is the caller graph for this function: