Easy Navigation
Loading...
Searching...
No Matches
SafetyChannelMonitor.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_SYSTEM__SAFETY__SAFETYCHANNELMONITOR_HPP_
19#define EASYNAV_SYSTEM__SAFETY__SAFETYCHANNELMONITOR_HPP_
20
21#include <chrono>
22#include <cstdint>
23#include <mutex>
24#include <optional>
25#include <string>
26
27#include "easynav_interfaces/msg/safety_status.hpp"
28
29#include "easynav_core/SafetyChannel.hpp"
30
31namespace easynav::safety
32{
33
43{
44public:
45 using Clock = std::chrono::steady_clock;
46 using Status = easynav_interfaces::msg::SafetyStatus;
47
49 enum class Condition : uint8_t {VALID, NO_STATUS, STALE, INVALID};
50
52 {
53 SafetyChannelState state;
54 Condition condition {Condition::NO_STATUS};
55 bool operator==(const Evaluation & other) const
56 {
57 return state == other.state && condition == other.condition;
58 }
59 };
60
62 void configure(double timeout);
63
65 void received(const Status & msg, Clock::time_point now);
66
68 Evaluation evaluate(Clock::time_point now) const;
69
71 std::optional<Status> last_status() const;
72
74 static std::string invalid_reason(const Status & msg);
75
76private:
77 Clock::duration timeout_ {};
78 mutable std::mutex mutex_;
79 std::optional<Status> last_;
80 Clock::time_point last_time_ {};
81 bool last_valid_ {false};
82};
83
84} // namespace easynav::safety
85
86#endif // EASYNAV_SYSTEM__SAFETY__SAFETYCHANNELMONITOR_HPP_
Turns the safety channel's SafetyStatus messages into what EasyNav applies.
Definition SafetyChannelMonitor.hpp:43
static std::string invalid_reason(const Status &msg)
Why msg is invalid, or "".
Definition SafetyChannelMonitor.cpp:83
std::chrono::steady_clock Clock
Definition SafetyChannelMonitor.hpp:45
Evaluation evaluate(Clock::time_point now) const
The state to apply at now.
Definition SafetyChannelMonitor.cpp:47
void received(const Status &msg, Clock::time_point now)
A status msg was received at now.
Definition SafetyChannelMonitor.cpp:37
Condition
Why the state is what it is.
Definition SafetyChannelMonitor.hpp:49
std::optional< Status > last_status() const
The last status received, if any.
Definition SafetyChannelMonitor.cpp:76
easynav_interfaces::msg::SafetyStatus Status
Definition SafetyChannelMonitor.hpp:46
void configure(double timeout)
Sets the timeout (s, > 0) and forgets any status.
Definition SafetyChannelMonitor.cpp:28
Definition CommandGuard.hpp:36
std::mutex Singleton< C >::mutex_
Definition Singleton.hpp:80
RtMonitor::Status Status
Definition rt_monitor_tests.cpp:25
Definition SafetyChannelMonitor.hpp:52
SafetyChannelState state
Definition SafetyChannelMonitor.hpp:53
bool operator==(const Evaluation &other) const
Definition SafetyChannelMonitor.hpp:55
Condition condition
Definition SafetyChannelMonitor.hpp:54