Cheetah Software  1.0
test_spatial.cpp File Reference

Test spatial vector/transform maniuplation functions. More...

#include "Dynamics/SpatialInertia.h"
#include "Dynamics/spatial.h"
#include "Math/orientation_tools.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
+ Include dependency graph for test_spatial.cpp:

Go to the source code of this file.

Functions

 TEST (Spatial, axisRotation)
 
 TEST (Spatial, crm)
 
 TEST (Spatial, crf)
 
 TEST (Spatial, crm_prod)
 
 TEST (Spatial, crf_prod)
 
 TEST (Spatial, inertia)
 
 TEST (Spatial, inertia_flips)
 
 TEST (Spatial, pluho_and_plux)
 
 TEST (Spatial, invert_sxform)
 
 TEST (Spatial, jcalc)
 
 TEST (Spatial, mass_properties)
 
 TEST (Spatial, box_inertia)
 
 TEST (Spatial, velocityConver)
 
 TEST (Spatial, pointTransform)
 
 TEST (Spatial, forceToSpatialForce)
 
 TEST (Spatial, spatialToLinearVelocity)
 
 TEST (Spatial, spatialToLinearAcceleration)
 

Detailed Description

Test spatial vector/transform maniuplation functions.

Test the spatial utilities Doesn't test the algorithms.

Definition in file test_spatial.cpp.

Function Documentation

TEST ( Spatial  ,
axisRotation   
)

Check the spatialRotation function, which generates spatial transforms for coordinate axis rotations

Definition at line 21 of file test_spatial.cpp.

References almostEqual(), spatial::spatialRotation(), ori::X, ori::Y, and ori::Z.

21  {
22  // test X which rotates around an axis
23  SXform<double> X1, X2;
24  X1 << 0.8384, 0.4580, -0.2955, 0, 0, 0, -0.4183, 0.8882, 0.1898, 0, 0, 0,
25  0.3494, -0.0355, 0.9363, 0, 0, 0, 0, 0, 0, 0.8384, 0.4580, -0.2955, 0, 0,
26  0, -0.4183, 0.8882, 0.1898, 0, 0, 0, 0.3494, -0.0355, 0.9363;
27  X2 = spatialRotation(CoordinateAxis::X, .2) *
28  spatialRotation(CoordinateAxis::Y, .3) *
29  spatialRotation(CoordinateAxis::Z, .5);
30 
31  EXPECT_TRUE(almostEqual(X1, X2, .001));
32 }
typename Eigen::Matrix< T, 6, 6 > SXform
Definition: cppTypes.h:66
SXform< T > spatialRotation(CoordinateAxis axis, T theta)
Definition: spatial.h:28
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Spatial  ,
crm   
)

Check the motionCrossMatrix function, which behaves like crm() in MATLAB

Definition at line 37 of file test_spatial.cpp.

References almostEqual(), and spatial::motionCrossMatrix().

37  {
38  // test motion cross product matrix
39  SVec<double> v1, v2, v3, v4, v5, v6;
40  v1 << 1, 2, 3, 4, 5, 6;
41  v2 << 6, 5, 4, 3, 2, 1;
42  v3 = motionCrossMatrix(v1) * v2;
43  v4 << -7, 14, -7, -14, 28, -14;
44  v6 = motionCrossMatrix(v1) * v1;
45  v5 << 0, 0, 0, 0, 0, 0;
46  EXPECT_TRUE(almostEqual(v3, v4, .001));
47  EXPECT_TRUE(almostEqual(v6, v5, .0001));
48 }
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
auto motionCrossMatrix(const Eigen::MatrixBase< T > &v)
Definition: spatial.h:43
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Spatial  ,
crf   
)

Check the forceCrossMatrix function, which behaves like crf() in MATLAB Uses crm(-v).transpose() = crf(v) identity

Definition at line 54 of file test_spatial.cpp.

References almostEqual(), spatial::forceCrossMatrix(), and spatial::motionCrossMatrix().

54  {
55  // test force cross product matrix
56  SVec<double> v1, v2;
57  v1 << 1, 2, 3, 4, 5, 6;
58  v2 << 6, 5, 4, 3, 2, 1;
60  m1.transposeInPlace();
62  EXPECT_TRUE(almostEqual(m1, m2, .0001));
63 }
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
auto motionCrossMatrix(const Eigen::MatrixBase< T > &v)
Definition: spatial.h:43
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
auto forceCrossMatrix(const Eigen::MatrixBase< T > &v)
Definition: spatial.h:60

+ Here is the call graph for this function:

TEST ( Spatial  ,
crm_prod   
)

Test motionCrossProduct, a function to compute crm(v1)*v2 with fewer multiplies

Definition at line 69 of file test_spatial.cpp.

References almostEqual(), spatial::motionCrossMatrix(), and spatial::motionCrossProduct().

69  {
70  // test motion cross product
71  SVec<double> v1, v2, v3, v4;
72  v1 << 1, 2, 3, 4, 5, 6;
73  v2 << 6, 5, 4, 3, 2, 1;
74  v3 = motionCrossMatrix(v1) * v2;
75  v4 = motionCrossProduct(v1, v2);
76  EXPECT_TRUE(almostEqual(v3, v4, .0001));
77 }
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
auto motionCrossMatrix(const Eigen::MatrixBase< T > &v)
Definition: spatial.h:43
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
auto motionCrossProduct(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b)
Definition: spatial.h:73

+ Here is the call graph for this function:

TEST ( Spatial  ,
crf_prod   
)

Test forceCrossProduct, a function to compute crf(v1)*v2 with fewer multiplies

Definition at line 83 of file test_spatial.cpp.

References almostEqual(), spatial::forceCrossMatrix(), and spatial::forceCrossProduct().

83  {
84  // test force cross product
85  SVec<double> v1, v2, v3, v4;
86  v1 << 1, 2, 3, 4, 5, 6;
87  v2 << 6, 5, 4, 3, 2, 1;
88  v3 = forceCrossMatrix(v1) * v2;
89  v4 = forceCrossProduct(v1, v2);
90  EXPECT_TRUE(almostEqual(v3, v4, .0001));
91 }
auto forceCrossProduct(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b)
Definition: spatial.h:91
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
auto forceCrossMatrix(const Eigen::MatrixBase< T > &v)
Definition: spatial.h:60

+ Here is the call graph for this function:

TEST ( Spatial  ,
inertia   
)

Test spatial inertia Checks that it is built correctly from mass, CoM and rotational inertia (like mcI) Also checks the 4x4 Pseudo Inertia

Definition at line 98 of file test_spatial.cpp.

References almostEqual(), SpatialInertia< T >::getCOM(), SpatialInertia< T >::getInertiaTensor(), SpatialInertia< T >::getMass(), SpatialInertia< T >::getMatrix(), and SpatialInertia< T >::getPseudoInertia().

98  {
99  // test spatial inertia, mcI, and Pat's PseudoInertia
100  Mat3<double> I;
101  I << 1, 2, 3, 2, 4, 5, 3, 5, 6;
102  Vec3<double> com(10, 11, 12);
103  SpatialInertia<double> IS(42, com, I);
104  Mat6<double> ref;
105  Mat4<double> pref;
106  pref << 4204.5, 4618, 5037, 420, 4618, 5083.5, 5539, 462, 5037, 5539, 6047.5,
107  504, 420, 462, 504, 42;
108 
109  ref << 11131, -4618, -5037, 0, -504, 462, -4618, 10252, -5539, 504, 0, -420,
110  -5037, -5539, 9288, -462, 420, 0, 0, 504, -462, 42, 0, 0, -504, 0, 420, 0,
111  42, 0, 462, -420, 0, 0, 0, 42;
112 
113  SpatialInertia<double> IS2(IS.getPseudoInertia());
114 
115  EXPECT_TRUE(almostEqual(ref, IS.getMatrix(), .001));
116  EXPECT_EQ(42, IS.getMass());
117  EXPECT_TRUE(almostEqual(I, IS.getInertiaTensor(), .00001));
118  EXPECT_TRUE(almostEqual(com, IS.getCOM(), .00001));
119  EXPECT_TRUE(almostEqual(IS.getPseudoInertia(), pref, .1));
120  EXPECT_TRUE(almostEqual(IS.getMatrix(), IS2.getMatrix(), .00001));
121 }
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, 4, 4 > Mat4
Definition: cppTypes.h:94
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Spatial  ,
inertia_flips   
)

Check the flipAlongAxis method of spatial inertias

Definition at line 126 of file test_spatial.cpp.

References almostEqual(), and ori::Y.

126  {
127  // test flipping inertias around axes
128  MassProperties<double> a, aref;
129  a << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
130  aref << 1, 2, -3, 4, 5, 6, 7, -8, 9, -10;
131  EXPECT_TRUE(almostEqual(
132  SpatialInertia<double>(aref).getMatrix(),
133  SpatialInertia<double>(a).flipAlongAxis(CoordinateAxis::Y).getMatrix(),
134  .0001));
135 }
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
typename Eigen::Matrix< T, 10, 1 > MassProperties
Definition: cppTypes.h:98

+ Here is the call graph for this function:

TEST ( Spatial  ,
pluho_and_plux   
)

Check the homogeneous transformation (pluho) Also check the spatial transformation functions (plux)

Definition at line 141 of file test_spatial.cpp.

References almostEqual(), ori::coordinateRotation(), spatial::createSXform(), spatial::homogeneousToSXform(), spatial::rotationFromSXform(), spatial::sxformToHomogeneous(), spatial::translationFromSXform(), ori::X, ori::Y, and ori::Z.

141  {
142  // test homogeneous transformations and spatial transformations
143  RotMat<double> R = coordinateRotation(CoordinateAxis::X, 1.0) *
144  coordinateRotation(CoordinateAxis::Y, 2.0) *
145  coordinateRotation(CoordinateAxis::Z, 3.0);
146  Vec3<double> r(4, 5, 6);
147  Mat6<double> X = createSXform(R, r);
148  Mat6<double> Xref, X2;
150  Mat4<double> Href;
151  X2 = homogeneousToSXform(H);
152  Xref << 0.4120, -0.0587, -0.9093, 0, 0, 0, -0.8337, -0.4269, -0.3502, 0, 0, 0,
153  -0.3676, 0.9024, -0.2248, 0, 0, 0, -4.1941, 6.1091, -2.2948, 0.4120,
154  -0.0587, -0.9093, 0.8106, -3.6017, 2.4610, -0.8337, -0.4269, -0.3502,
155  -6.5385, -1.3064, 5.4477, -0.3676, 0.9024, -0.2248;
156  Href << 0.4120, -0.0587, -0.9093, 4.1015, -0.8337, -0.4269, -0.3502, 7.5706,
157  -0.3676, 0.9024, -0.2248, -1.6923, 0, 0, 0, 1.0000;
158  EXPECT_TRUE(almostEqual(Xref, X, .001));
159  EXPECT_TRUE(almostEqual(R, rotationFromSXform(X), .001));
160  EXPECT_TRUE(almostEqual(r, translationFromSXform(X), .001));
161  EXPECT_TRUE(almostEqual(H, Href, .001));
162  EXPECT_TRUE(almostEqual(X, X2, .00001));
163 }
Mat3< T > coordinateRotation(CoordinateAxis axis, T theta)
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
typename Eigen::Matrix< T, 4, 4 > Mat4
Definition: cppTypes.h:94
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
auto translationFromSXform(const Eigen::MatrixBase< T > &X)
Definition: spatial.h:168
auto createSXform(const Eigen::MatrixBase< T > &R, const Eigen::MatrixBase< T2 > &r)
Definition: spatial.h:140
auto sxformToHomogeneous(const Eigen::MatrixBase< T > &X)
Definition: spatial.h:108
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
auto homogeneousToSXform(const Eigen::MatrixBase< T > &H)
Definition: spatial.h:124
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:

TEST ( Spatial  ,
invert_sxform   
)

Check invertSXform, which computes inverse(X) quickly if X is a plucker coordinate transform

Definition at line 169 of file test_spatial.cpp.

References almostEqual(), ori::coordinateRotation(), spatial::createSXform(), spatial::invertSXform(), ori::X, ori::Y, and ori::Z.

169  {
170  RotMat<double> R = coordinateRotation(CoordinateAxis::X, 1.0) *
171  coordinateRotation(CoordinateAxis::Y, 2.0) *
172  coordinateRotation(CoordinateAxis::Z, 3.0);
173  Vec3<double> r(4, 5, 6);
174  Mat6<double> X = createSXform(R, r);
175  Mat6<double> Xi_ref = X.inverse();
176  Mat6<double> Xi = invertSXform(X);
177  EXPECT_TRUE(almostEqual(Xi_ref, Xi, .00001));
178 }
Mat3< T > coordinateRotation(CoordinateAxis axis, T theta)
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
auto createSXform(const Eigen::MatrixBase< T > &R, const Eigen::MatrixBase< T2 > &r)
Definition: spatial.h:140
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18
auto invertSXform(const Eigen::MatrixBase< T > &X)
Definition: spatial.h:181

+ Here is the call graph for this function:

TEST ( Spatial  ,
jcalc   
)

Test the jointXform and jointMotionSubspace functions, which are similar to jcalc

Definition at line 184 of file test_spatial.cpp.

References almostEqual(), spatial::jointXform(), ori::Y, and ori::Z.

184  {
185  Mat6<double> Xr, Xp, Xr_ref, Xp_ref;
186  SVec<double> phi_r, phi_p, phi_r_ref, phi_p_ref;
187 
188  Xr = jointXform(JointType::Revolute, CoordinateAxis::Y, std::asin(.707));
189  Xp = jointXform(JointType::Prismatic, CoordinateAxis::Z, .2);
190  phi_r = jointMotionSubspace<double>(JointType::Revolute, CoordinateAxis::Y);
191  phi_p = jointMotionSubspace<double>(JointType::Prismatic, CoordinateAxis::Z);
192 
193  Xr_ref << 0.7072, 0, -0.7070, 0, 0, 0, 0, 1.0000, 0, 0, 0, 0, 0.7070, 0,
194  0.7072, 0, 0, 0, 0, 0, 0, 0.7072, 0, -0.7070, 0, 0, 0, 0, 1.0000, 0, 0, 0,
195  0, 0.7070, 0, 0.7072;
196 
197  phi_r_ref << 0, 1, 0, 0, 0, 0;
198 
199  Xp_ref << 1.0000, 0, 0, 0, 0, 0, 0, 1.0000, 0, 0, 0, 0, 0, 0, 1.0000, 0, 0, 0,
200  0, 0.2000, 0, 1.0000, 0, 0, -0.2000, 0, 0, 0, 1.0000, 0, 0, 0, 0, 0, 0,
201  1.0000;
202 
203  phi_p_ref << 0, 0, 0, 0, 0, 1;
204 
205  EXPECT_TRUE(almostEqual(Xr, Xr_ref, .001));
206  EXPECT_TRUE(almostEqual(Xp, Xp_ref, .001));
207  EXPECT_TRUE(almostEqual(phi_r, phi_r_ref, .000001));
208  EXPECT_TRUE(almostEqual(phi_p, phi_p_ref, .000001));
209 }
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
Mat6< T > jointXform(JointType joint, CoordinateAxis axis, T q)
Definition: spatial.h:219
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Spatial  ,
mass_properties   
)

Test functions for converting between spatial inertias and the minimal representation "mass property vector", which contains 10 elements.

Definition at line 215 of file test_spatial.cpp.

References almostEqual(), SpatialInertia< T >::asMassPropertyVector(), and SpatialInertia< T >::getMatrix().

215  {
217  a << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
218  Mat6<double> I, I_ref;
219  I_ref << 5, 10, 9, 0, -4, 3, 10, 6, 8, 4, 0, -2, 9, 8, 7, -3, 2, 0, 0, 4, -3,
220  1, 0, 0, -4, 0, 2, 0, 1, 0, 3, -2, 0, 0, 0, 1;
222  EXPECT_TRUE(almostEqual(I_ref, IS.getMatrix(), .001));
223  EXPECT_TRUE(almostEqual(a, IS.asMassPropertyVector(), .001));
224 }
typename Eigen::Matrix< T, 6, 6 > Mat6
Definition: cppTypes.h:70
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
typename Eigen::Matrix< T, 10, 1 > MassProperties
Definition: cppTypes.h:98

+ Here is the call graph for this function:

TEST ( Spatial  ,
box_inertia   
)

Test utility function for computing the inertia of a uniform rectangular box

Definition at line 229 of file test_spatial.cpp.

References almostEqual(), and spatial::rotInertiaOfBox().

229  {
230  // test inertia of uniformly distributed box
231  Mat3<double> I_ref;
232  I_ref << 2.0833, 0, 0, 0, 1.66667, 0, 0, 0, 1.083333;
233  Mat3<double> I_calc = rotInertiaOfBox(1., Vec3<double>(2, 3, 4));
234  EXPECT_TRUE(almostEqual(I_ref, I_calc, .001));
235 }
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
Mat3< typename T::Scalar > rotInertiaOfBox(typename T::Scalar mass, const Eigen::MatrixBase< T > &dims)
Definition: spatial.h:245

+ Here is the call graph for this function:

TEST ( Spatial  ,
velocityConver   
)

Test utility function for converting spatial velocity to linear velocity at a point

Definition at line 241 of file test_spatial.cpp.

References almostEqual(), and spatial::spatialToLinearVelocity().

241  {
242  Vec3<double> vRef(-2, 17, 0);
243  SVec<double> vs;
244  vs << 1, 2, 3, 4, 5, 6;
245  Vec3<double> p(7, 8, 9);
247  EXPECT_TRUE(almostEqual(v, vRef, .00001));
248 }
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
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Spatial  ,
pointTransform   
)

Test utility function for transforming a point by a spatial transform

Definition at line 253 of file test_spatial.cpp.

References almostEqual(), ori::coordinateRotation(), spatial::createSXform(), spatial::sXFormPoint(), ori::X, ori::Y, and ori::Z.

253  {
254  Vec3<double> p0(1, 2, 3);
255  Vec3<double> pxRef(-3.0026, -1.9791, -3.7507);
256  Mat3<double> R = coordinateRotation(CoordinateAxis::X, .2) *
257  coordinateRotation(CoordinateAxis::Y, .3) *
258  coordinateRotation(CoordinateAxis::Z, .5);
259 
260  Vec3<double> r(4, 5, 6);
261  Mat6<double> X = createSXform(R, r);
262 
263  Vec3<double> px = sXFormPoint(X, p0);
264  EXPECT_TRUE(almostEqual(px, pxRef, .0005));
265 }
Mat3< T > coordinateRotation(CoordinateAxis axis, T theta)
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
auto sXFormPoint(const Eigen::MatrixBase< T > &X, const Eigen::MatrixBase< T2 > &p)
Definition: spatial.h:329
auto createSXform(const Eigen::MatrixBase< T > &R, const Eigen::MatrixBase< T2 > &r)
Definition: spatial.h:140
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Spatial  ,
forceToSpatialForce   
)

Test utility function for converting force at a point to a spatial force

Definition at line 270 of file test_spatial.cpp.

References almostEqual(), and spatial::forceToSpatialForce().

270  {
271  Vec3<double> fLinear(1, 2, 3);
272  Vec3<double> point(7, 8, 9);
273  SVec<double> fRef;
274  fRef << 6, -12, 6, 1, 2, 3;
275  SVec<double> fSpatial = forceToSpatialForce(fLinear, point);
276  EXPECT_TRUE(almostEqual(fSpatial, fRef, .0005));
277 }
auto forceToSpatialForce(const Eigen::MatrixBase< T > &f, const Eigen::MatrixBase< T2 > &p)
Definition: spatial.h:348
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Spatial  ,
spatialToLinearVelocity   
)

Test utility function for converting the spatial velocity to the velocity at a point

Definition at line 283 of file test_spatial.cpp.

References almostEqual(), and spatial::spatialToLinearVelocity().

283  {
284  SVec<double> vspat;
285  vspat << 1.93, 2.34, 3.345, -4.23, 5.8383, 6.921;
286  Vec3<double> vlin = vspat.tail(3);
287  Vec3<double> vang = vspat.head(3);
288  Vec3<double> point;
289  point << -23.23, 2.638, 9.324;
290 
291  Vec3<double> vpoint = vlin + vang.cross(point);
292  Vec3<double> vpoint2 = spatialToLinearVelocity(vspat, point);
293 
294  EXPECT_TRUE(almostEqual(vpoint2, vpoint, 1e-8));
295 }
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
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Spatial  ,
spatialToLinearAcceleration   
)

Test utility function for converting the spatial acceleration to the linear acceleration of a point

Definition at line 301 of file test_spatial.cpp.

References almostEqual(), and spatial::spatialToLinearAcceleration().

301  {
302  SVec<double> vspat, aspat;
303  // Top spinning with angular velocity w on a skateboard that is traveling at
304  // velocity v and is currently at point p
305  double w = 5;
306  double v = 1;
307  double p = 1;
308 
309  vspat << 0, 0, w, v, -w * p, 0;
310  aspat << 0, 0, 0, 0, -w * v, 0;
311 
312  Vec3<double> p2;
313  p2 << p, 0, 0;
314 
315  Vec3<double> a1 = spatialToLinearAcceleration(aspat, vspat);
316 
317  Vec3<double> a2 = spatialToLinearAcceleration(aspat, vspat, p2);
318 
319  Vec3<double> a1_expected, a2_expected;
320  a1_expected << w * w * p, 0, 0;
321  a2_expected << 0, 0, 0;
322 
323  EXPECT_TRUE(almostEqual(a1, a1_expected, 1e-8));
324  EXPECT_TRUE(almostEqual(a2, a2_expected, 1e-8));
325 
326  vspat << 1.93, 2.34, 3.345, -4.23, 5.8383, 6.921;
327  aspat << -5.164, 68.4, 1.56879, -98.44, 8.14, 6.324;
328  p2 << 54.797, -6.1654, 3.64587;
329 
330  Vec3<double> w1, v1, wd1, vd1;
331  Vec3<double> w2, v2, wd2, vd2;
332 
333  w1 = vspat.head(3);
334  v1 = vspat.tail(3);
335  wd1 = aspat.head(3);
336  vd1 = aspat.tail(3);
337 
338  w2 = w1;
339  wd2 = w2;
340  v2 = v1 + w1.cross(p2);
341  vd2 = vd1 + wd1.cross(p2);
342 
343  a1_expected = vd1 + w1.cross(v1);
344  a2_expected = vd2 + w2.cross(v2);
345 
346  a1 = spatialToLinearAcceleration(aspat, vspat);
347  a2 = spatialToLinearAcceleration(aspat, vspat, p2);
348 
349  EXPECT_TRUE(almostEqual(a1, a1_expected, 1e-8));
350  EXPECT_TRUE(almostEqual(a2, a2_expected, 1e-8));
351 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
auto spatialToLinearAcceleration(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T2 > &v)
Definition: spatial.h:289
typename Eigen::Matrix< T, 6, 1 > SVec
Definition: cppTypes.h:62
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function: