Class: ROS::TimeValue
Overview
super class of times
Instance Attribute Summary collapse
-
#nsecs ⇒ Integer
Nano seconds.
-
#secs ⇒ Integer
Seconds.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
compare time value.
-
#canonicalize ⇒ TimeValue
canonicalize secs and nsecs.
-
#to_nsec ⇒ Float
convert to nano seconds.
-
#to_sec ⇒ Float
convert to seconds.
Instance Attribute Details
#nsecs ⇒ Integer
Returns nano seconds.
21 22 23 |
# File 'lib/ros/time.rb', line 21 def nsecs @nsecs end |
#secs ⇒ Integer
Returns seconds.
18 19 20 |
# File 'lib/ros/time.rb', line 18 def secs @secs end |
Instance Method Details
#<=>(other) ⇒ Integer
compare time value
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ros/time.rb', line 52 def <=>(other) diff = self.to_nsec - other.to_nsec if diff > 0 1 elsif diff < 0 -1 else 0 end end |
#canonicalize ⇒ TimeValue
canonicalize secs and nsecs
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ros/time.rb', line 25 def canonicalize while @nsecs >= 1e9.to_i @secs += 1 @nsecs -= 1e9.to_i end while @nsecs < 0 @secs -= 1 @nsecs += 1e9.to_i end self end |
#to_nsec ⇒ Float
convert to nano seconds
45 46 47 |
# File 'lib/ros/time.rb', line 45 def to_nsec @nsecs + (@secs * 1e9) end |
#to_sec ⇒ Float
convert to seconds
39 40 41 |
# File 'lib/ros/time.rb', line 39 def to_sec @secs + (@nsecs / 1e9) end |