31 #include <console_bridge/console.h>
43 auto s = std::make_shared<tesseract_scene_graph::JointSafety>();
44 if (xml_element->QueryDoubleAttribute(
"k_velocity", &(s->k_velocity)) != tinyxml2::XML_SUCCESS)
45 std::throw_with_nested(std::runtime_error(
"SafetyController: Missing or failed to parse attribute 'k_velocity'!"));
47 if (xml_element->Attribute(
"soft_upper_limit") ==
nullptr && xml_element->Attribute(
"soft_lower_limit") ==
nullptr &&
48 xml_element->Attribute(
"k_position") ==
nullptr)
50 CONSOLE_BRIDGE_logDebug(
"SafetyController: Missing attributes 'soft_upper_limit', 'soft_lower_limit', and "
51 "'k_position', using default value 0, 0, and 0!");
53 else if (xml_element->Attribute(
"soft_upper_limit") ==
nullptr ||
54 xml_element->Attribute(
"soft_lower_limit") ==
nullptr || xml_element->Attribute(
"k_position") ==
nullptr)
56 if (xml_element->Attribute(
"soft_upper_limit") ==
nullptr)
57 CONSOLE_BRIDGE_logDebug(
"SafetyController: Missing attribute 'soft_upper_limit', using default value 0!");
59 if (xml_element->Attribute(
"soft_lower_limit") ==
nullptr)
60 CONSOLE_BRIDGE_logDebug(
"SafetyController: Missing attribute 'soft_lower_limit', using default value 0!");
62 if (xml_element->Attribute(
"k_position") ==
nullptr)
63 CONSOLE_BRIDGE_logDebug(
"SafetyController: Missing attribute 'k_position', using default value 0!");
66 s->soft_upper_limit = 0;
67 s->soft_lower_limit = 0;
69 xml_element->QueryDoubleAttribute(
"soft_upper_limit", &s->soft_upper_limit);
70 xml_element->QueryDoubleAttribute(
"soft_lower_limit", &s->soft_lower_limit);
71 xml_element->QueryDoubleAttribute(
"k_position", &s->k_position);
76 tinyxml2::XMLElement*
writeSafetyController(
const std::shared_ptr<const tesseract_scene_graph::JointSafety>& safety,
77 tinyxml2::XMLDocument& doc)
79 if (safety ==
nullptr)
80 std::throw_with_nested(std::runtime_error(
"Safety Controller is nullptr and cannot be converted to XML"));
83 xml_element->SetAttribute(
"k_velocity",
toString(safety->k_velocity).c_str());
86 xml_element->SetAttribute(
"soft_upper_limit",
toString(safety->soft_upper_limit).c_str());
87 xml_element->SetAttribute(
"soft_lower_limit",
toString(safety->soft_lower_limit).c_str());
88 xml_element->SetAttribute(
"k_position",
toString(safety->k_position).c_str());