Skip to content

Commit

Permalink
Add documentation to the newly added structs
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Jan 20, 2025
1 parent ad466a1 commit 8936c7a
Showing 1 changed file with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@

namespace ros2_control
{
struct MovingAverageStatisticsData
/**
* @brief Data structure to store the statistics of a moving average. The data is protected by a
* mutex and the data can be updated and retrieved.
*/
class MovingAverageStatisticsData
{
using MovingAverageStatistics =
using MovingAverageStatisticsCollector =
libstatistics_collector::moving_average_statistics::MovingAverageStatistics;
using StatisticData = libstatistics_collector::moving_average_statistics::StatisticData;

Expand All @@ -39,7 +43,11 @@ struct MovingAverageStatisticsData
reset_statistics_sample_count_ = std::numeric_limits<unsigned int>::max();
}

void update_statistics(const std::shared_ptr<MovingAverageStatistics> & statistics)
/**
* @brief Update the statistics data with the new statistics data.
* @param statistics statistics collector to update the current statistics data.
*/
void update_statistics(const std::shared_ptr<MovingAverageStatisticsCollector> & statistics)
{
std::unique_lock<realtime_tools::prio_inherit_mutex> lock(mutex_);
if (statistics->GetCount() > 0)
Expand All @@ -57,6 +65,10 @@ struct MovingAverageStatisticsData
}
}

/**
* @brief Set the number of samples to reset the statistics.
* @param reset_sample_count number of samples to reset the statistics.
*/
void set_reset_statistics_sample_count(unsigned int reset_sample_count)
{
std::unique_lock<realtime_tools::prio_inherit_mutex> lock(mutex_);
Expand All @@ -72,40 +84,57 @@ struct MovingAverageStatisticsData
statistics_data.sample_count = 0;
}

/**
* @brief Get the statistics data.
* @return statistics data.
*/
const StatisticData & get_statistics() const
{
std::unique_lock<realtime_tools::prio_inherit_mutex> lock(mutex_);
return statistics_data;
}

private:
/// Statistics data
StatisticData statistics_data;
/// Number of samples to reset the statistics
unsigned int reset_statistics_sample_count_ = std::numeric_limits<unsigned int>::max();
/// Mutex to protect the statistics data
mutable realtime_tools::prio_inherit_mutex mutex_;
};
} // namespace ros2_control

namespace hardware_interface
{
/**
* @brief Data structure with two moving average statistics collectors. One for the execution time
* and the other for the periodicity.
*/
struct HardwareComponentStatisticsCollector
{
HardwareComponentStatisticsCollector()
{
execution_time = std::make_shared<MovingAverageStatistics>();
periodicity = std::make_shared<MovingAverageStatistics>();
execution_time = std::make_shared<MovingAverageStatisticsCollector>();
periodicity = std::make_shared<MovingAverageStatisticsCollector>();
}

using MovingAverageStatistics =
using MovingAverageStatisticsCollector =
libstatistics_collector::moving_average_statistics::MovingAverageStatistics;

/**
* @brief Resets the internal statistics of the execution time and periodicity statistics
* collectors.
*/
void reset_statistics()
{
execution_time->Reset();
periodicity->Reset();
}

std::shared_ptr<MovingAverageStatistics> execution_time = nullptr;
std::shared_ptr<MovingAverageStatistics> periodicity = nullptr;
/// Execution time statistics collector
std::shared_ptr<MovingAverageStatisticsCollector> execution_time = nullptr;
/// Periodicity statistics collector
std::shared_ptr<MovingAverageStatisticsCollector> periodicity = nullptr;
};
} // namespace hardware_interface

Expand Down

0 comments on commit 8936c7a

Please sign in to comment.