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

- (Integer) nsecs

Returns nano seconds

Returns:

  • (Integer)

    nano seconds



24
25
26
# File 'lib/ros/time.rb', line 24

def nsecs
  @nsecs
end

- (Integer) secs

Returns seconds

Returns:

  • (Integer)

    seconds



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

def secs
  @secs
end

Instance Method Details

- (Integer) <=>(other)

compare time value

Parameters:

Returns:

  • (Integer)

    result



55
56
57
58
59
60
61
62
63
64
# File 'lib/ros/time.rb', line 55

def <=>(other)
  diff = self.to_nsec - other.to_nsec
  if diff > 0
    1
  elsif diff < 0
    -1
  else
    0
  end
end

- (TimeValue) canonicalize

canonicalize secs and nsecs

Returns:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ros/time.rb', line 28

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

- (Float) to_nsec

convert to nano seconds

Returns:

  • (Float)

    nano seconds



48
49
50
# File 'lib/ros/time.rb', line 48

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

- (Float) to_sec

convert to seconds

Returns:

  • (Float)

    seconds



42
43
44
# File 'lib/ros/time.rb', line 42

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