44 std::string pkg, std::string filepath)
47 std::string pkgpath = ament_index_cpp::get_package_share_directory(pkg);
49 std::map<std::string, double> jointStates;
54 getLogger(),
"[" <<
getName() <<
"] package not found for the known poses file: " << pkg
56 <<
" [IGNORING BEHAVIOR]");
60 filepath = pkgpath +
"/" + filepath;
63 getLogger(),
"[" <<
getName() <<
"] Opening file with joint known state: " << filepath);
65 if (std::filesystem::exists(filepath))
67 RCLCPP_INFO_STREAM(
getLogger(),
"[" <<
getName() <<
"] known state file exists: " << filepath);
72 getLogger(),
"[" <<
getName() <<
"] known state file does not exists: " << filepath);
75 std::ifstream ifs(filepath.c_str(), std::ifstream::in);
76 if (ifs.good() ==
false)
80 "[" <<
getName() <<
"] Error opening file with joint known states: " << filepath);
81 throw std::string(
"joint state files not found");
86#ifdef HAVE_NEW_YAMLCPP
87 YAML::Node node = YAML::Load(ifs);
89 YAML::Parser parser(ifs);
90 parser.GetNextDocument(node);
93#ifdef HAVE_NEW_YAMLCPP
94 const YAML::Node & wp_node_tmp = node[
"joint_states"];
95 const YAML::Node * wp_node = wp_node_tmp ? &wp_node_tmp : NULL;
97 const YAML::Node * wp_node = node.FindValue(
"waypoints");
104 for (YAML::const_iterator it = wp_node->begin(); it != wp_node->end(); ++it)
106 std::string key = it->first.as<std::string>();
107 double value = it->second.as<
double>();
108 RCLCPP_DEBUG_STREAM(
getLogger(),
" joint - " << key <<
": " << value);
109 jointStates[key] = value;
114 catch (std::exception & ex)
116 RCLCPP_ERROR(
getLogger(),
"trying to convert to map, failed, errormsg: %s", ex.what());
119 RCLCPP_INFO_STREAM(
getLogger(),
"Parsed " << jointStates.size() <<
" joint entries.");
123 RCLCPP_WARN_STREAM(
getLogger(),
"Couldn't find any jointStates in the provided yaml file.");
126 catch (
const YAML::ParserException & ex)
129 getLogger(),
"Error loading the Waypoints YAML file. Incorrect syntax: " << ex.what());