Thunderbots Project
Loading...
Searching...
No Matches
Timestamp Class Reference

#include <timestamp.h>

Inheritance diagram for Timestamp:
Collaboration diagram for Timestamp:

Public Member Functions

 Timestamp ()
 
bool operator== (const Timestamp &other) const
 
bool operator!= (const Timestamp &other) const
 
bool operator< (const Timestamp &other) const
 
bool operator<= (const Timestamp &other) const
 
bool operator> (const Timestamp &other) const
 
bool operator>= (const Timestamp &other) const
 
Timestamp operator+ (const Duration &duration) const
 
Timestamp operator- (const Duration &duration) const
 
Duration operator- (const Timestamp &timestamp) const
 
- Public Member Functions inherited from Time
 Time ()
 
double toSeconds () const
 
double toMilliseconds () const
 
virtual ~Time ()=0
 

Static Public Member Functions

static const Timestamp fromSeconds (double seconds)
 
static const Timestamp fromMilliseconds (double milliseconds)
 
static const Timestamp fromTimestampProto (const TbotsProto::Timestamp &timestamp_proto)
 

Friends

std::ostream & operator<< (std::ostream &output_stream, const Timestamp &time)
 

Additional Inherited Members

- Static Public Attributes inherited from Time
static constexpr double EPSILON = 1e-15
 
- Protected Member Functions inherited from Time
 Time (double time_seconds)
 
- Protected Attributes inherited from Time
double time_in_seconds
 

Detailed Description

A simple Timestamp class built around doubles. This Timestamp is intended to represent the t_capture timestamps we receive from the SSL Vision system. These t_capture values are monotonic (meaning they are always positive and always increase), and are relative to the "epoch time" defined by SSL Vision. This "epoch" is when SSL Vision starts up and begins streaming data. Therefore, these timestamps are not absolute "wall clock" time, but points in time relative to when the SSL Vision program started. They can and should be used to timestamp all data received from SSL Vision and propagated throughout the system in order to calculate time differences (durations), velocities, and other time-dependent values.

Constructor & Destructor Documentation

◆ Timestamp()

Timestamp ( )

The default constructor for a Timestamp. Creates a Timestamp at time 0

Member Function Documentation

◆ fromMilliseconds()

const Timestamp fromMilliseconds ( double  milliseconds)
static

Creates a new Timestamp value from a value in milliseconds

Parameters
millisecondsA value >= 0.0, in milliseconds, from which to create the Timestamp
Exceptions
std::invalid_argumentif the given value is < 0.0
Returns
A Timestamp created from the given value

◆ fromSeconds()

const Timestamp fromSeconds ( double  seconds)
static

Creates a new Timestamp value from a value in seconds.

Parameters
secondsA value >= 0.0, in seconds, from which to create the Timestamp
Exceptions
std::invalid_argumentif the given value is < 0.0
Returns
A Timestamp created from the given value

◆ fromTimestampProto()

const Timestamp fromTimestampProto ( const TbotsProto::Timestamp &  timestamp_proto)
static

Creates a new Timestamp value based on the TbotsProto::Timestamp protobuf representation

Parameters
timestamp_protoThe TbotsProto::Timestamp protobuf which this timestamp should be based on
Exceptions
std::invalid_argumentif the given value is < 0.0
Returns
A Timestamp created from the given value

◆ operator!=()

bool operator!= ( const Timestamp other) const

Compares Timestamps for inequality

Parameters
otherthe Timestamp to compare with for inequality
Returns
true if the Timestamps are not equal, and false otherwise

◆ operator+()

Timestamp operator+ ( const Duration duration) const

Defines the addition operator for Timestamps. Allows Durations to be added to Timestamps

Parameters
durationthe Duration to add to this Timestamp
Returns
A new Timestamp with the given Duration added to this Timestamp

◆ operator-() [1/2]

Timestamp operator- ( const Duration duration) const

Defines the subtraction operator for Timestamps. Allows Durations to be subtracted from Timestamps

Parameters
durationthe Duration to subtract from this Timestamp
Returns
A new Timestamp with the given Duration subtracted from to this Timestamp

◆ operator-() [2/2]

Duration operator- ( const Timestamp timestamp) const

Defines the subtraction operator for Timestamps. Allows Timestamps to be subtracted from Timestamps

Parameters
timestampThe Timestamp to subtract from this Timestamp
Returns
A Duration that is the difference in time between the two timestamps

◆ operator<()

bool operator< ( const Timestamp other) const

Defines the "less than" operator. Returns true if this Timestamp is strictly less than (and not equal to) the other Timestamp

Parameters
otherthe Timestamp to compare with
Returns
true if this Timestamp is strictly less than (and not equal to) the other Timestamp, and false otherwise

◆ operator<=()

bool operator<= ( const Timestamp other) const

Defines the "less than or equal to" operator. Returns true if this Timestamp is less than or equal to the other Timestamp

Parameters
otherthe Timestamp to compare with
Returns
true if this Timestamp is less than or equal to the other Timestamp, and false otherwise

◆ operator==()

bool operator== ( const Timestamp other) const

Compares Timestamps for equality. Timestamps are considered equal if their values in seconds are within EPSILON from one another.

Parameters
otherthe Timestamp to compare with for equality
Returns
true if the Timestamps are equal and false otherwise

◆ operator>()

bool operator> ( const Timestamp other) const

Defines the "greater than" operator. Returns true if this Timestamp is strictly greater than (and not equal to) the other Timestamp

Parameters
otherthe Timestamp to compare with
Returns
true if this Timestamp is strictly greater than (and not equal to) the other Timestamp, and false otherwise

◆ operator>=()

bool operator>= ( const Timestamp other) const

Defines the "greater than or equal to" operator. Returns true if this Timestamp is greater than or equal to the other Timestamp

Parameters
otherthe Timestamp to compare with
Returns
true if this Timestamp is greater than or equal to the other Timestamp, and false otherwise

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  output_stream,
const Timestamp time 
)
friend

Implements the << operator for printing

Parameters
ostreamThe stream to print to
timeThe time to print
Returns
The output stream with the string representation of the class appended

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