yaml.cpp
Go to the documentation of this file.
1 /*
2  AR marker yaml parser
3 
4  LICENSE : BSD - https://raw.github.com/yujinrobot/yujin_ocs/license/LICENSE
5 
6  Author : Jihoon Lee
7  Date : Dec 2013
8  */
9 
11 
12 namespace yocs {
13 
14  bool loadAlvarMarkersFromYaml(const std::string& filename,ar_track_alvar_msgs::AlvarMarkers& ams)
15  {
16 
17  ams.markers.clear();
18 
19  // Yaml File Parsing
20  try
21  {
22  YAML::Node doc;
23 
24  getYamlNode(filename, doc);
25  parseMarkers(doc, ams);
26  }
27  catch(YAML::ParserException& e)
28  {
29  ROS_ERROR("Parse AR markers file failed: %s", e.what());
30  return false;
31  }
32  catch(YAML::RepresentationException& e)
33  {
34  ROS_ERROR("Parse AR Markers file failed: %s", e.what());
35  return false;
36  }
37  catch(std::string& e) {
38  ROS_ERROR("Parse AR Markers file failed: %s",e.c_str());
39  return false;
40  }
41  return true;
42  }
43 
44  void getYamlNode(const std::string& filename, YAML::Node& node)
45  {
46  std::ifstream ifs(filename.c_str(), std::ifstream::in);
47  if (ifs.good() == false)
48  {
49  throw std::string("file not found");
50  }
51 
52  #ifdef HAVE_NEW_YAMLCPP
53  node = YAML::Load(ifs);
54  #else
55  YAML::Parser parser(ifs);
56  parser.GetNextDocument(node);
57  #endif
58  }
59 
60  void parseMarkers(const YAML::Node& node, ar_track_alvar_msgs::AlvarMarkers& ams)
61  {
62  unsigned int i;
63 
64  for(i = 0; i < node.size(); i++)
65  {
66  // Parse AlvarMarker entries on YAML
67  ar_track_alvar_msgs::AlvarMarker m;
68 
69  node[i]["id"] >> m.id;
70  node[i]["frame_id"] >> m.header.frame_id;
71  node[i]["frame_id"] >> m.pose.header.frame_id;
72  node[i]["confidence"] >> m.confidence;
73  node[i]["pose"]["position"]["x"] >> m.pose.pose.position.x;
74  node[i]["pose"]["position"]["y"] >> m.pose.pose.position.y;
75  node[i]["pose"]["position"]["z"] >> m.pose.pose.position.z;
76  node[i]["pose"]["orientation"]["x"] >> m.pose.pose.orientation.x;
77  node[i]["pose"]["orientation"]["y"] >> m.pose.pose.orientation.y;
78  node[i]["pose"]["orientation"]["z"] >> m.pose.pose.orientation.z;
79  node[i]["pose"]["orientation"]["w"] >> m.pose.pose.orientation.w;
80 
81  ams.markers.push_back(m);
82  }
83  }
84 }
void getYamlNode(const std::string &filename, YAML::Node &node)
Definition: yaml.cpp:44
void parseMarkers(const YAML::Node &node, ar_track_alvar_msgs::AlvarMarkers &ams)
Definition: yaml.cpp:60
bool loadAlvarMarkersFromYaml(const std::string &filename, ar_track_alvar_msgs::AlvarMarkers &ams)
Definition: yaml.cpp:14
parser
#define ROS_ERROR(...)


yocs_ar_marker_tracking
Author(s): Daniel Stonier, Jorge Santos
autogenerated on Mon Jun 10 2019 15:53:43