Class: ROS::Duration

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

Overview

ROS Duration object

This is used as msg object for duration

Instance Attribute Summary

Attributes inherited from TimeValue

#nsecs, #secs

Instance Method Summary (collapse)

Methods inherited from TimeValue

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

Constructor Details

- (Duration) initialize(secs) - (Duration) initialize(secs, nsecs)

Returns a new instance of Duration

Examples:

d1 = ROS::Duration.new(0.1) # => @nsecs=100000000, @secs=0
d2 = ROS::Duration.new(1, 100) # => @nsecs=100, @secs=1

Overloads:

  • - (Duration) initialize(secs)

    Parameters:

    • secs (Float)

      initialize from seconds

  • - (Duration) initialize(secs, nsecs)

    Parameters:

    • secs (Integer)

      seconds

    • nsecs (Integer)

      nano seconds



27
28
29
30
31
32
33
34
35
# File 'lib/ros/duration.rb', line 27

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

Instance Method Details

- (Duration) +(duration)

create a new duration

Parameters:

  • duration (Duration)

    Duration for adding

Returns:



40
41
42
43
44
45
# File 'lib/ros/duration.rb', line 40

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

- (Duration) -(other)

create a new duration

Parameters:

  • other (Duration)

    Duration for substituting

Returns:



50
51
52
53
54
55
# File 'lib/ros/duration.rb', line 50

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

- (Object) sleep

sleep while this duration



58
59
60
# File 'lib/ros/duration.rb', line 58

def sleep
  Kernel.sleep(to_sec)
end