Easy Navigation
Toggle main menu visibility
Loading...
Searching...
No Matches
easynav_system
include
easynav_system
safety
RtMonitor.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__RTMONITOR_HPP_
19
#define EASYNAV_SYSTEM__SAFETY__RTMONITOR_HPP_
20
21
#include <chrono>
22
#include <cstdint>
23
#include <optional>
24
25
namespace
easynav::safety
26
{
27
36
class
RtMonitor
37
{
38
public
:
39
using
Clock
= std::chrono::steady_clock;
40
41
enum class
Status
: uint8_t {OK = 0, LATE = 1, ERROR = 2};
42
44
void
configure
(
double
period,
double
max_period_factor,
int
max_late_cycles);
45
47
void
reset
();
48
50
Status
cycle_started
(Clock::time_point now);
51
52
[[nodiscard]]
Status
status
()
const
{
return
status_;}
53
55
[[nodiscard]] uint64_t
late_cycles
()
const
{
return
late_cycles_;}
56
58
[[nodiscard]]
int
consecutive_late_cycles
()
const
{
return
consecutive_late_;}
59
61
[[nodiscard]]
double
last_period
()
const
{
return
last_period_;}
62
63
private
:
64
double
max_period_ {0.0};
65
int
max_late_cycles_ {1};
66
67
std::optional<Clock::time_point> last_start_;
68
Status
status_ {Status::OK};
69
uint64_t late_cycles_ {0};
70
int
consecutive_late_ {0};
71
double
last_period_ {0.0};
72
};
73
74
}
// namespace easynav::safety
75
76
#endif
// EASYNAV_SYSTEM__SAFETY__RTMONITOR_HPP_
easynav::safety::RtMonitor
Detects real-time cycles that start late.
Definition
RtMonitor.hpp:37
easynav::safety::RtMonitor::cycle_started
Status cycle_started(Clock::time_point now)
A cycle starts at now.
Definition
RtMonitor.cpp:42
easynav::safety::RtMonitor::Status
Status
Definition
RtMonitor.hpp:41
easynav::safety::RtMonitor::Clock
std::chrono::steady_clock Clock
Definition
RtMonitor.hpp:39
easynav::safety::RtMonitor::late_cycles
uint64_t late_cycles() const
Late cycles since the last reset().
Definition
RtMonitor.hpp:55
easynav::safety::RtMonitor::consecutive_late_cycles
int consecutive_late_cycles() const
Late cycles in a row, up to now.
Definition
RtMonitor.hpp:58
easynav::safety::RtMonitor::last_period
double last_period() const
Time (s) between the last two cycle starts, 0 if none yet.
Definition
RtMonitor.hpp:61
easynav::safety::RtMonitor::configure
void configure(double period, double max_period_factor, int max_late_cycles)
Sets the expected period (s) and the thresholds, and starts over.
Definition
RtMonitor.cpp:24
easynav::safety::RtMonitor::reset
void reset()
Starts over (e.g. on activation): the next cycle has no previous one to be late from.
Definition
RtMonitor.cpp:32
easynav::safety::RtMonitor::status
Status status() const
Definition
RtMonitor.hpp:52
easynav::safety
Definition
CommandGuard.hpp:36
Status
RtMonitor::Status Status
Definition
rt_monitor_tests.cpp:25
Generated by
1.18.0