Easy Navigation
Loading...
Searching...
No Matches
ControllerNode.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
18
19#ifndef EASYNAV_CONTROLLER__CONTROLLERNODE_HPP_
20#define EASYNAV_CONTROLLER__CONTROLLERNODE_HPP_
21
22#include <memory>
23#include <mutex>
24#include <optional>
25#include <set>
26#include <string>
27
28#include "geometry_msgs/msg/twist.hpp"
29#include "geometry_msgs/msg/twist_stamped.hpp"
30
34#include "easynav_core/ControllerMethodBase.hpp"
35#include "easynav_core/RobotLimits.hpp"
36#include "easynav_core/SafetyChannel.hpp"
37#include "easynav_core/PluginSwitcher.hpp"
38#include "rclcpp/macros.hpp"
39#include "rclcpp_lifecycle/lifecycle_node.hpp"
40
41namespace easynav
42{
43
47
71class ControllerNode : public rclcpp_lifecycle::LifecycleNode, public RobotLimitsProvider
72{
73public:
74 RCLCPP_SMART_PTR_DEFINITIONS(ControllerNode)
75 using CallbackReturnT = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
76
81 explicit ControllerNode(
82 const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
83
88
96 CallbackReturnT on_configure(const rclcpp_lifecycle::State & state);
97
105 CallbackReturnT on_activate(const rclcpp_lifecycle::State & state);
106
114 CallbackReturnT on_deactivate(const rclcpp_lifecycle::State & state);
115
123 CallbackReturnT on_cleanup(const rclcpp_lifecycle::State & state);
124
132 CallbackReturnT on_shutdown(const rclcpp_lifecycle::State & state);
133
141 CallbackReturnT on_error(const rclcpp_lifecycle::State & state);
142
151 rclcpp::CallbackGroup::SharedPtr get_real_time_cbg();
152
161 bool cycle_rt(std::shared_ptr<NavState> nav_state, bool trigger = false);
162
167 std::string get_loaded_controller() const;
168
178 void publish_cmd_vel_rt(std::shared_ptr<NavState> nav_state);
179
182 RobotLimits get_robot_limits() const override;
183
185 bool is_robot_limit_configured(const std::string & field) const override;
186
188 void set_robot_limits(const RobotLimits & limits) override;
189
190private:
192 void read_parameters();
193
195 void publish(const geometry_msgs::msg::TwistStamped & cmd);
196
198 void stop_robot();
199
201 bool check_cmd_timeout();
202
204 void apply_safety_channel(const SafetyChannelState & state);
205
206 RobotLimits robot_limits_;
207 SafetyChannelState safety_channel_;
208 std::set<std::string> configured_limits_;
209 mutable std::mutex robot_limits_mutex_;
210
211 bool use_cmd_vel_stamped_ {false};
212 rclcpp::Publisher<geometry_msgs::msg::TwistStamped>::SharedPtr vel_pub_stamped_;
213 rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr vel_pub_;
214
215 VelocityMux mux_;
216 VelocitySmoother smoother_;
217 safety::CommandGuard command_guard_;
218
220 std::optional<rclcpp::Time> last_smoother_step_;
221
224 bool last_published_zero_ {false};
225
229 rclcpp::CallbackGroup::SharedPtr realtime_cbg_;
230
238 PluginSwitcher<easynav::ControllerMethodBase> controller_;
239
245 const std::shared_ptr<const NavState> nav_state_;
246};
247
248} // namespace easynav
249
250#endif // EASYNAV_CONTROLLER__CONTROLLERNODE_HPP_
Declaration of the CommandGuard class.
Declaration of the VelocityMux class.
Declaration of the VelocitySmoother class.
CallbackReturnT on_activate(const rclcpp_lifecycle::State &state)
Activates the ControllerNode node.
Definition ControllerNode.cpp:189
CallbackReturnT on_configure(const rclcpp_lifecycle::State &state)
Configures the ControllerNode node.
Definition ControllerNode.cpp:136
CallbackReturnT on_shutdown(const rclcpp_lifecycle::State &state)
Shuts down the ControllerNode node.
Definition ControllerNode.cpp:216
std::string get_loaded_controller() const
Alias of the loaded controller (its "controller_types" entry).
Definition ControllerNode.cpp:260
CallbackReturnT on_cleanup(const rclcpp_lifecycle::State &state)
Cleans up the ControllerNode node.
Definition ControllerNode.cpp:207
ControllerNode(const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
Constructs a ControllerNode lifecycle node with the specified options.
Definition ControllerNode.cpp:72
bool cycle_rt(std::shared_ptr< NavState > nav_state, bool trigger=false)
Executes one cycle of real-time controller logic.
Definition ControllerNode.cpp:240
void publish_cmd_vel_rt(std::shared_ptr< NavState > nav_state)
Selects, smooths and publishes this RT cycle's velocity command.
Definition ControllerNode.cpp:267
rclcpp::CallbackGroup::SharedPtr get_real_time_cbg()
Returns the real-time callback group.
Definition ControllerNode.cpp:234
CallbackReturnT on_error(const rclcpp_lifecycle::State &state)
Handles errors in the ControllerNode node.
Definition ControllerNode.cpp:227
bool is_robot_limit_configured(const std::string &field) const override
Whether "robot_limits.<field>" was configured explicitly.
Definition ControllerNode.cpp:313
RobotLimits get_robot_limits() const override
Robot limits being enforced: the configured ones, cut down to the safety channel's safely limited spe...
Definition ControllerNode.cpp:306
void set_robot_limits(const RobotLimits &limits) override
Replaces the limits enforced until the next configure.
Definition ControllerNode.cpp:320
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn CallbackReturnT
Definition ControllerNode.hpp:75
CallbackReturnT on_deactivate(const rclcpp_lifecycle::State &state)
Deactivates the ControllerNode node.
Definition ControllerNode.cpp:199
A generic, type-safe, thread-safe blackboard to hold runtime state.
Definition NavState.hpp:87
Decides, every RT cycle, which velocity command is sent to the robot.
Definition VelocityMux.hpp:44
Brings the commanded velocity towards a target within the robot limits.
Definition VelocitySmoother.hpp:38
Keeps the velocity command sent to the robot from being stale or invalid.
Definition CommandGuard.hpp:51
Definition CircularBuffer.hpp:24
Definition PointPerception.hpp:51