9#include <yaml-cpp/yaml.h>
10#include <tf/transform_datatypes.h>
15 : currentWaypoint_(0),
40 auto pose = p->toPoseMsg();
42 ClMoveBaseZ::Goal goal;
43 goal.target_pose.header.frame_id = p->getReferenceFrame();
44 goal.target_pose.header.stamp = ros::Time::now();
45 goal.target_pose.pose = next;
51 ros::Duration(5).sleep();
53 if (odomTracker !=
nullptr)
55 odomTracker->pushPath(
"FreeNavigationToGoalWaypointPose");
56 odomTracker->setStartPoint(pose);
65 ROS_WARN(
"[WaypointsNavigator] All waypoints were consumed. There is no more waypoints available.");
85 for (
auto &p : waypoints)
87 geometry_msgs::Pose pose;
88 pose.position.x = p.x_;
89 pose.position.y = p.y_;
90 pose.position.z = 0.0;
91 pose.orientation = tf::createQuaternionMsgFromYaw(p.yaw_);
115#define HAVE_NEW_YAMLCPP
119 std::ifstream ifs(filepath.c_str(), std::ifstream::in);
120 if (ifs.good() ==
false)
122 throw std::string(
"Waypoints file not found");
128#ifdef HAVE_NEW_YAMLCPP
129 YAML::Node node = YAML::Load(ifs);
131 YAML::Parser parser(ifs);
132 parser.GetNextDocument(node);
135#ifdef HAVE_NEW_YAMLCPP
136 const YAML::Node &wp_node_tmp = node[
"waypoints"];
137 const YAML::Node *wp_node = wp_node_tmp ? &wp_node_tmp : NULL;
139 const YAML::Node *wp_node = node.FindValue(
"waypoints");
144 for (uint64_t i = 0; i < wp_node->size(); ++i)
147 geometry_msgs::Pose wp;
153 wp.position.x = (*wp_node)[i][
"position"][
"x"].as<
double>();
154 wp.position.y = (*wp_node)[i][
"position"][
"y"].as<
double>();
155 wp.position.z = (*wp_node)[i][
"position"][
"z"].as<
double>();
156 wp.orientation.x = (*wp_node)[i][
"orientation"][
"x"].as<
double>();
157 wp.orientation.y = (*wp_node)[i][
"orientation"][
"y"].as<
double>();
158 wp.orientation.z = (*wp_node)[i][
"orientation"][
"z"].as<
double>();
159 wp.orientation.w = (*wp_node)[i][
"orientation"][
"w"].as<
double>();
165 ROS_ERROR(
"parsing waypoint file, syntax error in point %ld", i);
168 ROS_INFO_STREAM(
"Parsed " << this->
waypoints_.size() <<
" waypoints.");
172 ROS_WARN_STREAM(
"Couldn't find any waypoints in the provided yaml file.");
175 catch (
const YAML::ParserException &ex)
177 ROS_ERROR_STREAM(
"Error loading the Waypoints YAML file. Incorrect syntax: " << ex.what());
SmaccActionClientBase< move_base_msgs::MoveBaseAction >::ResultConstPtr ResultConstPtr
void setDefaultPlanners()
void postWaypointEvent(int index)
void removeWaypoint(int index)
void loadWayPointsFromFile(std::string filepath)
void setWaypoints(const std::vector< geometry_msgs::Pose > &waypoints)
WaypointEventDispatcher waypointsEventDispatcher
const std::vector< geometry_msgs::Pose > & getWaypoints() const
void insertWaypoint(int index, geometry_msgs::Pose &newpose)
boost::signals2::connection succeddedConnection_
std::vector< geometry_msgs::Pose > waypoints_
long getCurrentWaypointIndex() const
virtual void onInitialize() override
void onGoalReached(ClMoveBaseZ::ResultConstPtr &res)
This class track the required distance of the cord based on the external localization system.
TComponent * getComponent()
void sendGoal(Goal &goal)
boost::signals2::connection onSucceeded(void(T::*callback)(ResultConstPtr &), T *object)