18#ifndef EASYNAV_CONTROLLER__SAFETY__COMMANDGUARD_HPP_
19#define EASYNAV_CONTROLLER__SAFETY__COMMANDGUARD_HPP_
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"
57 bool configure(rclcpp_lifecycle::LifecycleNode & node);
63 [[nodiscard]] rclcpp::QoS
qos()
const;
66 bool is_new(
const geometry_msgs::msg::TwistStamped & cmd);
76 [[nodiscard]]
bool timed_out()
const {
return timed_out_;}
82 [[nodiscard]]
bool keepalive_due(
const rclcpp::Time & now)
const;
85 void published(
const rclcpp::Time & stamp) {last_publish_ = stamp;}
91 [[nodiscard]]
double cmd_timeout()
const {
return cmd_timeout_;}
95 void write_report(
NavState & nav_state, uint8_t level,
const std::string & message);
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_;
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_;
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