Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ros2 QoS BestEffort and Volatile by default #94

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions rosboard/rosboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import rospy # ROS1
elif os.environ.get("ROS_VERSION") == "2":
import rosboard.rospy2 as rospy # ROS2
from rclpy.qos import QoSProfile, QoSReliabilityPolicy, QoSDurabilityPolicy
else:
print("ROS not detected. Please source your ROS environment\n(e.g. 'source /opt/ros/DISTRO/setup.bash')")
exit(1)
Expand Down Expand Up @@ -219,11 +220,23 @@ def sync_subs(self):

rospy.loginfo("Subscribing to %s" % topic_name)

kwargs = {}
if rospy.__name__ == "rospy2":
# In ros2 we also can pass QoS parameters to the subscriber.
# Hardcoding for now to BestEffort and Volatile.
kwargs = {"qos": QoSProfile(
depth=10,
reliability=QoSReliabilityPolicy.BEST_EFFORT,
# reliability=QoSReliabilityPolicy.RELIABLE,
durability=QoSDurabilityPolicy.VOLATILE,
# durability=QoSDurabilityPolicy.TRANSIENT_LOCAL,
)}
self.local_subs[topic_name] = rospy.Subscriber(
topic_name,
self.get_msg_class(topic_type),
self.on_ros_msg,
callback_args = (topic_name, topic_type),
**kwargs
)

# clean up local subscribers for which remote clients have lost interest
Expand Down
4 changes: 2 additions & 2 deletions rosboard/rospy2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def unregister(self):
_node.destroy_publisher(self._pub)

class Subscriber(object):
def __init__(self, topic_name, topic_type, callback, callback_args = None):
def __init__(self, topic_name, topic_type, callback, callback_args = None, qos=10):
global _node
self.reg_type = "sub"
self.data_class = topic_type
Expand All @@ -222,7 +222,7 @@ def __init__(self, topic_name, topic_type, callback, callback_args = None):
self.type = _ros2_type_to_type_name(topic_type)
self.callback = callback
self.callback_args = callback_args
self._sub = _node.create_subscription(topic_type, topic_name, self._ros2_callback, 10, event_callbacks = rclpy.qos_event.SubscriptionEventCallbacks())
self._sub = _node.create_subscription(topic_type, topic_name, self._ros2_callback, qos, event_callbacks = rclpy.qos_event.SubscriptionEventCallbacks())
_node.guards
self.get_num_connections = lambda: 1 # No good ROS2 equivalent

Expand Down