Easy Navigation
Loading...
Searching...
No Matches
CommandGuard.hpp
Go to the documentation of this file.
1// Copyright 2026 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_CONTROLLER__SAFETY__COMMANDGUARD_HPP_
19#define EASYNAV_CONTROLLER__SAFETY__COMMANDGUARD_HPP_
20
21#include <cstdint>
22#include <optional>
23#include <string>
24#include <utility>
25
26#include "geometry_msgs/msg/twist_stamped.hpp"
27#include "rclcpp/logger.hpp"
28#include "rclcpp/qos.hpp"
29#include "rclcpp/time.hpp"
30#include "rclcpp_lifecycle/lifecycle_node.hpp"
31
34
36{
37
51{
52public:
54 void declare_parameters(rclcpp_lifecycle::LifecycleNode & node);
55
57 bool configure(rclcpp_lifecycle::LifecycleNode & node);
58
60 bool check_controller_period(double period, const std::string & controller) const;
61
63 [[nodiscard]] rclcpp::QoS qos() const;
64
66 bool is_new(const geometry_msgs::msg::TwistStamped & cmd);
67
69 bool discard_non_finite(NavState & nav_state);
70
73 const VelocityMux::Selection & selection, const rclcpp::Time & now);
74
76 [[nodiscard]] bool timed_out() const {return timed_out_;}
77
79 void report(NavState & nav_state, bool discarded, bool fresh);
80
82 [[nodiscard]] bool keepalive_due(const rclcpp::Time & now) const;
83
85 void published(const rclcpp::Time & stamp) {last_publish_ = stamp;}
86
89 void reset();
90
91 [[nodiscard]] double cmd_timeout() const {return cmd_timeout_;}
92 [[nodiscard]] double keepalive_period() const {return keepalive_period_;}
93
94private:
95 void write_report(NavState & nav_state, uint8_t level, const std::string & message);
96
97 double cmd_timeout_ {0.5};
98 double keepalive_period_ {0.0};
99 rclcpp::Logger logger_ {rclcpp::get_logger("controller_node")};
100 std::string hardware_id_ {"controller_node"};
101 std::string timeout_message_;
102
103 std::optional<geometry_msgs::msg::TwistStamped> last_controller_cmd_;
104 std::optional<rclcpp::Time> last_proposal_;
105 std::optional<rclcpp::Time> last_publish_;
106 bool timed_out_ {false};
107 std::optional<std::pair<uint8_t, std::string>> last_report_;
108};
109
110} // namespace easynav::safety
111
112#endif // EASYNAV_CONTROLLER__SAFETY__COMMANDGUARD_HPP_
A blackboard-like structure to hold the current state of the navigation system.
Declaration of the VelocityMux class.
A generic, type-safe, thread-safe blackboard to hold runtime state.
Definition NavState.hpp:87
Keeps the velocity command sent to the robot from being stale or invalid.
Definition CommandGuard.hpp:51
bool configure(rclcpp_lifecycle::LifecycleNode &node)
Reads and checks the parameters, and starts over. Logs and returns false if invalid.
Definition CommandGuard.cpp:54
void report(NavState &nav_state, bool discarded, bool fresh)
Updates "diagnostics.cmd_vel" after this cycle's selection.
Definition CommandGuard.cpp:159
void published(const rclcpp::Time &stamp)
Records that a command stamped stamp was published.
Definition CommandGuard.hpp:85
bool discard_non_finite(NavState &nav_state)
Consumes this cycle's non-finite proposals.
Definition CommandGuard.cpp:115
double cmd_timeout() const
Definition CommandGuard.hpp:91
VelocityMux::Selection supervise(const VelocityMux::Selection &selection, const rclcpp::Time &now)
selection, or zero if its non-zero target is held for longer than the timeout.
Definition CommandGuard.cpp:131
bool check_controller_period(double period, const std::string &controller) const
Checks "cmd_timeout" against the period (s) of controller. Logs if not longer.
Definition CommandGuard.cpp:79
bool keepalive_due(const rclcpp::Time &now) const
Whether the command must be republished at now (keepalive).
Definition CommandGuard.cpp:172
double keepalive_period() const
Definition CommandGuard.hpp:92
bool timed_out() const
Whether the target was zeroed because no proposal arrived in time.
Definition CommandGuard.hpp:76
void reset()
Forgets the timeout, keepalive and last command (e.g.
Definition CommandGuard.cpp:186
bool is_new(const geometry_msgs::msg::TwistStamped &cmd)
Whether a controller command is new (stamp or value changed). Remembers it.
Definition CommandGuard.cpp:105
rclcpp::QoS qos() const
QoS of the velocity publisher.
Definition CommandGuard.cpp:91
void declare_parameters(rclcpp_lifecycle::LifecycleNode &node)
Declares "cmd_timeout" and "cmd_vel_keepalive_period" in node.
Definition CommandGuard.cpp:47
Definition CommandGuard.hpp:36
This cycle's selection.
Definition VelocityMux.hpp:51