tesseract_state_solver_ofkt_unit.cpp
Go to the documentation of this file.
3 #include <gtest/gtest.h>
5 
9 
10 using namespace tesseract_scene_graph;
11 
12 // Most of OFKT is tested in the tesseract_environment_unit.cpp
13 TEST(TesseractStateSolverUnit, OFKTNodeBaseAndFailuresUnit) // NOLINT
14 {
15  { // OFKTRootNode
16  OFKTRootNode node("base_link");
17  EXPECT_ANY_THROW(node.setParent(nullptr)); // NOLINT
18  EXPECT_ANY_THROW(node.storeJointValue(0)); // NOLINT
19  EXPECT_ANY_THROW(node.setStaticTransformation(Eigen::Isometry3d::Identity())); // NOLINT
20  EXPECT_FALSE(node.updateWorldTransformationRequired());
21  EXPECT_TRUE(Eigen::Isometry3d::Identity().isApprox(node.computeLocalTransformation(0), 1e-6));
24  EXPECT_TRUE(Eigen::Isometry3d::Identity().isApprox(node.getLocalTransformation(), 1e-6));
25  EXPECT_TRUE(Eigen::Isometry3d::Identity().isApprox(node.getWorldTransformation(), 1e-6));
26  }
27 
28  { // OFKTRootNode
29  OFKTRootNode node("base_link");
30  EXPECT_ANY_THROW(node.setParent(nullptr)); // NOLINT
31  EXPECT_ANY_THROW(node.storeJointValue(0)); // NOLINT
32  EXPECT_ANY_THROW(node.setStaticTransformation(Eigen::Isometry3d::Identity())); // NOLINT
33  EXPECT_FALSE(node.updateWorldTransformationRequired());
34  EXPECT_TRUE(Eigen::Isometry3d::Identity().isApprox(node.computeLocalTransformation(0), 1e-6));
35  }
36 
37  { // OFKTFixedNode
38  OFKTRootNode root_node("base_link");
39  OFKTFixedNode node(&root_node, "base_link", "joint_a1", Eigen::Isometry3d::Identity());
40  const OFKTFixedNode& const_node = node;
41  EXPECT_TRUE(const_node.getParent() == &root_node);
42  EXPECT_ANY_THROW(node.storeJointValue(M_PI_2)); // NOLINT
43  EXPECT_ANY_THROW(node.getJointValue()); // NOLINT
44  EXPECT_FALSE(node.updateWorldTransformationRequired());
45  EXPECT_TRUE(Eigen::Isometry3d::Identity().isApprox(node.computeLocalTransformation(0), 1e-6));
46  EXPECT_TRUE(node.getStaticTransformation().isApprox(Eigen::Isometry3d::Identity(), 1e-6));
48  EXPECT_TRUE(Eigen::Isometry3d::Identity().isApprox(node.getLocalTransformation(), 1e-6));
49 
50  Eigen::Isometry3d static_tf = Eigen::Isometry3d::Identity();
51  static_tf.translation() = Eigen::Vector3d(1, 2, 3);
52  node.setStaticTransformation(static_tf);
53  EXPECT_TRUE(node.getStaticTransformation().isApprox(static_tf, 1e-6));
54  }
55 
56  { // OFKTFloatingNode
57  OFKTRootNode root_node("base_link");
58  OFKTFloatingNode node(&root_node, "base_link", "joint_a1", Eigen::Isometry3d::Identity());
59  const OFKTFloatingNode& const_node = node;
60  EXPECT_TRUE(const_node.getParent() == &root_node);
61  EXPECT_ANY_THROW(node.storeJointValue(M_PI_2)); // NOLINT
62  EXPECT_ANY_THROW(node.getJointValue()); // NOLINT
63  EXPECT_FALSE(node.updateWorldTransformationRequired());
64  EXPECT_TRUE(Eigen::Isometry3d::Identity().isApprox(node.computeLocalTransformation(0), 1e-6));
65  EXPECT_TRUE(node.getStaticTransformation().isApprox(Eigen::Isometry3d::Identity(), 1e-6));
67  EXPECT_TRUE(Eigen::Isometry3d::Identity().isApprox(node.getLocalTransformation(), 1e-6));
68 
69  Eigen::Isometry3d static_tf = Eigen::Isometry3d::Identity();
70  static_tf.translation() = Eigen::Vector3d(1, 2, 3);
71  node.setStaticTransformation(static_tf);
72  EXPECT_TRUE(node.getStaticTransformation().isApprox(static_tf, 1e-6));
73  }
74 
75  { // OFKTRevoluteNode
76  auto check = Eigen::Isometry3d::Identity() * Eigen::AngleAxisd(M_PI_2, Eigen::Vector3d(0, 0, 1));
77  OFKTRootNode root_node("base_link");
78  OFKTRevoluteNode node(&root_node, "base_link", "joint_a1", Eigen::Isometry3d::Identity(), Eigen::Vector3d(0, 0, 1));
79  EXPECT_TRUE(node.getParent() == &root_node);
80  EXPECT_FALSE(node.updateWorldTransformationRequired());
81  EXPECT_TRUE(node.getAxis().isApprox(Eigen::Vector3d(0, 0, 1), 1e-6));
82  EXPECT_NO_THROW(node.storeJointValue(M_PI_2)); // NOLINT
83  EXPECT_NEAR(node.getJointValue(), M_PI_2, 1e-6);
84  EXPECT_FALSE(node.updateWorldTransformationRequired());
85  EXPECT_TRUE(check.isApprox(node.computeLocalTransformation(M_PI_2), 1e-6));
87  EXPECT_TRUE(node.getLocalTransformation().isApprox(check, 1e-6));
89  EXPECT_TRUE(check.isApprox(node.getWorldTransformation(), 1e-6));
90  }
91 
92  { // OFKTContinuousNode
93  auto check = Eigen::Isometry3d::Identity() * Eigen::AngleAxisd(M_PI_2, Eigen::Vector3d(0, 0, 1));
94  OFKTRootNode root_node("base_link");
95  OFKTContinuousNode node(
96  &root_node, "base_link", "joint_a1", Eigen::Isometry3d::Identity(), Eigen::Vector3d(0, 0, 1));
97  const OFKTContinuousNode& const_node = node;
98  EXPECT_TRUE(const_node.getParent() == &root_node);
99  EXPECT_FALSE(node.updateWorldTransformationRequired());
100  EXPECT_TRUE(node.getAxis().isApprox(Eigen::Vector3d(0, 0, 1), 1e-6));
101  EXPECT_NO_THROW(node.storeJointValue(M_PI_2)); // NOLINT
102  EXPECT_NEAR(node.getJointValue(), M_PI_2, 1e-6);
103  EXPECT_FALSE(node.updateWorldTransformationRequired());
104  EXPECT_TRUE(check.isApprox(node.computeLocalTransformation(M_PI_2), 1e-6));
106  EXPECT_TRUE(node.getLocalTransformation().isApprox(check, 1e-6));
108  EXPECT_TRUE(check.isApprox(node.getWorldTransformation(), 1e-6));
109  }
110 
111  { // OFKTPrismaticNode
112  auto check = Eigen::Isometry3d::Identity() * Eigen::Translation3d(1.45, 0, 0);
113  OFKTRootNode root_node("base_link");
114  OFKTPrismaticNode node(
115  &root_node, "base_link", "joint_a1", Eigen::Isometry3d::Identity(), Eigen::Vector3d(1, 0, 0));
116  EXPECT_TRUE(node.getParent() == &root_node);
117  EXPECT_FALSE(node.updateWorldTransformationRequired());
118  EXPECT_TRUE(node.getAxis().isApprox(Eigen::Vector3d(1, 0, 0), 1e-6));
119  EXPECT_NO_THROW(node.storeJointValue(1.45)); // NOLINT
120  EXPECT_NEAR(node.getJointValue(), 1.45, 1e-6);
121  EXPECT_FALSE(node.updateWorldTransformationRequired());
122  EXPECT_TRUE(check.isApprox(node.computeLocalTransformation(1.45), 1e-6));
124  EXPECT_TRUE(node.getLocalTransformation().isApprox(check, 1e-6));
126  EXPECT_TRUE(check.isApprox(node.getWorldTransformation(), 1e-6));
127  }
128 }
129 
130 TEST(TesseractStateSolverUnit, OFKTAddRemoveLinkUnit) // NOLINT
131 {
132  test_suite::runAddandRemoveLinkTest<OFKTStateSolver>();
133 }
134 
135 TEST(TesseractStateSolverUnit, OFKTAddSceneGraphUnit) // NOLINT
136 {
137  test_suite::runAddSceneGraphTest<OFKTStateSolver>();
138 }
139 
140 TEST(TesseractStateSolverUnit, OFKTChangeJointOriginUnit) // NOLINT
141 {
142  test_suite::runChangeJointOriginTest<OFKTStateSolver>();
143 }
144 
145 TEST(TesseractStateSolverUnit, OFKTMoveJointUnit) // NOLINT
146 {
147  test_suite::runMoveJointTest<OFKTStateSolver>();
148 }
149 
150 TEST(TesseractStateSolverUnit, OFKTMoveLinkUnit) // NOLINT
151 {
152  test_suite::runMoveLinkTest<OFKTStateSolver>();
153 }
154 
155 TEST(TesseractStateSolverUnit, OFKTReplaceJointUnit) // NOLINT
156 {
157  test_suite::runReplaceJointTest<OFKTStateSolver>();
158 }
159 
160 TEST(TesseractStateSolverUnit, OFKTChangeJointLimitsUnit) // NOLINT
161 {
162  test_suite::runChangeJointLimitsTest<OFKTStateSolver>();
163 }
164 
165 TEST(TesseractStateSolverUnit, KDLGetJacobianUnit) // NOLINT
166 {
167  test_suite::runJacobianTest<KDLStateSolver>();
168 }
169 
170 TEST(TesseractStateSolverUnit, OFKTGetJacobianUnit) // NOLINT
171 {
172  test_suite::runJacobianTest<OFKTStateSolver>();
173 }
174 
175 TEST(TesseractStateSolverUnit, OFKTSetFloatingJointStateUnit) // NOLINT
176 {
177  test_suite::runSetFloatingJointStateTest<OFKTStateSolver>();
178 }
179 
180 TEST(TesseractStateSolverUnit, OFKTUnit) // NOLINT
181 {
182  OFKTStateSolver solver("test");
183  EXPECT_TRUE(solver.getLinkNames().size() == 1);
184  EXPECT_TRUE(solver.getLinkNames().at(0) == "test");
185  EXPECT_TRUE(solver.getLinkTransform("test").isApprox(Eigen::Isometry3d::Identity(), 1e-6));
186  EXPECT_TRUE(solver.getRevision() == 0);
187  solver.setRevision(100);
188  EXPECT_TRUE(solver.getRevision() == 100);
189 }
190 
191 int main(int argc, char** argv)
192 {
193  testing::InitGoogleTest(&argc, argv);
194 
195  return RUN_ALL_TESTS();
196 }
tesseract_scene_graph::OFKTFloatingNode::computeLocalTransformation
Eigen::Isometry3d computeLocalTransformation(double joint_value) const override
Compute the local tranformation but do not save.
Definition: ofkt_nodes.cpp:227
tesseract_scene_graph::OFKTFixedNode::getJointValue
double getJointValue() const override
Get the current joint value.
Definition: ofkt_nodes.cpp:179
tesseract_scene_graph::OFKTRevoluteNode::computeLocalTransformation
Eigen::Isometry3d computeLocalTransformation(double joint_value) const override
Compute the local tranformation but do not save.
Definition: ofkt_nodes.cpp:260
tesseract_scene_graph::OFKTContinuousNode::computeAndStoreLocalTransformation
void computeAndStoreLocalTransformation() override
Compute and save the local transformation 'L = S * J(Joint Value)'.
Definition: ofkt_nodes.cpp:294
tesseract_scene_graph::OFKTContinuousNode
Definition: ofkt_nodes.h:215
tesseract_scene_graph::OFKTFloatingNode::computeAndStoreLocalTransformation
void computeAndStoreLocalTransformation() override
Compute and save the local transformation 'L = S * J(Joint Value)'.
Definition: ofkt_nodes.cpp:225
tesseract_scene_graph::OFKTBaseNode::computeAndStoreWorldTransformation
void computeAndStoreWorldTransformation() override
Compute and store the nodes world transformation.
Definition: ofkt_nodes.cpp:102
tesseract_scene_graph::OFKTPrismaticNode::computeLocalTransformation
Eigen::Isometry3d computeLocalTransformation(double joint_value) const override
Compute the local tranformation but do not save.
Definition: ofkt_nodes.cpp:332
tesseract_scene_graph::OFKTFixedNode
Definition: ofkt_nodes.h:142
tesseract_scene_graph::OFKTRootNode::setParent
void setParent(OFKTNode *parent) override
Set the parent node.
Definition: ofkt_nodes.cpp:137
main
int main(int argc, char **argv)
Definition: tesseract_state_solver_ofkt_unit.cpp:191
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_scene_graph::OFKTRootNode::computeLocalTransformation
Eigen::Isometry3d computeLocalTransformation(double joint_value) const override
Compute the local tranformation but do not save.
Definition: ofkt_nodes.cpp:156
tesseract_scene_graph::OFKTFloatingNode::storeJointValue
void storeJointValue(double joint_value) override
Set the nodes joint value if it has one.
Definition: ofkt_nodes.cpp:208
ofkt_nodes.h
A implementation of the Optimized Forward Kinematic Tree Nodes.
tesseract_scene_graph::OFKTRootNode
Definition: ofkt_nodes.h:113
tesseract_scene_graph::OFKTFixedNode::computeLocalTransformation
Eigen::Isometry3d computeLocalTransformation(double joint_value) const override
Compute the local tranformation but do not save.
Definition: ofkt_nodes.cpp:190
tesseract_scene_graph::OFKTBaseNode::getWorldTransformation
const Eigen::Isometry3d & getWorldTransformation() const override
Get the nodes world transformation.
Definition: ofkt_nodes.cpp:107
tesseract_scene_graph::OFKTPrismaticNode::computeAndStoreLocalTransformation
void computeAndStoreLocalTransformation() override
Compute and save the local transformation 'L = S * J(Joint Value)'.
Definition: ofkt_nodes.cpp:330
tesseract_scene_graph::OFKTContinuousNode::computeLocalTransformation
Eigen::Isometry3d computeLocalTransformation(double joint_value) const override
Compute the local tranformation but do not save.
Definition: ofkt_nodes.cpp:296
tesseract_scene_graph::OFKTStateSolver::getLinkNames
std::vector< std::string > getLinkNames() const override final
Get the vector of link names.
Definition: ofkt_state_solver.cpp:474
tesseract_scene_graph::OFKTBaseNode::getParent
OFKTNode * getParent() override
Get the parent node.
Definition: ofkt_nodes.cpp:67
tesseract_scene_graph::OFKTPrismaticNode
Definition: ofkt_nodes.h:243
tesseract_scene_graph::OFKTBaseNode::getLocalTransformation
const Eigen::Isometry3d & getLocalTransformation() const override
Get the local transformation: 'L = S * J'.
Definition: ofkt_nodes.cpp:94
ofkt_state_solver.h
A implementation of the Optimized Forward Kinematic Tree as a state solver.
tesseract_scene_graph::OFKTRevoluteNode::getAxis
const Eigen::Vector3d & getAxis() const
Definition: ofkt_nodes.cpp:265
tesseract_scene_graph::OFKTRootNode::updateWorldTransformationRequired
bool updateWorldTransformationRequired() const override
Indicates if an update of the world transformation is required.
Definition: ofkt_nodes.cpp:154
tesseract_scene_graph::OFKTFixedNode::computeAndStoreLocalTransformation
void computeAndStoreLocalTransformation() override
Compute and save the local transformation 'L = S * J(Joint Value)'.
Definition: ofkt_nodes.cpp:188
tesseract_scene_graph::OFKTFloatingNode::getJointValue
double getJointValue() const override
Get the current joint value.
Definition: ofkt_nodes.cpp:213
tesseract_scene_graph::OFKTBaseNode::getJointValue
double getJointValue() const override
Get the current joint value.
Definition: ofkt_nodes.cpp:82
tesseract_scene_graph::OFKTStateSolver
An implementation of the Optimized Forward Kinematic Tree as a stat solver.
Definition: ofkt_state_solver.h:56
state_solver_test_suite.h
tesseract_scene_graph::OFKTRevoluteNode::computeAndStoreLocalTransformation
void computeAndStoreLocalTransformation() override
Compute and save the local transformation 'L = S * J(Joint Value)'.
Definition: ofkt_nodes.cpp:258
tesseract_scene_graph::OFKTFloatingNode::setStaticTransformation
void setStaticTransformation(const Eigen::Isometry3d &static_tf) override
Set the static transformation.
Definition: ofkt_nodes.cpp:218
tesseract_scene_graph::OFKTContinuousNode::getAxis
const Eigen::Vector3d & getAxis() const
Definition: ofkt_nodes.cpp:301
TEST
TEST(TesseractStateSolverUnit, OFKTNodeBaseAndFailuresUnit)
Definition: tesseract_state_solver_ofkt_unit.cpp:13
tesseract_scene_graph::OFKTPrismaticNode::getAxis
const Eigen::Vector3d & getAxis() const
Definition: ofkt_nodes.cpp:337
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_scene_graph::OFKTStateSolver::getRevision
int getRevision() const override final
Get the state solver revision number.
Definition: ofkt_state_solver.cpp:197
tesseract_scene_graph::OFKTBaseNode::storeJointValue
void storeJointValue(double joint_value) override
Set the nodes joint value if it has one.
Definition: ofkt_nodes.cpp:73
tesseract_scene_graph::OFKTFloatingNode
Definition: ofkt_nodes.h:164
tesseract_scene_graph::OFKTRevoluteNode
Definition: ofkt_nodes.h:186
tesseract_scene_graph::OFKTFixedNode::storeJointValue
void storeJointValue(double joint_value) override
Set the nodes joint value if it has one.
Definition: ofkt_nodes.cpp:174
tesseract_scene_graph::OFKTBaseNode::getStaticTransformation
const Eigen::Isometry3d & getStaticTransformation() const override
Get the nodes static transformation.
Definition: ofkt_nodes.cpp:93
tesseract_scene_graph::OFKTFixedNode::setStaticTransformation
void setStaticTransformation(const Eigen::Isometry3d &static_tf) override
Set the static transformation.
Definition: ofkt_nodes.cpp:181
macros.h
tesseract_scene_graph::OFKTRevoluteNode::storeJointValue
void storeJointValue(double joint_value) override
Set the nodes joint value if it has one.
Definition: ofkt_nodes.cpp:249
tesseract_scene_graph::OFKTRootNode::storeJointValue
void storeJointValue(double joint_value) override
Set the nodes joint value if it has one.
Definition: ofkt_nodes.cpp:142
tesseract_scene_graph::OFKTRootNode::setStaticTransformation
void setStaticTransformation(const Eigen::Isometry3d &static_tf) override
Set the static transformation.
Definition: ofkt_nodes.cpp:147
tesseract_scene_graph::OFKTStateSolver::setRevision
void setRevision(int revision) override final
Set the state solver revision number.
Definition: ofkt_state_solver.cpp:191
tesseract_scene_graph
tesseract_scene_graph::OFKTRootNode::computeAndStoreWorldTransformation
void computeAndStoreWorldTransformation() override
Compute and store the nodes world transformation.
Definition: ofkt_nodes.cpp:153
tesseract_scene_graph::OFKTRootNode::computeAndStoreLocalTransformation
void computeAndStoreLocalTransformation() override
Compute and save the local transformation 'L = S * J(Joint Value)'.
Definition: ofkt_nodes.cpp:152
tesseract_scene_graph::OFKTStateSolver::getLinkTransform
Eigen::Isometry3d getLinkTransform(const std::string &link_name) const override final
Get the transform corresponding to the link.
Definition: ofkt_state_solver.cpp:521
tesseract_scene_graph::OFKTBaseNode::updateWorldTransformationRequired
bool updateWorldTransformationRequired() const override
Indicates if an update of the world transformation is required.
Definition: ofkt_nodes.cpp:108


tesseract_state_solver
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:10