1 #include <gtest/gtest.h> 12 std::srand(time(NULL));
41 EXPECT_EQ(v3.x(), 3.);
42 EXPECT_EQ(v3.y(), 5.);
43 EXPECT_EQ(v3.z(), 7.);
46 EXPECT_EQ(v1.x(), 1.);
47 EXPECT_EQ(v1.y(), 2.);
48 EXPECT_EQ(v1.z(), 3.);
52 EXPECT_EQ(v3.x(), -1.);
53 EXPECT_EQ(v3.y(), -1.);
54 EXPECT_EQ(v3.z(), -1.);
61 Vector3d v6 = v4 - (v4.dot(v5)) * v5;
65 v6 = v4 - v5 * (v4.dot(v5));
73 EXPECT_EQ(vec.x(), 1.);
74 EXPECT_EQ(vec.y(), 2.);
75 EXPECT_EQ(vec.z(), 3.);
77 Eigen::Vector3d vector = frameVector;
78 EXPECT_TRUE(vector(0) == 1.);
79 EXPECT_TRUE(vector(1) == 2.);
80 EXPECT_TRUE(vector(2) == 3.);
82 Eigen::Vector3d vector2(3., 2., 1.);
85 Eigen::Vector3d vectorCheck = frameVector2;
86 EXPECT_TRUE(vectorCheck(0) == 3.);
87 EXPECT_TRUE(vectorCheck(1) == 2.);
88 EXPECT_TRUE(vectorCheck(2) == 1.);
98 EXPECT_EQ(frameVector.x(), 0.1);
99 EXPECT_EQ(frameVector.y(), 0.2);
100 EXPECT_EQ(frameVector.z(), 0.3);
105 EXPECT_EQ(frameVector.x(), 0.3);
106 EXPECT_EQ(frameVector.y(), 0.2);
107 EXPECT_EQ(frameVector.z(), 0.1);
115 EXPECT_STREQ(e.
what(),
"Reference frame cannot be nullptr!");
124 EXPECT_STREQ(e.
what(),
"Reference frame cannot be nullptr!");
136 frameVector1.
dot(frameVector2);
140 EXPECT_STREQ(e.
what(),
"Reference frames do not match!");
143 double value = frameVector1.
dot(frameVector3);
145 EXPECT_TRUE(value = 24);
150 Eigen::Vector3d result;
151 Eigen::Vector3d expectedResult;
153 for (
int i = 0; i < nTests; i++)
155 Eigen::Vector3d v1(unit_test_utils::getRandomNumber<double>(), unit_test_utils::getRandomNumber<double>(), unit_test_utils::getRandomNumber<double>());
156 Eigen::Vector3d v2(unit_test_utils::getRandomNumber<double>(), unit_test_utils::getRandomNumber<double>(), unit_test_utils::getRandomNumber<double>());
157 Eigen::Vector3d v3(unit_test_utils::getRandomNumber<double>(), unit_test_utils::getRandomNumber<double>(), unit_test_utils::getRandomNumber<double>());
165 frameVector1.
cross(frameVector2);
169 EXPECT_STREQ(e.
what(),
"Reference frames do not match!");
172 Eigen::Vector3d result = frameVector1.
cross(frameVector3);
173 Eigen::Vector3d expectedResult = v1.
cross(v3);
174 EXPECT_TRUE(result(0) == expectedResult(0));
175 EXPECT_TRUE(result(1) == expectedResult(1));
176 EXPECT_TRUE(result(2) == expectedResult(2));
178 result = frameVector1.
cross(v2);
179 expectedResult = v1.
cross(v2);
180 EXPECT_TRUE(result.isApprox(expectedResult, 1.e-12));
190 double expectedResult = acos(13 / (sqrt(14) * sqrt(21)));
191 EXPECT_TRUE(angle == expectedResult);
193 frameVector1.
set(0., 0., 0.);
276 Eigen::Vector3d result;
277 Eigen::Vector3d expectedResult;
279 for (
int i = 0; i < nTests; i++)
281 Eigen::Vector3d v1(unit_test_utils::getRandomNumber<double>(), unit_test_utils::getRandomNumber<double>(), unit_test_utils::getRandomNumber<double>());
285 double result = frameVector1.norm();
286 double expectedResult = v1.norm();
287 EXPECT_TRUE(result == expectedResult);
291 int main(
int argc,
char** argv)
293 ::testing::InitGoogleTest(&argc, argv);
294 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
295 return RUN_ALL_TESTS();
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
static ReferenceFramePtr createRandomUnchangingFrame(const std::string &frameName, ReferenceFramePtr parentFrame, const unsigned int movableBodyId)
A custom exception for frame operations.
static ReferenceFramePtr createARootFrame(const std::string &frameName)
Creates a root frame with ReferenceFrame::parentFrame=nullptr.
SpatialTransform Xroty(const double &yrot)
Get transform with zero translation and pure rotation about y axis.
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
FrameVector changeFrameAndCopy(ReferenceFramePtr referenceFrame) const
copy into new frame vector and change the frame of that
void setReferenceFrame(ReferenceFramePtr frame)
Set frame objects internal reference frame.
FrameVector cross(const FrameVector &vector) const
Cross product between two FrameVectors, i.e. .
virtual const char * what() const
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
void setIncludingFrame(const double x, const double y, const double z, ReferenceFramePtr referenceFrame)
Set the x, y, and z components and the ReferenceFrame these components are expressed in...
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
ReferenceFrame object used to tell what frame objects are expressed in. Every ReferenceFrame has a po...
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
int main(int argc, char **argv)
void set(const Eigen::Vector3d &v)
double dot(const FrameVector &frameVector) const
Dot product between two FrameVectors, i.e. .
TEST_F(FrameVectorTest, operators)
Namespace for all structures of the RobotDynamics library.
double getAngleBetweenVectors(const FrameVector &frameVector) const
Computer the angle between two FrameVectors, .