From b580d89c70f91fdcfb36f5b3cb5184c3bfd1fd25 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Fri, 22 Sep 2023 12:21:36 +0200 Subject: [PATCH 1/3] Set a maximum number of accepted deadline miss the the AdvanceableRunner --- .../System/AdvanceableRunner.h | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/System/include/BipedalLocomotion/System/AdvanceableRunner.h b/src/System/include/BipedalLocomotion/System/AdvanceableRunner.h index c224a209ed..878afdac38 100644 --- a/src/System/include/BipedalLocomotion/System/AdvanceableRunner.h +++ b/src/System/include/BipedalLocomotion/System/AdvanceableRunner.h @@ -52,6 +52,7 @@ template class AdvanceableRunner bool m_isInitialized{false}; /**< True if the runner is initialized */ std::chrono::nanoseconds m_dT{std::chrono::nanoseconds::zero()}; /**< Period of the runner */ std::atomic m_isRunning{false}; /**> If True the runner is running */ + int m_maximumNumberOfAcceptedDeadlineMiss{-1}; /**< Maximum number of accepted deadline miss */ std::unique_ptr<_Advanceable> m_advanceable; /**< Advanceable contained in the runner */ typename SharedResource::Ptr m_input; /**< Input shared resource */ @@ -73,10 +74,11 @@ template class AdvanceableRunner * Initialize the AdvanceableRunner class * @param handler pointer to a parameter handler * @note The following parameters are required - * | Parameter Name | Type | Description | Mandatory | - * |:------------------:|:--------:|:---------------------------------------------------------------------:|:---------:| - * | `sampling_time` | `double` | Strictly positive number representing the sampling time in seconds | Yes | - * | `enable_telemetry` | `bool` | If True some additional information are stored. Default value `false` | No | + * | Parameter Name | Type | Description | Mandatory | + * |:------------------------------------------:|:--------:|:---------------------------------------------------------------------------------------------:|:---------:| + * | `sampling_time` | `double` | Strictly positive number representing the sampling time in seconds | Yes | + * | `enable_telemetry` | `bool` | If True some additional information are stored. Default value `false` | No | + * | `maximum_number_of_accepted_deadline_miss` | `int` | Number of accepted deadline miss. if negative the check is not considered. Default value `-1` | No | * @return true in case of success, false otherwise. */ bool initialize(std::weak_ptr handler); @@ -173,6 +175,15 @@ bool AdvanceableRunner<_Advanceable>::initialize( m_isTelemetryEnabled); } + if (!ptr->getParameter("maximum_number_of_accepted_deadline_miss", + m_maximumNumberOfAcceptedDeadlineMiss)) + { + log()->info("{} maximum_number_of_accepted_deadline_miss parameter not found. The default " + "parameter will be used: {}.", + errorPrefix, + m_maximumNumberOfAcceptedDeadlineMiss); + } + m_isInitialized = true; return true; } @@ -314,16 +325,30 @@ AdvanceableRunner<_Advanceable>::run(std::optionalm_output->set(this->m_advanceable->getOutput()); - // release the CPU - BipedalLocomotion::clock().yield(); - // this is enabled only if telemetry is set to true. if (m_isTelemetryEnabled && wakeUpTime < BipedalLocomotion::clock().now()) { std::lock_guard guard(m_infoMutex); m_info.deadlineMiss++; + if (m_maximumNumberOfAcceptedDeadlineMiss >= 0 + && m_info.deadlineMiss > m_maximumNumberOfAcceptedDeadlineMiss) + { + log()->error("{} - {} Experienced {} deadline misses. The maximum accepted " + "number is {}.", + logPrefix, + m_info.name, + m_info.deadlineMiss, + m_maximumNumberOfAcceptedDeadlineMiss); + + // we have to close the runner + this->m_isRunning = false; + break; + } } + // release the CPU + BipedalLocomotion::clock().yield(); + BipedalLocomotion::clock().sleepUntil(wakeUpTime); } From f9fdc7cc90fd357ad1ccf1cd954fe47cedcc8259 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Fri, 22 Sep 2023 12:24:43 +0200 Subject: [PATCH 2/3] Update the CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e549a7aeb8..2075a6106b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project are documented in this file. ### Added - Add the possibility to control a subset of coordinates in `TSID::CoMTask` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/724) +- Add the possibility to set the maximum number of accepted deadline miss in `System::AdvanceableRunner` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/726) ## [0.15.0] - 2023-09-05 ### Added From 5b6d71c9f0c7d4393c529e453abac7086a0d2bcc Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Mon, 25 Sep 2023 10:00:46 +0200 Subject: [PATCH 3/3] Remove the possibility to disable the telemetry in AdvanceableRunner --- .../System/AdvanceableRunner.h | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/System/include/BipedalLocomotion/System/AdvanceableRunner.h b/src/System/include/BipedalLocomotion/System/AdvanceableRunner.h index 878afdac38..02664a9458 100644 --- a/src/System/include/BipedalLocomotion/System/AdvanceableRunner.h +++ b/src/System/include/BipedalLocomotion/System/AdvanceableRunner.h @@ -58,7 +58,6 @@ template class AdvanceableRunner typename SharedResource::Ptr m_input; /**< Input shared resource */ typename SharedResource::Ptr m_output; /**< Output shared resource */ - bool m_isTelemetryEnabled{false}; /**< If true some additional information will be stored */ struct Info { unsigned int deadlineMiss{0}; /**< Number of deadline miss */ @@ -77,7 +76,6 @@ template class AdvanceableRunner * | Parameter Name | Type | Description | Mandatory | * |:------------------------------------------:|:--------:|:---------------------------------------------------------------------------------------------:|:---------:| * | `sampling_time` | `double` | Strictly positive number representing the sampling time in seconds | Yes | - * | `enable_telemetry` | `bool` | If True some additional information are stored. Default value `false` | No | * | `maximum_number_of_accepted_deadline_miss` | `int` | Number of accepted deadline miss. if negative the check is not considered. Default value `-1` | No | * @return true in case of success, false otherwise. */ @@ -167,14 +165,6 @@ bool AdvanceableRunner<_Advanceable>::initialize( m_dT = m_info.dT; - if (!ptr->getParameter("enable_telemetry", m_isTelemetryEnabled)) - { - log()->info("{} enable_telemetry parameter not found. The default parameter will be used: " - "{}.", - errorPrefix, - m_isTelemetryEnabled); - } - if (!ptr->getParameter("maximum_number_of_accepted_deadline_miss", m_maximumNumberOfAcceptedDeadlineMiss)) { @@ -325,23 +315,29 @@ AdvanceableRunner<_Advanceable>::run(std::optionalm_output->set(this->m_advanceable->getOutput()); - // this is enabled only if telemetry is set to true. - if (m_isTelemetryEnabled && wakeUpTime < BipedalLocomotion::clock().now()) + // check if the deadline is missed + if (wakeUpTime < BipedalLocomotion::clock().now()) { - std::lock_guard guard(m_infoMutex); - m_info.deadlineMiss++; + unsigned int deadlineMiss = 0; + + // scope to reduce the amount of time in which the mutex is locked + { + std::lock_guard guard(m_infoMutex); + m_info.deadlineMiss++; + deadlineMiss = m_info.deadlineMiss; + } + if (m_maximumNumberOfAcceptedDeadlineMiss >= 0 - && m_info.deadlineMiss > m_maximumNumberOfAcceptedDeadlineMiss) + && deadlineMiss > m_maximumNumberOfAcceptedDeadlineMiss) { + // we have to close the runner + m_isRunning = false; log()->error("{} - {} Experienced {} deadline misses. The maximum accepted " "number is {}.", logPrefix, m_info.name, - m_info.deadlineMiss, + deadlineMiss, m_maximumNumberOfAcceptedDeadlineMiss); - - // we have to close the runner - this->m_isRunning = false; break; } } @@ -352,22 +348,18 @@ AdvanceableRunner<_Advanceable>::run(std::optionalinfo("{} - {}: Closing the AdvanceableRunner.", logPrefix, m_info.name); - if (m_isTelemetryEnabled) + unsigned int deadlineMiss = 0; + // scope to reduce the amount of time in which the mutex is locked { - unsigned int deadlineMiss = 0; + std::lock_guard guard(m_infoMutex); + deadlineMiss = m_info.deadlineMiss; + } - // scope to reduce the amount of time in which the mutex is locked - { - std::lock_guard guard(m_infoMutex); - deadlineMiss = m_info.deadlineMiss; - } + log()->info("{} - {}: Closing the AdvanceableRunner. Number of deadline miss {}.", + logPrefix, + m_info.name, + deadlineMiss); - log()->info("{} - {}: Number of deadline miss {}.", - logPrefix, - m_info.name, - deadlineMiss); - } return this->m_advanceable->close(); };