Class: Rclrb::Subscription
- Inherits:
-
Object
- Object
- Rclrb::Subscription
- Defined in:
- lib/rclrb/subscription.rb
Overview
Represent a ROS subscription to a topic
Instance Attribute Summary collapse
-
#msg_type ⇒ Object
readonly
Returns the value of attribute msg_type.
-
#subscription_handle ⇒ Object
readonly
Returns the value of attribute subscription_handle.
Instance Method Summary collapse
-
#initialize(subscription_handle, node_handle, msg_type, topic, callback, qos_profile, callback_group, event_callbacks, raw) ⇒ Subscription
constructor
Construct a new subscription, this should not be called directly, instead use Node.create_subscription.
- #raw? ⇒ Boolean
- #spin(wait_set = nil) ⇒ Object
Constructor Details
#initialize(subscription_handle, node_handle, msg_type, topic, callback, qos_profile, callback_group, event_callbacks, raw) ⇒ Subscription
Construct a new subscription, this should not be called directly, instead use Node.create_subscription.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rclrb/subscription.rb', line 7 def initialize(subscription_handle, node_handle, msg_type, topic, callback, qos_profile, callback_group, event_callbacks, raw) @subscription_handle = subscription_handle @node_handle = node_handle @msg_type = msg_type @topic = topic @callback = callback @qos_profile = qos_profile @raw = raw callback_group.add self subscription_ops = CApi.() subscription_ops[:qos] = QoSProfile.get_profile(qos_profile).ros_profile CApi.handle_result CApi.rcl_subscription_init(@subscription_handle, node_handle, msg_type.type_support(), @topic, subscription_ops) Rclrb.rcl_signal_guard_condition.trigger end |
Instance Attribute Details
#msg_type ⇒ Object (readonly)
Returns the value of attribute msg_type.
5 6 7 |
# File 'lib/rclrb/subscription.rb', line 5 def msg_type @msg_type end |
#subscription_handle ⇒ Object (readonly)
Returns the value of attribute subscription_handle.
5 6 7 |
# File 'lib/rclrb/subscription.rb', line 5 def subscription_handle @subscription_handle end |
Instance Method Details
#raw? ⇒ Boolean
25 26 27 |
# File 'lib/rclrb/subscription.rb', line 25 def raw? return @raw end |
#spin(wait_set = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rclrb/subscription.rb', line 29 def spin(wait_set = nil) wait_set.add self if wait_set = CApi::RmwMessageInfoT.new data = @msg_type::FFIType.new status = CApi.rcl_take @subscription_handle, data, , nil if status == CApi::RCL_RET_OK msg = @msg_type. data @msg_type. data @callback.call(msg) elsif status == CApi::RCL_RET_SUBSCRIPTION_TAKE_FAILED # no message received else CApi.handle_result status end end |