CPP-TOOLBOX
Loading...
Searching...
No Matches
PeriodicSignal Class Reference

A class for generating periodic signals based on a specified rate with different operation modes. More...

#include <periodic_signal.hpp>

Public Member Functions

 PeriodicSignal (int rate_limit_hz, OperationMode mode=OperationMode::MEASURED_DELTAS)
 
bool process_and_get_signal ()
 Returns true if one or more signals should have occurred since the last call. If we have fallen behind, it "catches up" to the latest expected signal.
 
double get_last_delta_time () const
 returns the amount of time it took for the last signal to come through
 
bool enough_time_has_passed () const
 returns true if a signal would have occurred since the last signal.
 
double get_cycle_progress () const
 Returns normalized progress [0,1] through the current cycle.
 

Detailed Description

A class for generating periodic signals based on a specified rate with different operation modes.

The current implementation was found to be more accurate then the previous implementation, which can be viewed by going back in the git history to when this comment was added, and viewing the periodic signals implementation, in the old implementation everything was based off the last time and it would have error building up over time, with the new implemenation everything is thought of as a timeline, and the "ticks" are laid out before hand, we just sample the clock and figure out which tick we are in, which has shown to be more accurate.

Constructor & Destructor Documentation

◆ PeriodicSignal()

PeriodicSignal::PeriodicSignal ( int rate_limit_hz,
OperationMode mode = OperationMode::MEASURED_DELTAS )
inlineexplicit

Member Function Documentation

◆ enough_time_has_passed()

bool PeriodicSignal::enough_time_has_passed ( ) const
inline

returns true if a signal would have occurred since the last signal.

◆ get_cycle_progress()

double PeriodicSignal::get_cycle_progress ( ) const
inline

Returns normalized progress [0,1] through the current cycle.

◆ get_last_delta_time()

double PeriodicSignal::get_last_delta_time ( ) const
inline

returns the amount of time it took for the last signal to come through

when the operation mode is PERFECT_DELTAS, this function lies and always returns the computed period based off rate_limit_hz when the operation mode is MEASURED_DELTAS, this function returns the measured amount of time

◆ process_and_get_signal()

bool PeriodicSignal::process_and_get_signal ( )
inline

Returns true if one or more signals should have occurred since the last call. If we have fallen behind, it "catches up" to the latest expected signal.

Note
this is the function that should be called when you want to do something with the signal

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