Class: ROS::TimeValue

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ros/time.rb

Overview

super class of times

Direct Known Subclasses

Duration, Time

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nsecsInteger

Returns nano seconds.

Returns:

  • (Integer)

    nano seconds



21
22
23
# File 'lib/ros/time.rb', line 21

def nsecs
  @nsecs
end

#secsInteger

Returns seconds.

Returns:

  • (Integer)

    seconds



18
19
20
# File 'lib/ros/time.rb', line 18

def secs
  @secs
end

Instance Method Details

#<=>(other) ⇒ Integer

compare time value

Parameters:

Returns:

  • (Integer)

    result



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

#canonicalizeTimeValue

canonicalize secs and nsecs

Returns:



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_nsecFloat

convert to nano seconds

Returns:

  • (Float)

    nano seconds



45
46
47
# File 'lib/ros/time.rb', line 45

def to_nsec
  @nsecs + (@secs * 1e9)
end

#to_secFloat

convert to seconds

Returns:

  • (Float)

    seconds



39
40
41
# File 'lib/ros/time.rb', line 39

def to_sec
  @secs + (@nsecs / 1e9)
end