tesseract_scene_graph_joint_unit.cpp
Go to the documentation of this file.
3 #include <gtest/gtest.h>
4 #include <iostream>
5 #include <fstream>
9 
12 
13 TEST(TesseractSceneGraphUnit, TesseractSceneGraphJointDynamicsUnit) // NOLINT
14 {
15  using namespace tesseract_scene_graph;
16  JointDynamics j;
17 
18  EXPECT_NEAR(j.damping, 0, 1e-6);
19  EXPECT_NEAR(j.friction, 0, 1e-6);
20 
21  j.damping = 10;
22  j.friction = 5;
23  j.clear();
24 
25  EXPECT_NEAR(j.damping, 0, 1e-6);
26  EXPECT_NEAR(j.friction, 0, 1e-6);
27 }
28 
29 TEST(TesseractSceneGraphUnit, TesseractSceneGraphJointLimitsUnit) // NOLINT
30 {
31  using namespace tesseract_scene_graph;
32  JointLimits j;
33 
34  EXPECT_NEAR(j.lower, 0, 1e-6);
35  EXPECT_NEAR(j.upper, 0, 1e-6);
36  EXPECT_NEAR(j.effort, 0, 1e-6);
37  EXPECT_NEAR(j.velocity, 0, 1e-6);
38  EXPECT_NEAR(j.acceleration, 0, 1e-6);
39 
40  j.lower = 1;
41  j.upper = 2;
42  j.effort = 3;
43  j.velocity = 4;
44  j.acceleration = 5;
45  j.clear();
46 
47  EXPECT_NEAR(j.lower, 0, 1e-6);
48  EXPECT_NEAR(j.upper, 0, 1e-6);
49  EXPECT_NEAR(j.effort, 0, 1e-6);
50  EXPECT_NEAR(j.velocity, 0, 1e-6);
51  EXPECT_NEAR(j.acceleration, 0, 1e-6);
52 
53  std::ostringstream s;
54  s << j;
55  EXPECT_FALSE(s.str().empty());
56 }
57 
58 TEST(TesseractSceneGraphUnit, TesseractSceneGraphJointSafetyUnit) // NOLINT
59 {
60  using namespace tesseract_scene_graph;
61  JointSafety j;
62 
63  EXPECT_NEAR(j.soft_upper_limit, 0, 1e-6);
64  EXPECT_NEAR(j.soft_lower_limit, 0, 1e-6);
65  EXPECT_NEAR(j.k_position, 0, 1e-6);
66  EXPECT_NEAR(j.k_velocity, 0, 1e-6);
67 
68  j.soft_upper_limit = 1;
69  j.soft_lower_limit = 2;
70  j.k_position = 3;
71  j.k_velocity = 4;
72  j.clear();
73 
74  EXPECT_NEAR(j.soft_upper_limit, 0, 1e-6);
75  EXPECT_NEAR(j.soft_lower_limit, 0, 1e-6);
76  EXPECT_NEAR(j.k_position, 0, 1e-6);
77  EXPECT_NEAR(j.k_velocity, 0, 1e-6);
78 
79  std::ostringstream s;
80  s << j;
81  EXPECT_FALSE(s.str().empty());
82 }
83 
84 TEST(TesseractSceneGraphUnit, TesseractSceneGraphJointCalibrationUnit) // NOLINT
85 {
86  using namespace tesseract_scene_graph;
88 
89  EXPECT_NEAR(j.reference_position, 0, 1e-6);
90  EXPECT_NEAR(j.rising, 0, 1e-6);
91  EXPECT_NEAR(j.falling, 0, 1e-6);
92 
93  j.reference_position = 1;
94  j.rising = 2;
95  j.falling = 3;
96  j.clear();
97 
98  EXPECT_NEAR(j.reference_position, 0, 1e-6);
99  EXPECT_NEAR(j.rising, 0, 1e-6);
100  EXPECT_NEAR(j.falling, 0, 1e-6);
101 
102  std::ostringstream s;
103  s << j;
104  EXPECT_FALSE(s.str().empty());
105 }
106 
107 TEST(TesseractSceneGraphUnit, TesseractSceneGraphJointMimicUnit) // NOLINT
108 {
109  using namespace tesseract_scene_graph;
110  JointMimic j;
111 
112  EXPECT_NEAR(j.offset, 0, 1e-6);
113  EXPECT_NEAR(j.multiplier, 1, 1e-6);
114  EXPECT_TRUE(j.joint_name.empty());
115 
116  j.offset = 1;
117  j.multiplier = 2;
118  j.joint_name = "joint_name";
119  j.clear();
120 
121  EXPECT_NEAR(j.offset, 0, 1e-6);
122  EXPECT_NEAR(j.multiplier, 1, 1e-6);
123  EXPECT_TRUE(j.joint_name.empty());
124 
125  std::ostringstream s;
126  s << j;
127  EXPECT_FALSE(s.str().empty());
128 }
129 
130 TEST(TesseractSceneGraphUnit, TesseractSceneGraphJointUnit) // NOLINT
131 {
132  using namespace tesseract_scene_graph;
133 
134  Joint joint_1("joint_n1");
135  EXPECT_TRUE(joint_1.parent_to_joint_origin_transform.isApprox(Eigen::Isometry3d::Identity()));
136  EXPECT_TRUE(joint_1.child_link_name.empty());
137  EXPECT_TRUE(joint_1.parent_link_name.empty());
138  EXPECT_TRUE(joint_1.child_link_name.empty());
139  EXPECT_TRUE(joint_1.dynamics == nullptr);
140  EXPECT_TRUE(joint_1.limits == nullptr);
141  EXPECT_TRUE(joint_1.safety == nullptr);
142  EXPECT_TRUE(joint_1.calibration == nullptr);
143  EXPECT_TRUE(joint_1.mimic == nullptr);
144  EXPECT_TRUE(joint_1.type == JointType::UNKNOWN);
145 
146  joint_1.parent_to_joint_origin_transform.translation() = Eigen::Vector3d(1, 2, 3);
147  joint_1.parent_link_name = "link_n1";
148  joint_1.child_link_name = "link_n2";
149  joint_1.axis = Eigen::Vector3d::UnitZ();
150  joint_1.type = JointType::PRISMATIC;
151  joint_1.dynamics = std::make_shared<JointDynamics>();
152  joint_1.dynamics->damping = 0.1;
153  joint_1.dynamics->friction = 0.25;
154  joint_1.limits = std::make_shared<JointLimits>();
155  joint_1.limits->lower = -5;
156  joint_1.limits->upper = 5;
157  joint_1.limits->effort = 0.5;
158  joint_1.limits->velocity = 2;
159  joint_1.calibration = std::make_shared<JointCalibration>();
160  joint_1.calibration->rising = 0.1;
161  joint_1.calibration->falling = 0.1;
162  joint_1.mimic = std::make_shared<JointMimic>();
163  joint_1.mimic->offset = 0.5;
164  joint_1.mimic->joint_name = "joint_0";
165  joint_1.mimic->multiplier = 1.5;
166  joint_1.safety = std::make_shared<JointSafety>();
167  joint_1.safety->soft_lower_limit = -0.5;
168  joint_1.safety->soft_upper_limit = 0.5;
169  joint_1.safety->k_position = 1.1;
170  joint_1.safety->k_velocity = 2.5;
171 
172  EXPECT_EQ(joint_1.getName(), "joint_n1");
173 
174  Joint joint_1_clone = joint_1.clone();
175  EXPECT_EQ(joint_1_clone.getName(), "joint_n1");
176  EXPECT_EQ(joint_1_clone.parent_link_name, "link_n1");
177  EXPECT_EQ(joint_1_clone.child_link_name, "link_n2");
178  EXPECT_TRUE(joint_1_clone.parent_to_joint_origin_transform.isApprox(joint_1.parent_to_joint_origin_transform));
179  EXPECT_TRUE(joint_1_clone.axis.isApprox(Eigen::Vector3d::UnitZ()));
180  EXPECT_EQ(joint_1_clone.type, JointType::PRISMATIC);
181  EXPECT_TRUE(joint_1_clone.dynamics != joint_1.dynamics);
182  EXPECT_NEAR(joint_1_clone.dynamics->damping, 0.1, 1e-6);
183  EXPECT_NEAR(joint_1_clone.dynamics->friction, 0.25, 1e-6);
184  EXPECT_TRUE(joint_1_clone.limits != joint_1.limits);
185  EXPECT_NEAR(joint_1_clone.limits->lower, -5, 1e-6);
186  EXPECT_NEAR(joint_1_clone.limits->upper, 5, 1e-6);
187  EXPECT_NEAR(joint_1_clone.limits->effort, 0.5, 1e-6);
188  EXPECT_NEAR(joint_1_clone.limits->velocity, 2, 1e-6);
189  EXPECT_TRUE(joint_1_clone.calibration != joint_1.calibration);
190  EXPECT_NEAR(joint_1_clone.calibration->rising, 0.1, 1e-6);
191  EXPECT_NEAR(joint_1_clone.calibration->falling, 0.1, 1e-6);
192  EXPECT_TRUE(joint_1_clone.mimic != joint_1.mimic);
193  EXPECT_NEAR(joint_1_clone.mimic->offset, 0.5, 1e-6);
194  EXPECT_EQ(joint_1_clone.mimic->joint_name, "joint_0");
195  EXPECT_NEAR(joint_1_clone.mimic->multiplier, 1.5, 1e-6);
196  EXPECT_NEAR(joint_1_clone.safety->soft_lower_limit, -0.5, 1e-6);
197  EXPECT_NEAR(joint_1_clone.safety->soft_upper_limit, 0.5, 1e-6);
198  EXPECT_NEAR(joint_1_clone.safety->k_position, 1.1, 1e-6);
199  EXPECT_NEAR(joint_1_clone.safety->k_velocity, 2.5, 1e-6);
200 
201  std::ostringstream s1;
202  s1 << JointType::FIXED;
203  EXPECT_EQ(s1.str(), "Fixed");
204  std::ostringstream s2;
205  s2 << JointType::PLANAR;
206  EXPECT_EQ(s2.str(), "Planar");
207  std::ostringstream s3;
208  s3 << JointType::FLOATING;
209  EXPECT_EQ(s3.str(), "Floating");
210  std::ostringstream s4;
211  s4 << JointType::REVOLUTE;
212  EXPECT_EQ(s4.str(), "Revolute");
213  std::ostringstream s5;
214  s5 << JointType::PRISMATIC;
215  EXPECT_EQ(s5.str(), "Prismatic");
216  std::ostringstream s6;
217  s6 << JointType::CONTINUOUS;
218  EXPECT_EQ(s6.str(), "Continuous");
219  std::ostringstream s7;
220  s7 << JointType::UNKNOWN;
221  EXPECT_EQ(s7.str(), "Unknown");
222 
223  joint_1.clear();
224  EXPECT_EQ(joint_1.getName(), "joint_n1");
225  EXPECT_TRUE(joint_1.parent_to_joint_origin_transform.isApprox(Eigen::Isometry3d::Identity()));
226  EXPECT_TRUE(joint_1.child_link_name.empty());
227  EXPECT_TRUE(joint_1.parent_link_name.empty());
228  EXPECT_TRUE(joint_1.child_link_name.empty());
229  EXPECT_TRUE(joint_1.dynamics == nullptr);
230  EXPECT_TRUE(joint_1.limits == nullptr);
231  EXPECT_TRUE(joint_1.safety == nullptr);
232  EXPECT_TRUE(joint_1.calibration == nullptr);
233  EXPECT_TRUE(joint_1.mimic == nullptr);
234  EXPECT_TRUE(joint_1.type == JointType::UNKNOWN);
235 }
236 
237 int main(int argc, char** argv)
238 {
239  testing::InitGoogleTest(&argc, argv);
240 
241  return RUN_ALL_TESTS();
242 }
tesseract_scene_graph::JointType::REVOLUTE
@ REVOLUTE
tesseract_scene_graph::JointType::UNKNOWN
@ UNKNOWN
tesseract_scene_graph::JointType::FLOATING
@ FLOATING
tesseract_scene_graph::Joint::mimic
JointMimic::Ptr mimic
Option to Mimic another Joint.
Definition: joint.h:329
TEST
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH TESSERACT_COMMON_IGNORE_WARNINGS_POP TEST(TesseractSceneGraphUnit, TesseractSceneGraphJointDynamicsUnit)
Definition: tesseract_scene_graph_joint_unit.cpp:13
tesseract_scene_graph::Joint::clone
Joint clone() const
Clone the joint keeping the name.
Definition: joint.cpp:275
utils.h
tesseract_scene_graph::JointSafety::k_position
double k_position
Definition: joint.h:178
tesseract_scene_graph::JointCalibration
Definition: joint.h:195
tesseract_scene_graph::Joint::parent_to_joint_origin_transform
Eigen::Isometry3d parent_to_joint_origin_transform
transform from Parent Link frame to Joint frame
Definition: joint.h:314
tesseract_scene_graph::Joint::safety
JointSafety::Ptr safety
Unsupported Hidden Feature.
Definition: joint.h:323
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_scene_graph::JointCalibration::rising
double rising
Definition: joint.h:211
tesseract_scene_graph::JointSafety::soft_lower_limit
double soft_lower_limit
Definition: joint.h:177
tesseract_scene_graph::Joint::axis
Eigen::Vector3d axis
Definition: joint.h:303
tesseract_scene_graph::JointSafety::clear
void clear()
Definition: joint.cpp:137
joint.h
geometries.h
tesseract_scene_graph::JointDynamics::clear
void clear()
Definition: joint.cpp:44
tesseract_scene_graph::JointType::PLANAR
@ PLANAR
tesseract_scene_graph::JointLimits::upper
double upper
Definition: joint.h:108
main
int main(int argc, char **argv)
Definition: tesseract_scene_graph_joint_unit.cpp:237
tesseract_scene_graph::Joint::child_link_name
std::string child_link_name
Definition: joint.h:307
tesseract_scene_graph::Joint::limits
JointLimits::Ptr limits
Joint Limits.
Definition: joint.h:320
tesseract_scene_graph::Joint::clear
void clear()
Definition: joint.cpp:261
tesseract_scene_graph::JointType::PRISMATIC
@ PRISMATIC
tesseract_scene_graph::JointMimic
Definition: joint.h:228
tesseract_scene_graph::JointLimits::acceleration
double acceleration
Definition: joint.h:111
tesseract_scene_graph::JointLimits
Definition: joint.h:92
tesseract_scene_graph::JointType::CONTINUOUS
@ CONTINUOUS
tesseract_scene_graph::Joint
Definition: joint.h:272
tesseract_scene_graph::JointCalibration::falling
double falling
Definition: joint.h:212
tesseract_scene_graph::JointCalibration::reference_position
double reference_position
Definition: joint.h:210
graph.h
A basic scene graph using boost.
tesseract_scene_graph::JointCalibration::clear
void clear()
Definition: joint.cpp:181
tesseract_scene_graph::JointSafety
Parameters for Joint Safety Controllers.
Definition: joint.h:129
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_scene_graph::Joint::dynamics
JointDynamics::Ptr dynamics
Joint Dynamics.
Definition: joint.h:317
tesseract_scene_graph::JointLimits::effort
double effort
Definition: joint.h:109
tesseract_scene_graph::JointMimic::joint_name
std::string joint_name
Definition: joint.h:245
tesseract_scene_graph::JointDynamics
Definition: joint.h:60
tesseract_scene_graph::Joint::calibration
JointCalibration::Ptr calibration
Unsupported Hidden Feature.
Definition: joint.h:326
tesseract_scene_graph::Joint::type
JointType type
The type of joint.
Definition: joint.h:293
tesseract_scene_graph::Joint::getName
const std::string & getName() const
Definition: joint.cpp:259
tesseract_scene_graph::JointLimits::velocity
double velocity
Definition: joint.h:110
tesseract_scene_graph::JointSafety::soft_upper_limit
double soft_upper_limit
Definition: joint.h:176
tesseract_scene_graph::JointDynamics::damping
double damping
Definition: joint.h:75
macros.h
tesseract_scene_graph::JointSafety::k_velocity
double k_velocity
Definition: joint.h:179
tesseract_scene_graph::JointLimits::lower
double lower
Definition: joint.h:107
tesseract_scene_graph::JointMimic::offset
double offset
Definition: joint.h:243
tesseract_scene_graph
Definition: fwd.h:32
tesseract_scene_graph::Joint::parent_link_name
std::string parent_link_name
Definition: joint.h:311
tesseract_scene_graph::JointType::FIXED
@ FIXED
tesseract_scene_graph::JointLimits::clear
void clear()
Definition: joint.cpp:82
tesseract_scene_graph::JointMimic::multiplier
double multiplier
Definition: joint.h:244
tesseract_scene_graph::JointMimic::clear
void clear()
Definition: joint.cpp:222
tesseract_scene_graph::JointDynamics::friction
double friction
Definition: joint.h:76


tesseract_scene_graph
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:49