ReduxLib C++ 2024.3.2
Loading...
Searching...
No Matches
redux::frames Namespace Reference

Classes

class  Frame
 
class  FrameData
 
class  FrameListener
 

Functions

template<typename... T>
std::optional< std::tuple< FrameData< T >... > > WaitForFrames (units::second_t timeout, Frame< T > &... frames)
 
template<typename... T>
units::second_t MaxTimestamp (std::tuple< FrameData< T >... > frameData)
 

Detailed Description

Namespace holding classes relating to device data frames

Function Documentation

◆ MaxTimestamp()

template<typename... T>
units::second_t redux::frames::MaxTimestamp ( std::tuple< FrameData< T >... >  frameData)

Returns the max timestamp from a tuple of FrameData objects. Most useful for getting the "latest" CAN timestamp from a result of WaitForFrames.

Parameters
frameDatavalue from WaitForFrames
Returns
the maximum timestamp

◆ WaitForFrames()

template<typename... T>
std::optional< std::tuple< FrameData< T >... > > redux::frames::WaitForFrames ( units::second_t  timeout,
Frame< T > &...  frames 
)

Waits for all Frames to have transmitted a value. Either returns an std::tuple of FrameData<T>; representing the data from corresponding frames passed in (in the order they are passed in) or std::nullopt if timeout or interrupt is hit.

Code example:

// Keep in mind this code sample will likely cause timing overruns if on the main thread of your robot code.
// Device definitions:
// wait up to 40 ms for position and velocity data to come in from two Canandmags
auto data = redux::frames::WaitForFrames(40_ms, enc0.GetPositionFrame(), enc0.GetVelocityFrame(), enc1.GetPositionFrame());
if (!data.has_value()) {
fmt::print("WaitForFrames timed out before receiving all data\n");
} else {
// populates the above FrameData variables with the received data (unpacks the tuple)
std::tie(posFrame, velFrame, posFram1) = *data;
// fetches the maximum timestamp across all received timestamps (the "latest" value)
units::second_t maxTs = redux::frames::MaxTimestamp(*data);
// prints the received frame value and how far behind the latest received CAN timestamp it was
fmt::print("posFrame: {}, {}\n", posFrame.GetValue(),
(units::millisecond_t) (maxTs - posFrame.GetTimestamp()));
fmt::print("velFrame: {}, {}\n", velFrame.GetValue(),
(units::millisecond_t) (maxTs - velFrame.GetTimestamp()));
fmt::print("posFram1: {}, {}\n", posFram1.GetValue(),
(units::millisecond_t) (maxTs - posFram1.GetTimestamp()));
}
Definition: Frame.h:21
units::second_t GetTimestamp()
Definition: Frame.h:42
T GetValue()
Definition: Frame.h:35
Definition: Canandmag.h:91
std::optional< std::tuple< FrameData< T >... > > WaitForFrames(units::second_t timeout, Frame< T > &... frames)
Definition: Frame.h:243
units::second_t MaxTimestamp(std::tuple< FrameData< T >... > frameData)
Definition: Frame.h:274
Parameters
timeoutmaximum seconds to wait for before giving up
framesreferences to Frames to wait on. Position in argument list corresponds to position in the returned FrameData tuple.
Returns
a tuple of FrameData<T> representing the data from corresponding frames passed in or null if timeout or interrupt is hit.