53 std::string pkgpath = ament_index_cpp::get_package_share_directory(pkg);
55 std::map<std::string, double> jointStates;
60 getLogger(),
"[" <<
getName() <<
"] package not found for the known poses file: " << pkg
62 <<
" [IGNORING BEHAVIOR]");
66 filepath = pkgpath +
"/" + filepath;
69 getLogger(),
"[" <<
getName() <<
"] Opening file with joint known state: " << filepath);
71 if (std::filesystem::exists(filepath))
79 getLogger(),
"[" <<
getName() <<
"] known state file does not exists: " << filepath);
82 std::ifstream ifs(filepath.c_str(), std::ifstream::in);
83 if (ifs.good() ==
false)
87 "[" <<
getName() <<
"] Error opening file with joint known states: " << filepath);
88 throw std::string(
"joint state files not found");
93#ifdef HAVE_NEW_YAMLCPP
94 YAML::Node node = YAML::Load(ifs);
96 YAML::Parser parser(ifs);
97 parser.GetNextDocument(node);
100#ifdef HAVE_NEW_YAMLCPP
101 const YAML::Node & wp_node_tmp = node[
"joint_states"];
102 const YAML::Node * wp_node = wp_node_tmp ? &wp_node_tmp : NULL;
104 const YAML::Node * wp_node = node.FindValue(
"waypoints");
111 for (YAML::const_iterator it = wp_node->begin(); it != wp_node->end(); ++it)
113 std::string key = it->first.as<std::string>();
114 double value = it->second.as<
double>();
115 RCLCPP_DEBUG_STREAM(
getLogger(),
" joint - " << key <<
": " << value);
116 jointStates[key] = value;
121 catch (std::exception & ex)
123 RCLCPP_ERROR(
getLogger(),
"trying to convert to map, failed, errormsg: %s", ex.what());
126 RCLCPP_INFO_STREAM(
getLogger(),
"Parsed " << jointStates.size() <<
" joint entries.");
130 RCLCPP_WARN_STREAM(
getLogger(),
"Couldn't find any jointStates in the provided yaml file.");
133 catch (
const YAML::ParserException & ex)
136 getLogger(),
"Error loading the Waypoints YAML file. Incorrect syntax: " << ex.what());