|
Open Model Railroad Network (OpenMRN)
|
This class provides a mechanism for working with velocity in different forms. More...
#include <Velocity.hxx>
Public Types | |
| enum | { FORWARD = false , REVERSE = true } |
| define an enumeration for direction More... | |
Public Member Functions | |
| Velocity () | |
| Default constructor. | |
| Velocity (int value) | |
| Basic constructor. | |
| Velocity (unsigned int value) | |
| Basic constructor. | |
| Velocity (float value) | |
| Basic constructor. | |
| Velocity (double value) | |
| Basic constructor. | |
| Velocity (float16_t value) | |
| Constructor that takes the 16 bit wire format. | |
| Velocity (const Velocity &old_velocity) | |
| Copy constructor. | |
| ~Velocity () | |
| Destructor does nothing. | |
| bool | isnan () const |
| Checks whether the speed is unknown. | |
| float | speed () const |
| Return the speed independent of direction. | |
| bool | direction () const |
| Return the direction independent of speed. | |
| void | set_direction (bool direction) |
| void | forward () |
| Set the direction to forward. | |
| void | reverse () |
| Set the direction to reverse. | |
| float | mph () const |
| Convert the native meters/sec representation into mile per hour. | |
| void | set_mph (float mph) |
| Sets the speed value from a given mph value. | |
| uint8_t | get_dcc_128 () |
| Get the speed in DCC 128 speed step format. | |
| void | set_dcc_128 (uint8_t value) |
| Set the speed from DCC 128 speed step format. | |
| uint8_t | get_dcc_28 () |
| Get the speed in DCC 28 speed step format. | |
| void | set_dcc_28 (uint8_t value) |
| Set the speed from DCC 28 speed step format. | |
| uint8_t | get_dcc_14 () |
| Get the speed in DCC 14 speed step format. | |
| void | set_dcc_14 (uint8_t value) |
| Set the speed from DCC 14 speed step format. | |
| float16_t | get_wire () const |
| Get a wire version of the velocity. | |
| void | set_wire (float16_t value) |
| Set the value based on the wire version of velocity. | |
| Velocity | operator+ (const Velocity &v) const |
| Overloaded addition operator. | |
| Velocity | operator+ (const float &v) const |
| Overloaded addition operator. | |
| Velocity | operator- (const Velocity &v) const |
| Overloaded subtraction operator. | |
| Velocity | operator- (const float &v) const |
| Overloaded subtraction operator. | |
| Velocity | operator* (const Velocity &v) const |
| Overloaded multiplication operator. | |
| Velocity | operator* (const float &v) const |
| Overloaded multiplication operator. | |
| Velocity | operator/ (const Velocity &v) const |
| Overloaded division operator. | |
| Velocity | operator/ (const float &v) const |
| Overloaded division operator. | |
| Velocity & | operator++ () |
| Overloaded pre-increement operator. | |
| Velocity | operator++ (int) |
| Overloaded post-increment operator. | |
| Velocity & | operator-- () |
| Overloaded pre-decreement operator. | |
| Velocity | operator-- (int) |
| Overloaded post-decrement operator. | |
| Velocity & | operator+= (const Velocity &v) |
| Overloaded addition equals operator. | |
| Velocity & | operator+= (const float &v) |
| Overloaded addition equals operator. | |
| Velocity & | operator-= (const Velocity &v) |
| Overloaded subtraction equals operator. | |
| Velocity & | operator-= (const float &v) |
| Overloaded subtraction equals operator. | |
| Velocity & | operator*= (const Velocity &v) |
| Overloaded multiplication equals operator. | |
| Velocity & | operator*= (const float &v) |
| Overloaded multiplication equals operator. | |
| Velocity & | operator/= (const Velocity &v) |
| Overloaded division equals operator. | |
| Velocity & | operator/= (const float &v) |
| Overloaded division equals operator. | |
| Velocity & | operator= (const Velocity &v) |
| Overloaded equals operator. | |
| Velocity & | operator= (const float &v) |
| Overloaded equals operator. | |
| bool | operator== (const Velocity &v) const |
| Overloaded equals equals operator. | |
| bool | operator== (const float &v) const |
| Overloaded equals equals operator. | |
| bool | operator!= (const Velocity &v) const |
| Overloaded not equals operator. | |
| bool | operator!= (const float &v) const |
| Overloaded not equals operator. | |
Static Public Member Functions | |
| static Velocity | from_mph (float mph) |
Static Private Member Functions | |
| static float | zero_adjust (float value, float old) |
| Adjust for a math result of negative 0. | |
Private Attributes | |
| float | velocity |
| Floating point representation of velocity. | |
This class provides a mechanism for working with velocity in different forms.
A single precision floating point value is used internally to store velocity, but this class provides the ability to easily work with different velocity formats including DCC 14/28/128 speed step formats. NMRAnet velocity is represented as a floating point meters/sec. The sign represents direction where negative is reverse and positive is forward. Sign is always preserved even when the result is 0. For example, -7.0 + 7.0 = -0.0 and 7.0 - 7.0 = +0.0 Be careful thought, per the C standards, a negative zero (-.0.0) velocity compared to constant 0.0 will compare true. Always use direction() when trying to determine the sign or direction of travel.
Definition at line 72 of file Velocity.hxx.
define an enumeration for direction
| Enumerator | |
|---|---|
| FORWARD | forward direction |
| REVERSE | reverse direction |
Definition at line 77 of file Velocity.hxx.
|
inline |
Default constructor.
Definition at line 85 of file Velocity.hxx.
|
inline |
Basic constructor.
| value | starting value for Velocity. |
Definition at line 93 of file Velocity.hxx.
Basic constructor.
| value | starting value for Velocity. |
Definition at line 101 of file Velocity.hxx.
|
inline |
Basic constructor.
| value | starting value for Velocity. |
Definition at line 109 of file Velocity.hxx.
|
inline |
Basic constructor.
| value | starting value for Velocity. |
Definition at line 117 of file Velocity.hxx.
|
inline |
Constructor that takes the 16 bit wire format.
| value | starting value for Velocity as IEEE half precision float. |
Definition at line 125 of file Velocity.hxx.
Copy constructor.
Definition at line 132 of file Velocity.hxx.
|
inline |
Destructor does nothing.
Definition at line 138 of file Velocity.hxx.
|
inline |
Return the direction independent of speed.
Definition at line 164 of file Velocity.hxx.
|
inline |
Set the direction to forward.
Definition at line 186 of file Velocity.hxx.
Definition at line 140 of file Velocity.hxx.
| uint8_t openlcb::Velocity::get_dcc_128 | ( | ) |
Get the speed in DCC 128 speed step format.
The mapping from meters/sec is strait forward. First convert to miles/hour, then each speed step represents 1 mile/hour. Saturate at 126 miles/hour.
bit 7: direction bits 6..0: 0 = stopped, 1 = estop, 2 - 127 = speed steps 1 - 126
Definition at line 48 of file Velocity.cxx.
| uint8_t openlcb::Velocity::get_dcc_14 | ( | ) |
Get the speed in DCC 14 speed step format.
This is a decimation of the 128 speed step mode.
bit 7..6: fixed at b'01' bit 5: direction bits 4: reserved 0 for headlight bits 3..0: 0 = stopped, 4 - 31 = speed steps 1 - 28
Definition at line 171 of file Velocity.cxx.
| uint8_t openlcb::Velocity::get_dcc_28 | ( | ) |
Get the speed in DCC 28 speed step format.
This is a decimation of the 128 speed step mode.
bit 7..6: fixed at b'01' bit 5: direction bits 4: speed step least significant bit bits 3..0: speed step significatn bits 4..1
Definition at line 105 of file Velocity.cxx.
|
inline |
Get a wire version of the velocity.
Definition at line 285 of file Velocity.hxx.
|
inline |
Checks whether the speed is unknown.
(NaN).
Definition at line 148 of file Velocity.hxx.
|
inline |
Convert the native meters/sec representation into mile per hour.
Definition at line 206 of file Velocity.hxx.
|
inline |
Overloaded not equals operator.
Definition at line 467 of file Velocity.hxx.
|
inline |
Overloaded not equals operator.
Definition at line 461 of file Velocity.hxx.
|
inline |
Overloaded multiplication operator.
Definition at line 331 of file Velocity.hxx.
|
inline |
Overloaded multiplication operator.
Definition at line 325 of file Velocity.hxx.
|
inline |
Overloaded multiplication equals operator.
Definition at line 414 of file Velocity.hxx.
|
inline |
Overloaded multiplication equals operator.
Definition at line 407 of file Velocity.hxx.
|
inline |
Overloaded addition operator.
Definition at line 307 of file Velocity.hxx.
|
inline |
Overloaded addition operator.
Definition at line 301 of file Velocity.hxx.
|
inline |
Overloaded pre-increement operator.
Definition at line 349 of file Velocity.hxx.
|
inline |
Overloaded post-increment operator.
Definition at line 356 of file Velocity.hxx.
|
inline |
Overloaded addition equals operator.
Definition at line 386 of file Velocity.hxx.
|
inline |
Overloaded addition equals operator.
Definition at line 379 of file Velocity.hxx.
|
inline |
Overloaded subtraction operator.
Definition at line 319 of file Velocity.hxx.
|
inline |
Overloaded subtraction operator.
Definition at line 313 of file Velocity.hxx.
|
inline |
Overloaded pre-decreement operator.
Definition at line 364 of file Velocity.hxx.
|
inline |
Overloaded post-decrement operator.
Definition at line 371 of file Velocity.hxx.
|
inline |
Overloaded subtraction equals operator.
Definition at line 400 of file Velocity.hxx.
|
inline |
Overloaded subtraction equals operator.
Definition at line 393 of file Velocity.hxx.
|
inline |
Overloaded division operator.
Definition at line 343 of file Velocity.hxx.
|
inline |
Overloaded division operator.
Definition at line 337 of file Velocity.hxx.
|
inline |
Overloaded division equals operator.
Definition at line 428 of file Velocity.hxx.
|
inline |
Overloaded division equals operator.
Definition at line 421 of file Velocity.hxx.
|
inline |
Overloaded equals operator.
Definition at line 442 of file Velocity.hxx.
|
inline |
Overloaded equals operator.
Definition at line 435 of file Velocity.hxx.
|
inline |
Overloaded equals equals operator.
Definition at line 455 of file Velocity.hxx.
|
inline |
Overloaded equals equals operator.
Definition at line 449 of file Velocity.hxx.
|
inline |
Set the direction to reverse.
Definition at line 195 of file Velocity.hxx.
Set the speed from DCC 128 speed step format.
The mapping from meters/sec is strait forward. First convert to miles/hour, then each speed step represents 1 mile/hour. Saturate at 126 miles/hour.
| value | bit 7: direction bits 6..0: 0 = stopped, 1 = estop, 2 - 127 = speed steps 1 - 126 |
Definition at line 78 of file Velocity.cxx.
Set the speed from DCC 14 speed step format.
This is a decimation of the 128 speed step mode.
| value | bit 7..6: fixed at b'01' bit 5: direction bits 4: reserved 0 for headlight bits 3..0: 0 = stopped, 4 - 31 = speed steps 1 - 28 |
This is a decimation of the 128 speed step mode.
| value | bit 7..6: fixed at b'01' bit 5: direction bits 4: reserved 0 for headlight bits 3..0: 0 = stopped, 2 - 15 = speed steps 1 - 14 |
Definition at line 203 of file Velocity.cxx.
Set the speed from DCC 28 speed step format.
This is a decimation of the 128 speed step mode.
| value | bit 7..6: fixed at b'01' bit 5: direction bits 4: speed step least significant bit bits 3..0: speed step significatn bits 4..1 |
Definition at line 139 of file Velocity.cxx.
Definition at line 173 of file Velocity.hxx.
Sets the speed value from a given mph value.
The sign of the mph value is ignored.
Definition at line 213 of file Velocity.hxx.
Set the value based on the wire version of velocity.
| value | IEEE half precision floating point representation of velocity |
Definition at line 295 of file Velocity.hxx.
|
inline |
Return the speed independent of direction.
Definition at line 156 of file Velocity.hxx.
Adjust for a math result of negative 0.
| value | value of math result |
| old | original value before expression |
Definition at line 480 of file Velocity.hxx.
|
private |
Floating point representation of velocity.
Definition at line 474 of file Velocity.hxx.