21#include <tf2/transform_datatypes.h>
22#include <yaml-cpp/yaml.h>
32#include <rclcpp/rclcpp.hpp>
36using namespace std::chrono_literals;
60 getLogger(),
"[WaypointNavigator] Goal result received, incrementing waypoint index: %ld",
94 goal.pose.header.frame_id = p->getReferenceFrame();
95 goal.pose.header.stamp =
getNode()->now();
96 goal.pose.pose = next;
98 RCLCPP_WARN(
getLogger(),
"[WaypointsNavigator] Configuring default planners");
102 RCLCPP_WARN(
getLogger(),
"[WaypointsNavigator] Configuring default goal planner");
109 RCLCPP_INFO(
getLogger(),
"[WaypointsNavigator] Getting odom tracker");
111 if (odomTracker !=
nullptr)
113 RCLCPP_INFO(
getLogger(),
"[WaypointsNavigator] Storing path in odom tracker");
117 odomTracker->pushPath(pathname);
118 odomTracker->setStartPoint(pose);
139 "[WaypointsNavigator] All waypoints were consumed. There is no more waypoints available.");
145 if (index >= 0 && index <= (
int)
waypoints_.size())
161 for (
auto & p : waypoints)
163 geometry_msgs::msg::Pose pose;
164 pose.position.x = p.x_;
165 pose.position.y = p.y_;
166 pose.position.z = 0.0;
168 q.setRPY(0, 0, p.yaw_);
169 pose.orientation = tf2::toMsg(q);
178 if (index >= 0 && index < (
int)
waypoints_.size())
191#define HAVE_NEW_YAMLCPP
194 RCLCPP_INFO_STREAM(
getLogger(),
"[WaypointNavigator] Loading file:" << filepath);
196 std::ifstream ifs(filepath.c_str(), std::ifstream::in);
197 if (ifs.good() ==
false)
199 throw std::string(
"Waypoints file not found");
204#ifdef HAVE_NEW_YAMLCPP
205 YAML::Node node = YAML::Load(ifs);
208 parser.GetNextDocument(node);
211#ifdef HAVE_NEW_YAMLCPP
212 const YAML::Node & wp_node_tmp = node[
"waypoints"];
213 const YAML::Node * wp_node = wp_node_tmp ? &wp_node_tmp : NULL;
215 const YAML::Node * wp_node = node.FindValue(
"waypoints");
220 for (
unsigned int i = 0; i < wp_node->size(); ++i)
223 geometry_msgs::msg::Pose wp;
229 wp.position.x = (*wp_node)[i][
"position"][
"x"].as<
double>();
230 wp.position.y = (*wp_node)[i][
"position"][
"y"].as<
double>();
231 wp.position.z = (*wp_node)[i][
"position"][
"z"].as<
double>();
232 wp.orientation.x = (*wp_node)[i][
"orientation"][
"x"].as<
double>();
233 wp.orientation.y = (*wp_node)[i][
"orientation"][
"y"].as<
double>();
234 wp.orientation.z = (*wp_node)[i][
"orientation"][
"z"].as<
double>();
235 wp.orientation.w = (*wp_node)[i][
"orientation"][
"w"].as<
double>();
241 RCLCPP_ERROR(
getLogger(),
"parsing waypoint file, syntax error in point %d", i);
248 RCLCPP_WARN_STREAM(
getLogger(),
"Couldn't find any waypoints in the provided yaml file.");
251 catch (
const YAML::ParserException & ex)
254 getLogger(),
"Error loading the Waypoints YAML file. Incorrect syntax: " << ex.what());
260 RCLCPP_INFO_STREAM(
getLogger(),
"[WaypointNavigator] Loading file:" << filepath);
262 std::ifstream ifs(filepath.c_str(), std::ifstream::in);
263 if (ifs.good() ==
false)
265 throw std::string(
"Waypoints file not found");
270#ifdef HAVE_NEW_YAMLCPP
271 YAML::Node node = YAML::Load(ifs);
274 parser.GetNextDocument(node);
277#ifdef HAVE_NEW_YAMLCPP
278 const YAML::Node & wp_node_tmp = node[
"waypoints"];
279 const YAML::Node * wp_node = wp_node_tmp ? &wp_node_tmp : NULL;
281 const YAML::Node * wp_node = node.FindValue(
"waypoints");
286 for (
unsigned int i = 0; i < wp_node->size(); ++i)
289 geometry_msgs::msg::Pose wp;
295 wp.position.x = (*wp_node)[i][
"x"].as<
double>();
296 wp.position.y = (*wp_node)[i][
"y"].as<
double>();
297 auto name = (*wp_node)[i][
"name"].as<std::string>();
304 RCLCPP_ERROR(
getLogger(),
"parsing waypoint file, syntax error in point %d", i);
311 RCLCPP_WARN_STREAM(
getLogger(),
"Couldn't find any waypoints in the provided yaml file.");
314 catch (
const YAML::ParserException & ex)
317 getLogger(),
"Error loading the Waypoints YAML file. Incorrect syntax: " << ex.what());
void setGoalCheckerId(std::string goal_checker_id)
void setDefaultPlanners()
geometry_msgs::msg::Pose toPoseMsg()
void postWaypointEvent(int index)
boost::signals2::connection cancelledNav2ZClientConnection_
void loadWayPointsFromFile2(std::string filepath)
const std::vector< geometry_msgs::msg::Pose > & getWaypoints() const
long getCurrentWaypointIndex() const
void onGoalCancelled(ClNav2Z::WrappedResult &)
boost::signals2::connection abortedNav2ZClientConnection_
std::vector< std::string > waypointsNames_
void removeWaypoint(int index)
WaypointEventDispatcher waypointsEventDispatcher
boost::signals2::connection succeddedNav2ZClientConnection_
smacc2::SmaccSignal< void()> onNavigationRequestCancelled
void onGoalAborted(ClNav2Z::WrappedResult &)
smacc2::SmaccSignal< void()> onNavigationRequestAborted
std::vector< geometry_msgs::msg::Pose > waypoints_
void onInitialize() override
void loadWayPointsFromFile(std::string filepath)
void onGoalReached(ClNav2Z::WrappedResult &res)
smacc2::SmaccSignal< void()> onNavigationRequestSucceded
void setWaypoints(const std::vector< geometry_msgs::msg::Pose > &waypoints)
void insertWaypoint(int index, geometry_msgs::msg::Pose &newpose)
ISmaccStateMachine * getStateMachine()
TComponent * getComponent()
rclcpp::Logger getLogger()
virtual std::string getName() const
rclcpp::Node::SharedPtr getNode()
ISmaccState * getCurrentState() const
virtual std::string getName()=0
boost::signals2::connection onAborted(void(T::*callback)(WrappedResult &), T *object)
std::shared_future< typename GoalHandle::SharedPtr > sendGoal(Goal &goal)
boost::signals2::connection onSucceeded(void(T::*callback)(WrappedResult &), T *object)
typename ActionClient::Goal Goal
GoalHandle::WrappedResult WrappedResult
boost::signals2::connection onCancelled(void(T::*callback)(WrappedResult &), T *object)