tesseract_environment_serialization_unit.cpp
Go to the documentation of this file.
1 
29 #include <gtest/gtest.h>
31 
35 #include <tesseract_common/utils.h>
36 
39 
43 
45 
47 
48 using namespace tesseract_common;
49 using namespace tesseract_environment;
50 using namespace tesseract_scene_graph;
51 using namespace tesseract_srdf;
52 
54 {
55  std::string path = "package://tesseract_support/urdf/lbr_iiwa_14_r820.urdf";
56  return tesseract_urdf::parseURDFFile(locator.locateResource(path)->getFilePath(), locator);
57 }
58 
60 {
61  std::string path = "package://tesseract_support/urdf/lbr_iiwa_14_r820.srdf";
62 
63  auto srdf = std::make_shared<SRDFModel>();
64  srdf->initFile(scene_graph, locator.locateResource(path)->getFilePath(), locator);
65 
66  return srdf;
67 }
68 
70 {
72  auto env = std::make_shared<Environment>();
74  auto srdf = getSRDFModel(*scene_graph, locator);
75  env->init(*scene_graph, srdf);
76  env->setResourceLocator(std::make_shared<tesseract_common::GeneralResourceLocator>());
77  return env;
78 }
79 
80 TEST(EnvironmentSerializeUnit, Environment) // NOLINT
81 {
83  testSerializationPtr<Environment>(env, "Environment");
84 }
85 
86 TEST(EnvironmentSerializeUnit, EnvironmentAnyPoly) // NOLINT
87 {
89  tesseract_common::AnyPoly env_any(env);
90  testSerializationAnyPolyStoredSharedPtr<Environment::Ptr>(env_any, "EnvironmentAnyPoly");
91 }
92 
93 TEST(EnvironmentCommandsSerializeUnit, ModifyAllowedCollisionsCommand) // NOLINT
94 {
95  { // ADD
97  add_ac.addAllowedCollision("link1", "link2", "description");
98  auto object = std::make_shared<ModifyAllowedCollisionsCommand>(add_ac, ModifyAllowedCollisionsType::ADD);
99  testSerialization<ModifyAllowedCollisionsCommand>(*object, "ModifyAllowedCollisionsCommand");
100  testSerializationDerivedClass<Command, ModifyAllowedCollisionsCommand>(object, "ModifyAllowedCollisionsCommand");
101  }
102 
103  { // REMOVE
105  remove_ac.addAllowedCollision("link1", "link2", "description");
106  auto object = std::make_shared<ModifyAllowedCollisionsCommand>(remove_ac, ModifyAllowedCollisionsType::REMOVE);
107  testSerialization<ModifyAllowedCollisionsCommand>(*object, "ModifyAllowedCollisionsCommand");
108  testSerializationDerivedClass<Command, ModifyAllowedCollisionsCommand>(object, "ModifyAllowedCollisionsCommand");
109  }
110 
111  { // REMOVE
113  replace_ac.addAllowedCollision("link1", "link2", "description");
114  auto object = std::make_shared<ModifyAllowedCollisionsCommand>(replace_ac, ModifyAllowedCollisionsType::REPLACE);
115  testSerialization<ModifyAllowedCollisionsCommand>(*object, "ModifyAllowedCollisionsCommand");
116  testSerializationDerivedClass<Command, ModifyAllowedCollisionsCommand>(object, "ModifyAllowedCollisionsCommand");
117  }
118 }
119 
120 TEST(EnvironmentCommandsSerializeUnit, AddContactManagersPluginInfoCommand) // NOLINT
121 {
122  tesseract_common::ContactManagersPluginInfo info = getEnvironment()->getContactManagersPluginInfo();
123  auto object = std::make_shared<AddContactManagersPluginInfoCommand>(info);
124  testSerialization<AddContactManagersPluginInfoCommand>(*object, "AddContactManagersPluginInfoCommand");
125  testSerializationDerivedClass<Command, AddContactManagersPluginInfoCommand>(object,
126  "AddContactManagersPluginInfoCommand");
127 }
128 
129 TEST(EnvironmentCommandsSerializeUnit, AddKinematicsInformationCommand) // NOLINT
130 {
131  tesseract_srdf::KinematicsInformation info = getEnvironment()->getKinematicsInformation();
132  auto object = std::make_shared<AddKinematicsInformationCommand>(info);
133  testSerialization<AddKinematicsInformationCommand>(*object, "AddKinematicsInformationCommand");
134  testSerializationDerivedClass<Command, AddKinematicsInformationCommand>(object, "AddKinematicsInformationCommand");
135 }
136 
137 TEST(EnvironmentCommandsSerializeUnit, AddLinkCommand) // NOLINT
138 {
139  Link link_1("link_1");
140  Link link_2("link_2");
141  Joint joint_1("joint_1");
142  joint_1.parent_to_joint_origin_transform.translation()(0) = 1.25;
143  joint_1.parent_link_name = "link_1";
144  joint_1.child_link_name = "link_2";
145  joint_1.type = JointType::FIXED;
146 
147  auto object = std::make_shared<AddLinkCommand>(link_2, joint_1, false);
148  testSerialization<AddLinkCommand>(*object, "AddLinkCommand");
149  testSerializationDerivedClass<Command, AddLinkCommand>(object, "AddLinkCommand");
150 }
151 
152 TEST(EnvironmentCommandsSerializeUnit, AddTrajectoryLinkCommand) // NOLINT
153 {
155  trajectory.push_back(tesseract_common::JointState({ "j1", "j2" }, Eigen::VectorXd::Zero(2)));
156  trajectory.push_back(tesseract_common::JointState({ "j1", "j2" }, Eigen::VectorXd::Ones(2)));
157 
158  auto object = std::make_shared<AddTrajectoryLinkCommand>("link_name", "parent_link_name", trajectory, false);
159  testSerialization<AddTrajectoryLinkCommand>(*object, "AddTrajectoryLinkCommand");
160  testSerializationDerivedClass<Command, AddTrajectoryLinkCommand>(object, "AddTrajectoryLinkCommand");
161 }
162 
163 TEST(EnvironmentCommandsSerializeUnit, AddSceneGraphCommand) // NOLINT
164 {
167  Joint joint_1("joint_1");
168  joint_1.parent_to_joint_origin_transform.translation()(0) = 1.25;
169  joint_1.parent_link_name = "world";
170  joint_1.child_link_name = "joint_a1";
171  joint_1.type = JointType::FIXED;
172  auto object = std::make_shared<AddSceneGraphCommand>(*getSceneGraph(locator), joint, "prefix");
173  testSerialization<AddSceneGraphCommand>(*object, "AddSceneGraphCommand");
174  testSerializationDerivedClass<Command, AddSceneGraphCommand>(object, "AddSceneGraphCommand");
175 }
176 
177 TEST(EnvironmentCommandsSerializeUnit, ChangeCollisionMarginsCommand) // NOLINT
178 {
179  CollisionMarginPairData pair_margin_data;
180  pair_margin_data.setCollisionMargin("a", "b", 0.2);
181  auto object =
182  std::make_shared<ChangeCollisionMarginsCommand>(0.1, pair_margin_data, CollisionMarginPairOverrideType::MODIFY);
183  testSerialization<ChangeCollisionMarginsCommand>(*object, "ChangeCollisionMarginsCommand");
184  testSerializationDerivedClass<Command, ChangeCollisionMarginsCommand>(object, "ChangeCollisionMarginsCommand");
185 }
186 
187 TEST(EnvironmentCommandsSerializeUnit, ChangeJointAccelerationLimitsCommand) // NOLINT
188 {
189  auto object = std::make_shared<ChangeJointAccelerationLimitsCommand>("joint6", 3001);
190  testSerialization<ChangeJointAccelerationLimitsCommand>(*object, "ChangeJointAccelerationLimitsCommand");
191  testSerializationDerivedClass<Command, ChangeJointAccelerationLimitsCommand>(object,
192  "ChangeJointAccelerationLimitsCommand");
193 }
194 
195 TEST(EnvironmentCommandsSerializeUnit, ChangeJointOriginCommand) // NOLINT
196 {
197  Eigen::Isometry3d origin = Eigen::Isometry3d::Identity();
198  origin.translate(Eigen::Vector3d(1, 5, 9));
199  auto object = std::make_shared<ChangeJointOriginCommand>("joint6", origin);
200  testSerialization<ChangeJointOriginCommand>(*object, "ChangeJointOriginCommand");
201  testSerializationDerivedClass<Command, ChangeJointOriginCommand>(object, "ChangeJointOriginCommand");
202 }
203 
204 TEST(EnvironmentCommandsSerializeUnit, ChangeJointPositionLimitsCommand) // NOLINT
205 {
206  auto object = std::make_shared<ChangeJointPositionLimitsCommand>("joint6", -M_PI, M_PI);
207  testSerialization<ChangeJointPositionLimitsCommand>(*object, "ChangeJointPositionLimitsCommand");
208  testSerializationDerivedClass<Command, ChangeJointPositionLimitsCommand>(object, "ChangeJointPositionLimitsCommand");
209 }
210 
211 TEST(EnvironmentCommandsSerializeUnit, ChangeJointVelocityLimitsCommand) // NOLINT
212 {
213  auto object = std::make_shared<ChangeJointVelocityLimitsCommand>("joint6", 5001);
214  testSerialization<ChangeJointVelocityLimitsCommand>(*object, "ChangeJointVelocityLimitsCommand");
215  testSerializationDerivedClass<Command, ChangeJointVelocityLimitsCommand>(object, "ChangeJointVelocityLimitsCommand");
216 }
217 
218 TEST(EnvironmentCommandsSerializeUnit, ChangeLinkCollisionEnabledCommand) // NOLINT
219 {
220  auto object = std::make_shared<ChangeLinkCollisionEnabledCommand>("joint3", true);
221  testSerialization<ChangeLinkCollisionEnabledCommand>(*object, "ChangeLinkCollisionEnabledCommand");
222  testSerializationDerivedClass<Command, ChangeLinkCollisionEnabledCommand>(object,
223  "ChangeLinkCollisionEnabledCommand");
224 }
225 
226 TEST(EnvironmentCommandsSerializeUnit, ChangeLinkOriginCommand) // NOLINT
227 {
228  Eigen::Isometry3d origin = Eigen::Isometry3d::Identity();
229  origin.translate(Eigen::Vector3d(1, 5, 9));
230  auto object = std::make_shared<ChangeLinkOriginCommand>("really long test joint name with whitespace", origin);
231  testSerialization<ChangeLinkOriginCommand>(*object, "ChangeLinkOriginCommand");
232  testSerializationDerivedClass<Command, ChangeLinkOriginCommand>(object, "ChangeLinkOriginCommand");
233 }
234 
235 TEST(EnvironmentCommandsSerializeUnit, ChangeLinkVisibilityCommand) // NOLINT
236 {
237  auto object = std::make_shared<ChangeLinkVisibilityCommand>("j1", true);
238  testSerialization<ChangeLinkVisibilityCommand>(*object, "ChangeLinkVisibilityCommand");
239  testSerializationDerivedClass<Command, ChangeLinkVisibilityCommand>(object, "ChangeLinkVisibilityCommand");
240 }
241 
242 TEST(EnvironmentCommandsSerializeUnit, MoveJointCommand) // NOLINT
243 {
244  auto object = std::make_shared<MoveJointCommand>("j1", "j2");
245  testSerialization<MoveJointCommand>(*object, "MoveJointCommand");
246  testSerializationDerivedClass<Command, MoveJointCommand>(object, "MoveJointCommand");
247 }
248 
249 TEST(EnvironmentCommandsSerializeUnit, MoveLinkCommand) // NOLINT
250 {
251  auto joint_1 = std::make_shared<Joint>("name");
252  joint_1->parent_to_joint_origin_transform.translation()(0) = 1.25;
253  joint_1->parent_link_name = "l1";
254  joint_1->child_link_name = "l2";
255  joint_1->type = JointType::FIXED;
256 
257  auto object = std::make_shared<MoveLinkCommand>(*joint_1);
258  testSerialization<MoveLinkCommand>(*object, "MoveLinkCommand");
259  testSerializationDerivedClass<Command, MoveLinkCommand>(object, "MoveLinkCommand");
260 }
261 
262 TEST(EnvironmentCommandsSerializeUnit, RemoveAllowedCollisionLinkCommand) // NOLINT
263 {
264  auto object = std::make_shared<RemoveAllowedCollisionLinkCommand>("link name");
265  testSerialization<RemoveAllowedCollisionLinkCommand>(*object, "RemoveAllowedCollisionLinkCommand");
266  testSerializationDerivedClass<Command, RemoveAllowedCollisionLinkCommand>(object,
267  "RemoveAllowedCollisionLinkCommand");
268 }
269 
270 TEST(EnvironmentCommandsSerializeUnit, RemoveJointCommand) // NOLINT
271 {
272  auto object = std::make_shared<RemoveJointCommand>("joint name");
273  testSerialization<RemoveJointCommand>(*object, "RemoveJointCommand");
274  testSerializationDerivedClass<Command, RemoveJointCommand>(object, "RemoveJointCommand");
275 }
276 
277 TEST(EnvironmentCommandsSerializeUnit, RemoveLinkCommand) // NOLINT
278 {
279  auto object = std::make_shared<RemoveLinkCommand>("link name");
280  testSerialization<RemoveLinkCommand>(*object, "RemoveLinkCommand");
281  testSerializationDerivedClass<Command, RemoveLinkCommand>(object, "RemoveLinkCommand");
282 }
283 
284 TEST(EnvironmentCommandsSerializeUnit, ReplaceJointCommand) // NOLINT
285 {
286  auto joint_1 = std::make_shared<Joint>("name");
287  joint_1->parent_to_joint_origin_transform.translation()(0) = 1.25;
288  joint_1->parent_link_name = "l1";
289  joint_1->child_link_name = "l2";
290  joint_1->type = JointType::FIXED;
291  auto object = std::make_shared<ReplaceJointCommand>(*joint_1);
292  testSerialization<ReplaceJointCommand>(*object, "ReplaceJointCommand");
293  testSerializationDerivedClass<Command, ReplaceJointCommand>(object, "ReplaceJointCommand");
294 }
295 
296 TEST(EnvironmentCommandsSerializeUnit, SetActiveContinuousContactManagerCommand) // NOLINT
297 {
298  auto object = std::make_shared<SetActiveContinuousContactManagerCommand>("my contact manager");
299  testSerialization<SetActiveContinuousContactManagerCommand>(*object, "SetActiveContinuousContactManagerCommand");
300  testSerializationDerivedClass<Command, SetActiveContinuousContactManagerCommand>(object,
301  "SetActiveContinuousContactManagerCo"
302  "mmand");
303 }
304 
305 TEST(EnvironmentCommandsSerializeUnit, SetActiveDiscreteContactManagerCommand) // NOLINT
306 {
307  auto object = std::make_shared<SetActiveDiscreteContactManagerCommand>("my contact manager 2");
308  testSerialization<SetActiveDiscreteContactManagerCommand>(*object, "SetActiveDiscreteContactManagerCommand");
309  testSerializationDerivedClass<Command, SetActiveDiscreteContactManagerCommand>(object,
310  "SetActiveDiscreteContactManagerComman"
311  "d");
312 }
313 
314 int main(int argc, char** argv)
315 {
316  testing::InitGoogleTest(&argc, argv);
317 
318  return RUN_ALL_TESTS();
319 }
tesseract_environment::RemoveAllowedCollisionLinkCommand
Definition: remove_allowed_collision_link_command.h:45
getSRDFModel
SRDFModel::Ptr getSRDFModel(const SceneGraph &scene_graph, const tesseract_common::ResourceLocator &locator)
Definition: tesseract_environment_serialization_unit.cpp:59
graph.h
tesseract_environment::AddContactManagersPluginInfoCommand
Definition: add_contact_managers_plugin_info_command.h:45
tesseract_srdf::SRDFModel::Ptr
std::shared_ptr< SRDFModel > Ptr
tesseract_srdf
tesseract_environment
Definition: command.h:45
tesseract_common
tesseract_common::JointTrajectory::push_back
void push_back(const value_type &&x)
tesseract_environment::RemoveJointCommand
Definition: remove_joint_command.h:45
tesseract_environment::ModifyAllowedCollisionsCommand
Definition: modify_allowed_collisions_command.h:52
tesseract_environment::ChangeLinkCollisionEnabledCommand
Definition: change_link_collision_enabled_command.h:45
tesseract_environment::RemoveLinkCommand
Definition: remove_link_command.h:45
utils.h
tesseract_environment::SetActiveContinuousContactManagerCommand
Definition: set_active_continuous_contact_manager_command.h:45
tesseract_environment::Environment::Ptr
std::shared_ptr< Environment > Ptr
Definition: environment.h:78
tesseract_common::CollisionMarginPairOverrideType::MODIFY
@ MODIFY
resource_locator.h
tesseract_common::ResourceLocator::locateResource
virtual std::shared_ptr< Resource > locateResource(const std::string &url) const=0
joint.h
tesseract_scene_graph::Joint::parent_to_joint_origin_transform
Eigen::Isometry3d parent_to_joint_origin_transform
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_scene_graph::SceneGraph
tesseract_environment::AddTrajectoryLinkCommand
Definition: add_trajectory_link_command.h:45
getSceneGraph
SceneGraph::Ptr getSceneGraph(const tesseract_common::ResourceLocator &locator)
Definition: tesseract_environment_serialization_unit.cpp:53
getEnvironment
Environment::Ptr getEnvironment()
Definition: tesseract_environment_serialization_unit.cpp:69
tesseract_common::CollisionMarginPairData::setCollisionMargin
void setCollisionMargin(const std::string &obj1, const std::string &obj2, double margin)
urdf_parser.h
tesseract_environment::MoveJointCommand
Definition: move_joint_command.h:45
tesseract_common::JointState
tesseract_environment::ChangeJointOriginCommand
Definition: change_joint_origin_command.h:46
tesseract_urdf::parseURDFFile
std::unique_ptr< tesseract_scene_graph::SceneGraph > parseURDFFile(const std::string &path, const tesseract_common::ResourceLocator &locator)
tesseract_common::AnyPoly
tesseract_scene_graph::Joint::child_link_name
std::string child_link_name
tesseract_environment::ChangeCollisionMarginsCommand
Definition: change_collision_margins_command.h:49
TEST
TEST(EnvironmentSerializeUnit, Environment)
Definition: tesseract_environment_serialization_unit.cpp:80
serialization.h
tesseract_common::JointTrajectory
tesseract_common::ContactManagersPluginInfo
tesseract_environment::ReplaceJointCommand
Definition: replace_joint_command.h:44
tesseract_common::ResourceLocator
tesseract_environment::AddKinematicsInformationCommand
Definition: add_kinematics_information_command.h:45
tesseract_srdf::KinematicsInformation
tesseract_environment::Environment
Definition: environment.h:71
tesseract_environment::AddSceneGraphCommand
Definition: add_scene_graph_command.h:46
TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_environment::AddLinkCommand
Definition: add_link_command.h:45
tesseract_environment::ChangeJointAccelerationLimitsCommand
Definition: change_joint_acceleration_limits_command.h:46
tesseract_environment::ChangeLinkOriginCommand
Definition: change_link_origin_command.h:45
tesseract_scene_graph::Joint
tesseract_common::CollisionMarginPairData
tesseract_environment::ChangeJointVelocityLimitsCommand
Definition: change_joint_velocity_limits_command.h:46
srdf_model.h
tesseract_common::AllowedCollisionMatrix
M_PI
#define M_PI
tesseract_environment::MoveLinkCommand
Definition: move_link_command.h:45
environment.h
tesseract_common::GeneralResourceLocator
tesseract_common::AllowedCollisionMatrix::addAllowedCollision
virtual void addAllowedCollision(const std::string &link_name1, const std::string &link_name2, const std::string &reason)
tesseract_scene_graph::Joint::type
JointType type
unit_test_utils.h
commands.h
This contains classes for recording operations applied to the environment for tracking changes....
macros.h
tesseract_scene_graph::SceneGraph::Ptr
std::shared_ptr< SceneGraph > Ptr
tesseract_scene_graph
tesseract_environment::SetActiveDiscreteContactManagerCommand
Definition: set_active_discrete_contact_manager_command.h:45
tesseract_scene_graph::Joint::parent_link_name
std::string parent_link_name
tesseract_environment::ChangeLinkVisibilityCommand
Definition: change_link_visibility_command.h:45
tesseract_environment::ChangeJointPositionLimitsCommand
Definition: change_joint_position_limits_command.h:46
main
int main(int argc, char **argv)
Definition: tesseract_environment_serialization_unit.cpp:314


tesseract_environment
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:21