calibration.cpp
Go to the documentation of this file.
1 
29 #include <stdexcept>
30 
31 #include <console_bridge/console.h>
32 #include <tinyxml2.h>
34 
37 #include <tesseract_urdf/utils.h>
38 
39 namespace tesseract_urdf
40 {
41 tesseract_scene_graph::JointCalibration::Ptr parseCalibration(const tinyxml2::XMLElement* xml_element)
42 {
43  if (xml_element->Attribute("rising") == nullptr && xml_element->Attribute("falling") == nullptr)
44  std::throw_with_nested(std::runtime_error("Calibration: Missing both attribute 'rising' and 'falling', either "
45  "remove tag add attributes and values!"));
46 
47  auto calibration = std::make_shared<tesseract_scene_graph::JointCalibration>();
48  if (xml_element->Attribute("rising") == nullptr && xml_element->Attribute("falling") != nullptr)
49  CONSOLE_BRIDGE_logDebug("Calibration: Missing attribute 'rising', using default value 0!");
50 
51  if (xml_element->Attribute("rising") != nullptr && xml_element->Attribute("falling") == nullptr)
52  CONSOLE_BRIDGE_logDebug("Calibration: Missing attribute 'falling', using default value 0!");
53 
54  auto xml_status = xml_element->QueryDoubleAttribute("rising", &(calibration->rising));
55  if (xml_status != tinyxml2::XML_NO_ATTRIBUTE && xml_status != tinyxml2::XML_SUCCESS)
56  std::throw_with_nested(std::runtime_error("Calibration: Error parsing attribute 'rising'!"));
57 
58  xml_status = xml_element->QueryDoubleAttribute("falling", &(calibration->falling));
59  if (xml_status != tinyxml2::XML_NO_ATTRIBUTE && xml_status != tinyxml2::XML_SUCCESS)
60  std::throw_with_nested(std::runtime_error("Calibration: Error parsing attribute 'falling'!"));
61 
62  return calibration;
63 }
64 
65 tinyxml2::XMLElement*
66 writeCalibration(const std::shared_ptr<const tesseract_scene_graph::JointCalibration>& calibration,
67  tinyxml2::XMLDocument& doc)
68 {
69  if (calibration == nullptr)
70  std::throw_with_nested(std::runtime_error("Calibration is nullptr and cannot be converted to XML"));
71  tinyxml2::XMLElement* xml_element = doc.NewElement(CALIBRATION_ELEMENT_NAME.data());
72  xml_element->SetAttribute("rising", toString(calibration->rising).c_str());
73  xml_element->SetAttribute("falling", toString(calibration->falling).c_str());
74  return xml_element;
75 }
76 
77 } // namespace tesseract_urdf
tesseract_urdf::CALIBRATION_ELEMENT_NAME
static constexpr std::string_view CALIBRATION_ELEMENT_NAME
Definition: calibration.h:45
joint.h
tesseract_scene_graph::JointCalibration::Ptr
std::shared_ptr< JointCalibration > Ptr
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
utils.h
tesseract_urdf::parseCalibration
std::shared_ptr< tesseract_scene_graph::JointCalibration > parseCalibration(const tinyxml2::XMLElement *xml_element)
Parse a xml calibration element.
Definition: calibration.cpp:41
TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_urdf::toString
std::string toString(const double &float_value, int precision=3)
Definition: utils.cpp:12
macros.h
tesseract_urdf
Definition: box.h:43
calibration.h
Parse calibration from xml string.
tesseract_urdf::writeCalibration
tinyxml2::XMLElement * writeCalibration(const std::shared_ptr< const tesseract_scene_graph::JointCalibration > &calibration, tinyxml2::XMLDocument &doc)
Definition: calibration.cpp:66


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