Class: ROS::Time

Inherits:
TimeValue show all
Defined in:
lib/ros/time.rb

Overview

ROS Time object. This is used as msg object for time

Instance Attribute Summary

Attributes inherited from TimeValue

#nsecs, #secs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TimeValue

#<=>, #canonicalize, #to_nsec, #to_sec

Constructor Details

#initialize(time) ⇒ Time #initializeTime

Returns a new instance of Time.

Overloads:

  • #initialize(time) ⇒ Time

    Parameters:

    • initialize (::Time)

      with this time



78
79
80
81
82
83
84
85
86
87
# File 'lib/ros/time.rb', line 78

def initialize(time=nil)
  if time
    @secs = time.to_i
    @nsecs = ((time.to_f - @secs) * 1e9.to_i).to_i
  else
    @secs = 0
    @nsecs = 0
  end
  canonicalize
end

Class Method Details

.nowObject

initialize with current time



71
72
73
# File 'lib/ros/time.rb', line 71

def self.now
  self.new(::Time::now)
end

Instance Method Details

#+(duration) ⇒ Time

add time value

Parameters:

  • duration (Duration)

    duration for adding

Returns:

  • (Time)

    new time



92
93
94
95
96
97
# File 'lib/ros/time.rb', line 92

def +(duration)
  tm = ::ROS::Time.new
  tm.secs = @secs + duration.secs
  tm.nsecs = @nsecs + duration.nsecs
  tm.canonicalize
end

#-(other) ⇒ Duration

subtract time value

Parameters:

Returns:



102
103
104
105
106
107
# File 'lib/ros/time.rb', line 102

def -(other)
  d = ::ROS::Duration.new
  d.secs = @secs - other.secs
  d.nsecs = @nsecs - other.nsecs
  d.canonicalize
end