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 "rclcpp/subscription.hpp"
22#include "rclcpp/publisher.hpp"
23#include "rclcpp/macros.hpp"
24#include "rclcpp_lifecycle/lifecycle_node.hpp"
25
26#include "easynav_interfaces/msg/navigation_control.hpp"
27#include "easynav_interfaces/msg/goal_manager_info.hpp"
28#include "geometry_msgs/msg/pose_stamped.hpp"
29#include "nav_msgs/msg/goals.hpp"
30
32
33namespace easynav
34{
35
43{
44public:
45 RCLCPP_SMART_PTR_DEFINITIONS(GoalManager)
46
47
51 enum class State
52 {
55 };
56
62 {
64 double position {0.03};
66 double height {std::numeric_limits<double>::max()};
68 double yaw {0.01};
69 };
70
77 NavState & nav_state,
78 rclcpp_lifecycle::LifecycleNode::SharedPtr parent_node);
79
84 [[nodiscard]] inline nav_msgs::msg::Goals get_goals() const {return goals_;}
85
90 [[nodiscard]] inline State get_state() const {return state_;}
91
95 void set_finished();
96
101 void set_failed(const std::string & reason);
102
107 void set_error(const std::string & reason);
108
112 void update(NavState & nav_state);
113
123 void check_goals(
124 const geometry_msgs::msg::Pose & current_pose,
125 const GoalTolerance & goal_tolerance
126 );
127
128private:
130 rclcpp_lifecycle::LifecycleNode::SharedPtr parent_node_;
131
133 GoalTolerance goal_tolerance_ {};
134
136 nav_msgs::msg::Goals goals_;
137
139 rclcpp::Publisher<easynav_interfaces::msg::NavigationControl>::SharedPtr control_pub_;
140
142 rclcpp::Subscription<easynav_interfaces::msg::NavigationControl>::SharedPtr control_sub_;
143
145 rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr comanded_pose_sub_;
146
148 rclcpp::Publisher<easynav_interfaces::msg::GoalManagerInfo>::SharedPtr info_pub_;
149
151 easynav_interfaces::msg::NavigationControl::UniquePtr last_control_;
152
154 std::string id_;
155
157 std::string current_client_id_;
158
160 bool allow_preempt_goal_ {true};
161
163 rclcpp::Time nav_start_time_;
164
166 void accept_request(
167 const easynav_interfaces::msg::NavigationControl & msg,
168 easynav_interfaces::msg::NavigationControl & response);
169
171 void control_callback(easynav_interfaces::msg::NavigationControl::UniquePtr msg);
172
174 void comanded_pose_callback(geometry_msgs::msg::PoseStamped::UniquePtr msg);
175
177 void set_preempted();
178
180 State state_ {State::IDLE};
181};
182
183} // namespace easynav
184
185#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:309
nav_msgs::msg::Goals get_goals() const
Get current goals.
Definition GoalManager.hpp:84
GoalManager(NavState &nav_state, rclcpp_lifecycle::LifecycleNode::SharedPtr parent_node)
Constructor.
Definition GoalManager.cpp:71
void set_finished()
Mark the current goal as successfully completed.
Definition GoalManager.cpp:241
State
Current internal goal state.
Definition GoalManager.hpp:52
@ ACTIVE
A goal is currently being pursued.
Definition GoalManager.hpp:54
@ IDLE
No active goal.
Definition GoalManager.hpp:53
void set_error(const std::string &reason)
Mark the system as in error state.
Definition GoalManager.cpp:259
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:390
State get_state() const
Get current internal goal state.
Definition GoalManager.hpp:90
void set_failed(const std::string &reason)
Mark the current goal as failed.
Definition GoalManager.cpp:277
A generic, type-safe, thread-safe blackboard to hold runtime state.
Definition NavState.hpp:82
Definition CircularBuffer.hpp:23
A structure to represent the goal tolerances.
Definition GoalManager.hpp:62
double yaw
Angular tolerance in radians for the yaw angle.
Definition GoalManager.hpp:68
double height
Positional tolerance for z axis in meters. Very big number as default.
Definition GoalManager.hpp:66
double position
Positional tolerance for x/y in meters.
Definition GoalManager.hpp:64