43 auto limits = std::make_shared<tesseract_scene_graph::JointLimits>();
45 int status = xml_element->QueryDoubleAttribute(
"lower", &(limits->lower));
46 if (status != tinyxml2::XML_NO_ATTRIBUTE && status != tinyxml2::XML_SUCCESS)
47 std::throw_with_nested(std::runtime_error(
"Limits: Missing or failed to parse attribute 'lower'!"));
49 status = xml_element->QueryDoubleAttribute(
"upper", &(limits->upper));
50 if (status != tinyxml2::XML_NO_ATTRIBUTE && status != tinyxml2::XML_SUCCESS)
51 std::throw_with_nested(std::runtime_error(
"Limits: Missing or failed to parse attribute 'upper'!"));
53 if (xml_element->QueryDoubleAttribute(
"effort", &(limits->effort)) != tinyxml2::XML_SUCCESS)
54 std::throw_with_nested(std::runtime_error(
"Limits: Missing or failed to parse attribute 'effort'!"));
56 if (xml_element->QueryDoubleAttribute(
"velocity", &(limits->velocity)) != tinyxml2::XML_SUCCESS)
57 std::throw_with_nested(std::runtime_error(
"Limits: Missing or failed to parse attribute 'velocity'!"));
59 status = xml_element->QueryDoubleAttribute(
"acceleration", &(limits->acceleration));
60 if (status == tinyxml2::XML_NO_ATTRIBUTE)
61 limits->acceleration = 0.5 * limits->velocity;
62 else if (status != tinyxml2::XML_SUCCESS)
63 std::throw_with_nested(std::runtime_error(
"Limits: Failed to parse attribute 'acceleration'!"));
65 status = xml_element->QueryDoubleAttribute(
"jerk", &(limits->jerk));
66 if (status == tinyxml2::XML_NO_ATTRIBUTE)
68 else if (status != tinyxml2::XML_SUCCESS)
69 std::throw_with_nested(std::runtime_error(
"Limits: Failed to parse attribute 'jerk'!"));
74 tinyxml2::XMLElement*
writeLimits(
const std::shared_ptr<const tesseract_scene_graph::JointLimits>& limits,
75 tinyxml2::XMLDocument& doc)
77 if (limits ==
nullptr)
78 std::throw_with_nested(std::runtime_error(
"Limits are nullptr and cannot be converted to XML"));
85 xml_element->SetAttribute(
"lower",
toString(limits->lower).c_str());
86 xml_element->SetAttribute(
"upper",
toString(limits->upper).c_str());
90 xml_element->SetAttribute(
"effort",
toString(limits->effort).c_str());
91 xml_element->SetAttribute(
"velocity",
toString(limits->velocity).c_str());
96 xml_element->SetAttribute(
"acceleration",
toString(limits->acceleration).c_str());
101 xml_element->SetAttribute(
"jerk",
toString(limits->jerk).c_str());