Easy Navigation
Loading...
Searching...
No Matches
GoalManager.hpp
Go to the documentation of this file.
1// Copyright 2025 Intelligent Robotics Lab
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
17
18#ifndef EASYNAV_SYSTEM__GOALMANAGER_HPP_
19#define EASYNAV_SYSTEM__GOALMANAGER_HPP_
20
21#include <atomic>
22#include <memory>
23#include <string>
24
25#include "rclcpp/subscription.hpp"
26#include "rclcpp/publisher.hpp"
27#include "rclcpp/macros.hpp"
28#include "rclcpp_lifecycle/lifecycle_node.hpp"
29#include "easynav_interfaces/msg/navigation_control.hpp"
30#include "easynav_interfaces/msg/goal_manager_info.hpp"
31#include "geometry_msgs/msg/pose_stamped.hpp"
32#include "nav_msgs/msg/goals.hpp"
34
35namespace easynav
36{
37
45{
46public:
47 RCLCPP_SMART_PTR_DEFINITIONS(GoalManager)
48
49
53 enum class State
54 {
55 IDLE,
56 ACTIVE
57 };
58
64 {
66 double position {0.03};
68 double height {10000.0};
70 double yaw {0.01};
71 };
72
79 NavState & nav_state,
80 rclcpp_lifecycle::LifecycleNode::SharedPtr parent_node);
81
86 [[nodiscard]] inline nav_msgs::msg::Goals get_goals() const {return goals_;}
87
92 [[nodiscard]] inline State get_state() const {return state_;}
93
98 [[nodiscard]] inline bool is_paused() const {return paused_;}
99
103 void set_finished();
104
109 void set_failed(const std::string & reason);
110
115 void set_error(const std::string & reason);
116
123 void set_progress_held(bool held);
124
126 [[nodiscard]] bool is_progress_held() const {return progress_held_;}
127
131 void update(NavState & nav_state);
132
134 void read_parameters(NavState & nav_state);
135
145 void check_goals(
146 const geometry_msgs::msg::Pose & current_pose,
147 const GoalTolerance & goal_tolerance
148 );
149
150private:
153 rclcpp_lifecycle::LifecycleNode::SharedPtr get_node() const;
154
156 std::weak_ptr<rclcpp_lifecycle::LifecycleNode> parent_node_;
157
159 GoalTolerance goal_tolerance_ {};
160
162 nav_msgs::msg::Goals goals_;
163
165 rclcpp::Publisher<easynav_interfaces::msg::NavigationControl>::SharedPtr control_pub_;
166
168 rclcpp::Subscription<easynav_interfaces::msg::NavigationControl>::SharedPtr control_sub_;
169
171 rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr comanded_pose_sub_;
172
174 rclcpp::Publisher<easynav_interfaces::msg::GoalManagerInfo>::SharedPtr info_pub_;
175
177 easynav_interfaces::msg::NavigationControl::UniquePtr last_control_;
178
180 std::string id_;
181
183 std::string current_client_id_;
184
186 bool allow_preempt_goal_ {true};
187
189 rclcpp::Time nav_start_time_;
190
192 double update_frequency_ {20.0};
193
195 rclcpp::Duration update_period_ {0, 0};
196
198 rclcpp::Time last_update_time_;
199
201 bool first_update_ {true};
202
204 void accept_request(
205 const easynav_interfaces::msg::NavigationControl & msg,
206 easynav_interfaces::msg::NavigationControl & response);
207
209 void control_callback(easynav_interfaces::msg::NavigationControl::UniquePtr msg);
210
212 void comanded_pose_callback(geometry_msgs::msg::PoseStamped::UniquePtr msg);
213
215 void set_preempted();
216
218 State state_ {State::IDLE};
219
222 bool paused_ {false};
223
225 std::atomic<bool> progress_held_ {false};
226
229 State last_synced_navigation_state_ {State::IDLE};
230
233 bool last_synced_paused_ {false};
234
237 bool goals_synced_empty_ {true};
238
240 easynav_interfaces::msg::GoalManagerInfo info_;
241
243 bool info_final_pending_ {false};
244
246 void publish_final_info();
247};
248
249} // namespace easynav
250
251#endif // EASYNAV_SYSTEM__GOALMANAGER_HPP_
A blackboard-like structure to hold the current state of the navigation system.
void set_progress_held(bool held)
Holds or releases the mission's progress.
Definition GoalManager.cpp:349
void update(NavState &nav_state)
Update internal logic, including preemption and timeout checks.
Definition GoalManager.cpp:422
nav_msgs::msg::Goals get_goals() const
Get current goals.
Definition GoalManager.hpp:86
GoalManager(NavState &nav_state, rclcpp_lifecycle::LifecycleNode::SharedPtr parent_node)
Constructor.
Definition GoalManager.cpp:72
void set_finished()
Mark the current goal as successfully completed.
Definition GoalManager.cpp:327
State
Current internal goal state.
Definition GoalManager.hpp:54
@ IDLE
No active goal.
Definition GoalManager.hpp:55
void set_error(const std::string &reason)
Mark the system as in error state.
Definition GoalManager.cpp:364
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:547
void read_parameters(NavState &nav_state)
(Re)reads the parameters (on every configure: the GoalManager outlives cleanup).
Definition GoalManager.cpp:130
bool is_paused() const
Whether the current navigation (if any) is currently paused.
Definition GoalManager.hpp:98
State get_state() const
Get current internal goal state.
Definition GoalManager.hpp:92
void set_failed(const std::string &reason)
Mark the current goal as failed.
Definition GoalManager.cpp:386
bool is_progress_held() const
Whether the mission's progress is held (see set_progress_held()).
Definition GoalManager.hpp:126
A generic, type-safe, thread-safe blackboard to hold runtime state.
Definition NavState.hpp:87
Definition CircularBuffer.hpp:24
A structure to represent the goal tolerances.
Definition GoalManager.hpp:64
double yaw
Angular tolerance in radians for the yaw angle.
Definition GoalManager.hpp:70
double height
Positional tolerance for z axis in meters. Large default: height ignored.
Definition GoalManager.hpp:68
double position
Positional tolerance for x/y in meters.
Definition GoalManager.hpp:66