ros2_control - rolling
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
realtime_tools::AsyncFunctionHandlerParams Struct Reference

The AsyncFunctionHandlerParams struct is used to configure the AsyncFunctionHandler. If the type is SYNCHRONIZED, the async worker thread will be synchronized with the main thread, as the main thread will be triggering the async callback method. If the type is DETACHED, the async worker thread will be detached from the main thread and will have its own execution cycle. More...

#include <async_function_handler.hpp>

Collaboration diagram for realtime_tools::AsyncFunctionHandlerParams:
Collaboration graph
[legend]

Public Member Functions

bool validate () const
 Validate the parameters.
 
template<typename NodeT >
void initialize (NodeT &node, const std::string &prefix)
 Initialize the parameters from a node's parameters. The node should have the following parameters:
 

Public Attributes

int thread_priority = 50
 
std::vector< int > cpu_affinity_cores = {}
 
AsyncSchedulingPolicy scheduling_policy = AsyncSchedulingPolicy::SYNCHRONIZED
 
unsigned int exec_rate = 0u
 
rclcpp::Clock::SharedPtr clock = nullptr
 
rclcpp::Logger logger = rclcpp::get_logger("AsyncFunctionHandler")
 
std::function< bool()> trigger_predicate = []() { return true; }
 
bool wait_until_initial_trigger = true
 
bool print_warnings = true
 

Detailed Description

The AsyncFunctionHandlerParams struct is used to configure the AsyncFunctionHandler. If the type is SYNCHRONIZED, the async worker thread will be synchronized with the main thread, as the main thread will be triggering the async callback method. If the type is DETACHED, the async worker thread will be detached from the main thread and will have its own execution cycle.

Parameters
thread_priorityPriority of the async worker thread. Should be between 0 and 99.
cpu_affinity_coresCPU cores to which the async worker thread should be pinned. If empty, the thread will not be pinned to any CPU core.
scheduling_policyScheduling policy for the async worker thread. Can be either SYNCHRONIZED or DETACHED.
exec_rateExecution rate of the async worker thread in Hz. Only used if the scheduling_policy is DETACHED. Must be a positive integer.
clockClock to be used for the async worker thread. Only used if the scheduling_policy is DETACHED.
loggerLogger to be used for the async worker thread. If not set, a default logger will be used.
trigger_predicatePredicate function to check if the async callback method should be triggered or not. If not set, the async callback method will be triggered every time.
wait_until_initial_triggerWhether to wait until the initial trigger predicate is true before starting the async callback method. If true, the async callback method will not be called until the trigger predicate returns true for the first time. Very useful when the type is DETACHED.
print_warningsWhether to print warnings when the async callback method is not triggered due to any reason.

Member Function Documentation

◆ initialize()

template<typename NodeT >
void realtime_tools::AsyncFunctionHandlerParams::initialize ( NodeT &  node,
const std::string &  prefix 
)
inline

Initialize the parameters from a node's parameters. The node should have the following parameters:

  • thread_priority (int): Priority of the async worker thread. Default is 50.
  • cpu_affinity (int[]): CPU cores to which the async worker thread should be pinned. Default is empty, which means the thread will not be pinned to any CPU core.
  • scheduling_policy (string): Scheduling policy for the async worker thread. Can be either "synchronized" or "detached". Default is "synchronized".
  • execution_rate (int): Execution rate of the async worker thread in Hz.
  • wait_until_initial_trigger (bool): Whether to wait until the initial trigger predicate is true before starting the async callback method. Default is true.
  • print_warnings (bool): Whether to print warnings when the async callback method is not triggered due to any reason. Default is true.
    Parameters
    nodeThe node that is used to get the parameters.
    prefixParameter prefix to use when accessing node parameters.

◆ validate()

bool realtime_tools::AsyncFunctionHandlerParams::validate ( ) const
inline

Validate the parameters.

Returns
true if the parameters are valid, false otherwise.
Exceptions
std::runtime_errorif the scheduling policy is UNKNOWN.

The documentation for this struct was generated from the following file: