collision_margins.cpp
Go to the documentation of this file.
1 
29 #include <console_bridge/console.h>
30 #include <tinyxml2.h>
32 
35 #include <tesseract_common/types.h>
36 #include <tesseract_common/utils.h>
38 
39 namespace tesseract_srdf
40 {
42  const tinyxml2::XMLElement* srdf_xml,
43  const std::array<int, 3>& /*version*/)
44 {
45  double default_margin{ 0 };
46  const tinyxml2::XMLElement* xml_element = srdf_xml->FirstChildElement("collision_margins");
47  if (xml_element == nullptr)
48  return nullptr;
49 
50  int status = tesseract_common::QueryDoubleAttributeRequired(xml_element, "default_margin", default_margin);
51  if (status != tinyxml2::XML_SUCCESS)
52  std::throw_with_nested(std::runtime_error("CollisionMargins: collision_margins missing attribute "
53  "'default_margin'."));
54 
55  auto margin_data = std::make_shared<tesseract_common::CollisionMarginData>(default_margin);
56  for (const tinyxml2::XMLElement* xml_pair_element = xml_element->FirstChildElement("pair_margin");
57  xml_pair_element != nullptr;
58  xml_pair_element = xml_pair_element->NextSiblingElement("pair_margin"))
59  {
60  std::string link1_name, link2_name;
61  double link_pair_margin{ 0 };
62  int status = tesseract_common::QueryStringAttributeRequired(xml_pair_element, "link1", link1_name);
63  if (status != tinyxml2::XML_SUCCESS)
64  std::throw_with_nested(std::runtime_error("parseCollisionMargins: Missing or failed to parse 'link1' "
65  "attribute."));
66 
67  status = tesseract_common::QueryStringAttributeRequired(xml_pair_element, "link2", link2_name);
68  if (status != tinyxml2::XML_SUCCESS)
69  std::throw_with_nested(std::runtime_error("CollisionMargins: Missing or failed to parse 'link2' attribute."));
70 
71  if (!scene_graph.getLink(link1_name))
72  {
73  CONSOLE_BRIDGE_logWarn("parseCollisionMargins: Link '%s' is not known to URDF.", link1_name.c_str());
74  }
75 
76  if (!scene_graph.getLink(link2_name))
77  {
78  CONSOLE_BRIDGE_logWarn("parseCollisionMargins: Link '%s' is not known to URDF.", link2_name.c_str());
79  }
80 
81  status = tesseract_common::QueryDoubleAttributeRequired(xml_pair_element, "margin", link_pair_margin);
82  if (status != tinyxml2::XML_SUCCESS)
83  std::throw_with_nested(std::runtime_error("parseCollisionMargins: failed to parse link pair 'margin' "
84  "attribute."));
85 
86  margin_data->setCollisionMargin(link1_name, link2_name, link_pair_margin);
87  }
88 
89  return margin_data;
90 }
91 } // namespace tesseract_srdf
graph.h
tesseract_srdf
Main namespace.
Definition: collision_margins.h:43
tesseract_common::QueryStringAttributeRequired
int QueryStringAttributeRequired(const tinyxml2::XMLElement *xml_element, const char *name, std::string &value)
utils.h
collision_margin_data.h
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_scene_graph::SceneGraph
tesseract_common::CollisionMarginData::Ptr
std::shared_ptr< CollisionMarginData > Ptr
tesseract_srdf::parseCollisionMargins
std::shared_ptr< tesseract_common::CollisionMarginData > parseCollisionMargins(const tesseract_scene_graph::SceneGraph &scene_graph, const tinyxml2::XMLElement *srdf_xml, const std::array< int, 3 > &version)
Parse allowed collisions from srdf xml element.
Definition: collision_margins.cpp:41
tesseract_common::QueryDoubleAttributeRequired
int QueryDoubleAttributeRequired(const tinyxml2::XMLElement *xml_element, const char *name, double &value)
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_scene_graph::SceneGraph::getLink
std::shared_ptr< const Link > getLink(const std::string &name) const
types.h
collision_margins.h
Parse collision margin data from srdf file.
macros.h


tesseract_srdf
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:04