8#include <yaml-cpp/yaml.h>
10#include <ros/package.h>
11#include <experimental/filesystem>
16 :
CbMoveJoints(loadJointStatesFromFile(pkg, config_path))
26#define HAVE_NEW_YAMLCPP
29 auto pkgpath = ros::package::getPath(pkg);
30 std::map<std::string, double> jointStates;
34 ROS_ERROR_STREAM(
"[CbMoveKnownState] package not found for the known poses file: " << pkg << std::endl <<
" [IGNORING BEHAVIOR]");
38 filepath = pkgpath +
"/" + filepath;
41 ROS_INFO(
"[CbMoveKnownState] Opening file with joint known state: %s", filepath.c_str());
44 if(std::experimental::filesystem::exists(filepath))
46 ROS_INFO_STREAM(
"[CbMoveKnownState] known state file exists: " << filepath);
50 ROS_ERROR_STREAM(
"[CbMoveKnownState] known state file does not exists: " << filepath);
53 std::ifstream ifs(filepath.c_str(), std::ifstream::in);
54 if (ifs.good() ==
false)
56 ROS_ERROR(
"[CbMoveKnownState] Error opening file with joint known states: %s", filepath.c_str());
57 throw std::string(
"joint state files not found");
62#ifdef HAVE_NEW_YAMLCPP
63 YAML::Node node = YAML::Load(ifs);
65 YAML::Parser parser(ifs);
66 parser.GetNextDocument(node);
69#ifdef HAVE_NEW_YAMLCPP
70 const YAML::Node &wp_node_tmp = node[
"joint_states"];
71 const YAML::Node *wp_node = wp_node_tmp ? &wp_node_tmp : NULL;
73 const YAML::Node *wp_node = node.FindValue(
"waypoints");
80 for(YAML::const_iterator it=wp_node->begin();it != wp_node->end();++it)
82 std::string key = it->first.as<std::string>();
83 double value = it->second.as<
double>();
84 ROS_DEBUG_STREAM(
" joint - " << key <<
": " << value);
85 jointStates[key] = value;
90 catch(std::exception& ex)
92 ROS_ERROR(
"trying to convert to map, failed, errormsg: %s", ex.what());
95 ROS_INFO_STREAM(
"Parsed " << jointStates.size() <<
" joint entries.");
99 ROS_WARN_STREAM(
"Couldn't find any jointStates in the provided yaml file.");
102 catch (
const YAML::ParserException &ex)
104 ROS_ERROR_STREAM(
"Error loading the Waypoints YAML file. Incorrect syntax: " << ex.what());
static std::map< std::string, double > loadJointStatesFromFile(std::string pkg, std::string filepath)
virtual ~CbMoveKnownState()
CbMoveKnownState(std::string pkg, std::string config_path)