Easy Navigation
Loading...
Searching...
No Matches
GoalManager.hpp
Go to the documentation of this file.
1// Copyright 2025 Intelligent Robotics Lab
2//
3// This file is part of the project Easy Navigation (EasyNav in short)
4// licensed under the GNU General Public License v3.0.
5// See <http://www.gnu.org/licenses/> for details.
6//
7// Easy Navigation program is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
22
23#ifndef EASYNAV_SYSTEM__GOALMANAGER_HPP_
24#define EASYNAV_SYSTEM__GOALMANAGER_HPP_
25
26#include "rclcpp/subscription.hpp"
27#include "rclcpp/publisher.hpp"
28#include "rclcpp/macros.hpp"
29#include "rclcpp_lifecycle/lifecycle_node.hpp"
30
31#include "easynav_interfaces/msg/navigation_control.hpp"
32#include "easynav_interfaces/msg/goal_manager_info.hpp"
33#include "geometry_msgs/msg/pose_stamped.hpp"
34#include "nav_msgs/msg/goals.hpp"
35
37
38namespace easynav
39{
40
48{
49public:
50 RCLCPP_SMART_PTR_DEFINITIONS(GoalManager)
51
52
56 enum class State
57 {
60 };
61
67 {
69 double position {0.03};
71 double height {std::numeric_limits<double>::max()};
73 double yaw {0.01};
74 };
75
82 NavState & nav_state,
83 rclcpp_lifecycle::LifecycleNode::SharedPtr parent_node);
84
89 [[nodiscard]] inline nav_msgs::msg::Goals get_goals() const {return goals_;}
90
95 [[nodiscard]] inline State get_state() const {return state_;}
96
100 void set_finished();
101
106 void set_failed(const std::string & reason);
107
112 void set_error(const std::string & reason);
113
117 void update(NavState & nav_state);
118
128 void check_goals(
129 const geometry_msgs::msg::Pose & current_pose,
130 const GoalTolerance & goal_tolerance
131 );
132
133private:
135 rclcpp_lifecycle::LifecycleNode::SharedPtr parent_node_;
136
138 GoalTolerance goal_tolerance_ {};
139
141 nav_msgs::msg::Goals goals_;
142
144 rclcpp::Publisher<easynav_interfaces::msg::NavigationControl>::SharedPtr control_pub_;
145
147 rclcpp::Subscription<easynav_interfaces::msg::NavigationControl>::SharedPtr control_sub_;
148
150 rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr comanded_pose_sub_;
151
153 rclcpp::Publisher<easynav_interfaces::msg::GoalManagerInfo>::SharedPtr info_pub_;
154
156 easynav_interfaces::msg::NavigationControl::UniquePtr last_control_;
157
159 std::string id_;
160
162 std::string current_client_id_;
163
165 bool allow_preempt_goal_ {true};
166
168 rclcpp::Time nav_start_time_;
169
171 void accept_request(
172 const easynav_interfaces::msg::NavigationControl & msg,
173 easynav_interfaces::msg::NavigationControl & response);
174
176 void control_callback(easynav_interfaces::msg::NavigationControl::UniquePtr msg);
177
179 void comanded_pose_callback(geometry_msgs::msg::PoseStamped::UniquePtr msg);
180
182 void set_preempted();
183
185 State state_ {State::IDLE};
186};
187
188} // namespace easynav
189
190#endif // EASYNAV_SYSTEM__GOALMANAGER_HPP_
A blackboard-like structure to hold the current state of the navigation system.
void update(NavState &nav_state)
Update internal logic, including preemption and timeout checks.
Definition GoalManager.cpp:314
nav_msgs::msg::Goals get_goals() const
Get current goals.
Definition GoalManager.hpp:89
GoalManager(NavState &nav_state, rclcpp_lifecycle::LifecycleNode::SharedPtr parent_node)
Constructor.
Definition GoalManager.cpp:76
void set_finished()
Mark the current goal as successfully completed.
Definition GoalManager.cpp:246
State
Current internal goal state.
Definition GoalManager.hpp:57
@ ACTIVE
A goal is currently being pursued.
Definition GoalManager.hpp:59
@ IDLE
No active goal.
Definition GoalManager.hpp:58
void set_error(const std::string &reason)
Mark the system as in error state.
Definition GoalManager.cpp:264
void check_goals(const geometry_msgs::msg::Pose &current_pose, const GoalTolerance &goal_tolerance)
Check if the robot is currently at the first goal.
Definition GoalManager.cpp:395
State get_state() const
Get current internal goal state.
Definition GoalManager.hpp:95
void set_failed(const std::string &reason)
Mark the current goal as failed.
Definition GoalManager.cpp:282
A generic, type-safe, thread-safe blackboard to hold runtime state.
Definition NavState.hpp:87
Definition CircularBuffer.hpp:28
A structure to represent the goal tolerances.
Definition GoalManager.hpp:67
double yaw
Angular tolerance in radians for the yaw angle.
Definition GoalManager.hpp:73
double height
Positional tolerance for z axis in meters. Very big number as default.
Definition GoalManager.hpp:71
double position
Positional tolerance for x/y in meters.
Definition GoalManager.hpp:69