configs.cpp
Go to the documentation of this file.
1 
29 #include <tinyxml2.h>
31 
34 #include <tesseract_common/utils.h>
37 #include <tesseract_srdf/configs.h>
38 
39 namespace tesseract_srdf
40 {
41 std::filesystem::path parseConfigFilePath(const tesseract_common::ResourceLocator& locator,
42  const tinyxml2::XMLElement* xml_element,
43  const std::array<int, 3>& /*version*/)
44 {
45  std::string filename;
46  int status = tesseract_common::QueryStringAttributeRequired(xml_element, "filename", filename);
47  if (status != tinyxml2::XML_SUCCESS)
48  std::throw_with_nested(std::runtime_error(std::string(xml_element->Value()) + ": Missing or failed to parse "
49  "'filename' attribute."));
50 
51  tesseract_common::Resource::Ptr resource = locator.locateResource(filename);
52  if (resource == nullptr)
53  std::throw_with_nested(
54  std::runtime_error(std::string(xml_element->Value()) + ": Failed to locate resource '" + filename + "'."));
55 
56  std::filesystem::path file_path(resource->getFilePath());
57  if (!std::filesystem::exists(file_path))
58  std::throw_with_nested(std::runtime_error(std::string(xml_element->Value()) +
59  ": config file does not exist: "
60  "'" +
61  file_path.string() + "'."));
62  return file_path;
63 }
64 
66  const tesseract_common::ResourceLocator& locator,
67  const tinyxml2::XMLElement* xml_element,
68  const std::array<int, 3>& version)
69 {
70  std::filesystem::path cal_config_file_path = parseConfigFilePath(locator, xml_element, version);
71  YAML::Node config;
72  try
73  {
74  config = tesseract_common::processYamlIncludeDirective(YAML::LoadFile(cal_config_file_path.string()), locator);
75  }
76  // LCOV_EXCL_START
77  catch (...)
78  {
79  std::throw_with_nested(std::runtime_error("calibration_config: YAML failed to parse calibration config "
80  "file '" +
81  cal_config_file_path.string() + "'."));
82  }
83  // LCOV_EXCL_STOP
84 
85  const YAML::Node& cal_info = config[tesseract_common::CalibrationInfo::CONFIG_KEY];
86  auto info = cal_info.as<tesseract_common::CalibrationInfo>();
87 
88  // Check to make sure calibration joints exist
89  for (const auto& cal_joint : info.joints)
90  {
91  if (scene_graph.getJoint(cal_joint.first) == nullptr)
92  std::throw_with_nested(std::runtime_error("calibration_config: joint '" + cal_joint.first + "' does not exist!"));
93  }
94 
95  return info;
96 }
97 
99  const tinyxml2::XMLElement* xml_element,
100  const std::array<int, 3>& version)
101 {
102  std::filesystem::path kin_plugin_file_path = parseConfigFilePath(locator, xml_element, version);
103  YAML::Node config;
104  try
105  {
106  config = tesseract_common::processYamlIncludeDirective(YAML::LoadFile(kin_plugin_file_path.string()), locator);
107  }
108  // LCOV_EXCL_START
109  catch (...)
110  {
111  std::throw_with_nested(std::runtime_error("kinematics_plugin_config: YAML failed to parse kinematics plugins "
112  "file '" +
113  kin_plugin_file_path.string() + "'."));
114  }
115  // LCOV_EXCL_STOP
116 
117  const YAML::Node& kin_plugin_info = config[tesseract_common::KinematicsPluginInfo::CONFIG_KEY];
118 
119  return kin_plugin_info.as<tesseract_common::KinematicsPluginInfo>();
120 }
121 
124  const tinyxml2::XMLElement* xml_element,
125  const std::array<int, 3>& version)
126 {
127  std::filesystem::path cm_plugin_file_path = parseConfigFilePath(locator, xml_element, version);
128  YAML::Node config;
129  try
130  {
131  config = tesseract_common::processYamlIncludeDirective(YAML::LoadFile(cm_plugin_file_path.string()), locator);
132  }
133  // LCOV_EXCL_START
134  catch (...)
135  {
136  std::throw_with_nested(std::runtime_error("contact_managers_plugin_config: YAML failed to parse contact "
137  "managers plugins "
138  "file '" +
139  cm_plugin_file_path.string() + "'."));
140  }
141  // LCOV_EXCL_STOP
142 
143  const YAML::Node& cm_plugin_info = config[tesseract_common::ContactManagersPluginInfo::CONFIG_KEY];
144  return cm_plugin_info.as<tesseract_common::ContactManagersPluginInfo>();
145 }
146 } // namespace tesseract_srdf
tesseract_common::CalibrationInfo::CONFIG_KEY
static const std::string CONFIG_KEY
tesseract_common::processYamlIncludeDirective
YAML::Node processYamlIncludeDirective(const YAML::Node &node, const ResourceLocator &locator)
yaml_extenstions.h
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)
tesseract_srdf::parseContactManagersPluginConfig
tesseract_common::ContactManagersPluginInfo parseContactManagersPluginConfig(const tesseract_common::ResourceLocator &locator, const tinyxml2::XMLElement *xml_element, const std::array< int, 3 > &version)
Parse contact managers plugin config xml element.
Definition: configs.cpp:123
utils.h
resource_locator.h
tesseract_srdf::parseConfigFilePath
std::filesystem::path parseConfigFilePath(const tesseract_common::ResourceLocator &locator, const tinyxml2::XMLElement *xml_element, const std::array< int, 3 > &version)
Parse a config xml element.
Definition: configs.cpp:41
tesseract_common::ResourceLocator::locateResource
virtual std::shared_ptr< Resource > locateResource(const std::string &url) const=0
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_scene_graph::SceneGraph
configs.h
tesseract_common::CalibrationInfo
tesseract_srdf::parseKinematicsPluginConfig
tesseract_common::KinematicsPluginInfo parseKinematicsPluginConfig(const tesseract_common::ResourceLocator &locator, const tinyxml2::XMLElement *xml_element, const std::array< int, 3 > &version)
Parse kinematics plugin config xml element.
Definition: configs.cpp:98
tesseract_common::ContactManagersPluginInfo
tesseract_common::ResourceLocator
tesseract_common::KinematicsPluginInfo
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_scene_graph::SceneGraph::getJoint
std::shared_ptr< const Joint > getJoint(const std::string &name) const
tesseract_common::Resource::Ptr
std::shared_ptr< Resource > Ptr
yaml_utils.h
tesseract_common::ContactManagersPluginInfo::CONFIG_KEY
static const std::string CONFIG_KEY
tesseract_srdf::parseCalibrationConfig
tesseract_common::CalibrationInfo parseCalibrationConfig(const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_common::ResourceLocator &locator, const tinyxml2::XMLElement *xml_element, const std::array< int, 3 > &version)
Parse calibration config xml element.
Definition: configs.cpp:65
macros.h
tesseract_common::KinematicsPluginInfo::CONFIG_KEY
static const std::string CONFIG_KEY


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