mimic.cpp
Go to the documentation of this file.
1 
29 #include <stdexcept>
30 
31 #include <console_bridge/console.h>
32 #include <tesseract_common/utils.h>
33 #include <tinyxml2.h>
35 
37 #include <tesseract_urdf/mimic.h>
38 #include <tesseract_urdf/utils.h>
39 
40 namespace tesseract_urdf
41 {
42 tesseract_scene_graph::JointMimic::Ptr parseMimic(const tinyxml2::XMLElement* xml_element)
43 {
44  auto m = std::make_shared<tesseract_scene_graph::JointMimic>();
45  if (tesseract_common::QueryStringAttribute(xml_element, "joint", m->joint_name) != tinyxml2::XML_SUCCESS)
46  std::throw_with_nested(std::runtime_error("Mimic: Missing or failed to parse mimic attribute 'joint'!"));
47 
48  if (xml_element->Attribute("offset") == nullptr && xml_element->Attribute("multiplier") == nullptr)
49  CONSOLE_BRIDGE_logDebug("Mimic: Missing attribute 'offset' and 'multiplier', using default value 0 and 1!");
50  else if (xml_element->Attribute("offset") != nullptr && xml_element->Attribute("multiplier") == nullptr)
51  CONSOLE_BRIDGE_logDebug("Mimic: Missing attribute 'multiplier', using default value 1!");
52  else if (xml_element->Attribute("offset") == nullptr && xml_element->Attribute("multiplier") != nullptr)
53  CONSOLE_BRIDGE_logDebug("Mimic: Missing attribute 'offset', using default value 1!");
54 
55  int s = xml_element->QueryDoubleAttribute("offset", &(m->offset));
56  if (s != tinyxml2::XML_NO_ATTRIBUTE && s != tinyxml2::XML_SUCCESS)
57  std::throw_with_nested(std::runtime_error("Mimic: Error parsing attribute 'offset'!"));
58 
59  s = xml_element->QueryDoubleAttribute("multiplier", &(m->multiplier));
60  if (s != tinyxml2::XML_NO_ATTRIBUTE && s != tinyxml2::XML_SUCCESS)
61  std::throw_with_nested(std::runtime_error("Mimic: Error parsing attribute 'multiplier'!"));
62 
63  return m;
64 }
65 
66 tinyxml2::XMLElement* writeMimic(const std::shared_ptr<const tesseract_scene_graph::JointMimic>& mimic,
67  tinyxml2::XMLDocument& doc)
68 {
69  if (mimic == nullptr)
70  std::throw_with_nested(std::runtime_error("Mimic Joint is nullptr and cannot be converted to XML"));
71  tinyxml2::XMLElement* xml_element = doc.NewElement(MIMIC_ELEMENT_NAME.data());
72 
73  xml_element->SetAttribute("joint", mimic->joint_name.c_str());
74  xml_element->SetAttribute("offset", toString(mimic->offset).c_str());
75  xml_element->SetAttribute("multiplier", toString(mimic->multiplier).c_str());
76 
77  return xml_element;
78 }
79 
80 } // namespace tesseract_urdf
utils.h
joint.h
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
utils.h
tesseract_scene_graph::JointMimic::Ptr
std::shared_ptr< JointMimic > Ptr
tesseract_urdf::parseMimic
std::shared_ptr< tesseract_scene_graph::JointMimic > parseMimic(const tinyxml2::XMLElement *xml_element)
Parse xml element mimic.
Definition: mimic.cpp:42
tesseract_common::QueryStringAttribute
int QueryStringAttribute(const tinyxml2::XMLElement *xml_element, const char *name, std::string &value)
TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_urdf::toString
std::string toString(const double &float_value, int precision=3)
Definition: utils.cpp:12
tesseract_urdf::MIMIC_ELEMENT_NAME
static constexpr std::string_view MIMIC_ELEMENT_NAME
Definition: mimic.h:45
tesseract_urdf::writeMimic
tinyxml2::XMLElement * writeMimic(const std::shared_ptr< const tesseract_scene_graph::JointMimic > &mimic, tinyxml2::XMLDocument &doc)
Definition: mimic.cpp:66
macros.h
tesseract_urdf
Definition: box.h:43
mimic.h
Parse mimic from xml string.


tesseract_urdf
Author(s): Levi Armstrong
autogenerated on Thu Apr 24 2025 03:10:44