1 #include <yocs_msgs/Trajectory.h> 2 #include <yocs_msgs/Waypoint.h> 8 yocs_msgs::WaypointList& wps,
9 yocs_msgs::TrajectoryList& trajs)
11 wps.waypoints.clear();
12 trajs.trajectories.clear();
23 catch(YAML::ParserException& e)
25 ROS_ERROR(
"Parsing waypoints file failed: %s", e.what());
28 catch(YAML::RepresentationException& e)
30 ROS_ERROR(
"Parsing waypoints file failed: %s", e.what());
33 catch(std::string& e) {
34 ROS_ERROR(
"Parsing waypoints file failed: %s",e.c_str());
40 void getYamlNode(
const std::string& filename, YAML::Node& node)
42 std::ifstream ifs(filename.c_str(), std::ifstream::in);
43 if (ifs.good() ==
false)
45 throw std::string(
"Waypoints file not found");
48 #ifdef HAVE_NEW_YAMLCPP 49 node = YAML::Load(ifs);
51 YAML::Parser parser(ifs);
52 parser.GetNextDocument(node);
58 #ifdef HAVE_NEW_YAMLCPP 59 const YAML::Node& wp_node_tmp = node[
"waypoints"];
60 const YAML::Node* wp_node = wp_node_tmp ? &wp_node_tmp : NULL;
62 const YAML::Node* wp_node = node.FindValue(
"waypoints");
67 for(
unsigned int i = 0; i < wp_node->size(); ++i)
70 yocs_msgs::Waypoint wp;
72 (*wp_node)[i][
"name"] >> wp.name;
73 (*wp_node)[i][
"frame_id"] >> wp.header.frame_id;
74 (*wp_node)[i][
"pose"][
"position"][
"x"] >> wp.pose.position.x;
75 (*wp_node)[i][
"pose"][
"position"][
"y"] >> wp.pose.position.y;
76 (*wp_node)[i][
"pose"][
"position"][
"z"] >> wp.pose.position.z;
77 (*wp_node)[i][
"pose"][
"orientation"][
"x"] >> wp.pose.orientation.x;
78 (*wp_node)[i][
"pose"][
"orientation"][
"y"] >> wp.pose.orientation.y;
79 (*wp_node)[i][
"pose"][
"orientation"][
"z"] >> wp.pose.orientation.z;
80 (*wp_node)[i][
"pose"][
"orientation"][
"w"] >> wp.pose.orientation.w;
82 wps.waypoints.push_back(wp);
88 ROS_WARN_STREAM(
"Couldn't find any waypoints in the provided yaml file.");
93 const yocs_msgs::WaypointList& wps,
94 yocs_msgs::TrajectoryList& trajs)
98 #ifdef HAVE_NEW_YAMLCPP 99 const YAML::Node& wp_node_tmp = node[
"trajectories"];
100 const YAML::Node* wp_node = wp_node_tmp ? &wp_node_tmp : NULL;
102 const YAML::Node* wp_node = node.FindValue(
"trajectories");
106 for(i = 0; i < wp_node->size(); ++i)
109 yocs_msgs::Trajectory traj;
112 bool all_waypoints_found =
true;
114 for(
unsigned int wp = 0; wp < (*wp_node)[i][
"waypoints"].size(); ++wp)
116 bool wp_found =
false;
118 (*wp_node)[i][
"waypoints"][wp] >> wp_name;
119 for(
unsigned int known_wp = 0; known_wp < wps.waypoints.size(); ++known_wp)
121 if (wp_name == wps.waypoints[known_wp].name)
123 traj.waypoints.push_back(wps.waypoints[known_wp]);
130 all_waypoints_found =
false;
134 if (all_waypoints_found)
136 (*wp_node)[i][
"name"] >> traj.name;
137 trajs.trajectories.push_back(traj);
140 ROS_INFO_STREAM(
"Parsed " << trajs.trajectories.size() <<
" trajectories.");
144 ROS_WARN_STREAM(
"Couldn't find any trajectories in the provided yaml file.");
bool loadWaypointsAndTrajectoriesFromYaml(const std::string &filename, yocs_msgs::WaypointList &wps, yocs_msgs::TrajectoryList &trajs)
void getYamlNode(const std::string &filename, YAML::Node &node)
#define ROS_WARN_STREAM(args)
#define ROS_INFO_STREAM(args)
void parseTrajectories(const YAML::Node &node, const yocs_msgs::WaypointList &wps, yocs_msgs::TrajectoryList &trajs)
void parseWaypoints(const YAML::Node &node, yocs_msgs::WaypointList &wps)