TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Speed Class Reference

Represents a speed measurement with unit conversion support. More...

#include <Speed.h>

Public Member Functions

 Speed (float speed, SpeedUnit unit)
 
void setValue (float newSpeed, SpeedUnit newUnit)
 
float getValue (SpeedUnit desiredUnit) const
 
Speed operator+ (const Speed &other) const
 
Speed operator- (const Speed &other) const
 
Speed operator* (float scalar) const
 
Speed operator/ (float scalar) const
 
bool operator== (const Speed &other) const
 
bool operator!= (const Speed &other) const
 
bool operator< (const Speed &other) const
 
bool operator<= (const Speed &other) const
 
bool operator> (const Speed &other) const
 
bool operator>= (const Speed &other) const
 
Speedoperator+= (const Speed &other)
 
Speedoperator-= (const Speed &other)
 
Speedoperator*= (float scalar)
 
Speedoperator/= (float scalar)
 

Protected Attributes

float speed = 0.0f
 
SpeedUnit unit = SpeedUnit::MPS
 Unit of the speed.
 

Detailed Description

Represents a speed measurement with unit conversion support.

The Speed class encapsulates a speed value and its unit, supporting meters per second (MPS), kilometers per hour (KPH), feet per second (FPS), and miles per hour (MPH). It provides methods to set and retrieve the speed in any supported unit, automatically handling conversions.

Example:

Speed s(10.0, SpeedUnit::MPS);
float mph = s.getValue(SpeedUnit::MPH); // Convert to miles per hour
s.setValue(36.0, SpeedUnit::KPH); // Update value in km/h
float mps = s.getValue(SpeedUnit::MPS); // Convert back to m/s
Represents a speed measurement with unit conversion support.
Definition: Speed.h:40
Note
Invalid conversions return -1.0f.
See also
SpeedUnit

Member Data Documentation

◆ unit

SpeedUnit unit = SpeedUnit::MPS
protected

Unit of the speed.

See also
SpeedUnit

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