Class: Rclrb::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/rclrb/timer.rb

Overview

Represent a ROS Timer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handle, node_handle, timer_period_sec, callback, callback_group, clock) ⇒ Timer

Construct a new timer, this should not be called directly, instead use Node.create_subscription.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rclrb/timer.rb', line 7

def initialize(handle, node_handle, timer_period_sec, callback, callback_group, clock)
  @callback_proc = Proc.new do |timer, time|
    callback.call time
  end
  @timer_handle = handle
  @node_handle = node_handle
  callback_group.add self

  CApi.handle_result(CApi.rcl_timer_init(handle, clock.handle, Rclrb.rcl_context, timer_period_sec*1e9, @callback_proc, Rclrb.rcl_allocator))
  Rclrb.rcl_signal_guard_condition.trigger
end

Instance Attribute Details

#timer_handleObject (readonly)

Returns the value of attribute timer_handle.



5
6
7
# File 'lib/rclrb/timer.rb', line 5

def timer_handle
  @timer_handle
end

Instance Method Details

#spin(wait_set = nil) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/rclrb/timer.rb', line 23

def spin(wait_set = nil)
  wait_set.add self if wait_set
  is_ready = CApi::BoolPtr.new
  CApi.handle_result(CApi.rcl_timer_is_ready @timer_handle, is_ready)
  if is_ready[:value]
    CApi.handle_result(CApi.rcl_timer_call @timer_handle)
  end
end