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 Quality of Service (QoS) to publishers and subscribers #107

Merged
merged 2 commits into from
May 29, 2023

Conversation

hoffmann-stefan
Copy link
Member

extracted from #94

Adds QoS basic settings to publisher and subscribers.

The default profiles (see https://github.com/ros2/rmw/blob/rolling/rmw/include/rmw/qos_profiles.h) are for another PR.

Example

// taken and stripped down from https://github.com/schiller-de/tf2_dotnet/blob/main/tf2_dotnet/TransformListener.cs

var tf2ListenerQosProfile = QosProfile.KeepLast(100);

// The with methods return a immutable copy with the changed value.
var tf2StaticListenerQosProfile = QosProfile.KeepLast(100)
    .WithTransientLocal();

var tfSubscription = node.CreateSubscription<TFMessage>("/tf", (TFMessage message) =>
{
    // ...
}, tf2ListenerQosProfile);

var tfStaticSubscription = node.CreateSubscription<TFMessage>("/tf_static", (TFMessage message) =>
{
    // ...
}, tf2StaticListenerQosProfile);

Added/changed public API

namespace ROS2
{
    public enum QosHistoryPolicy
    {
        SystemDefault = 0,
        KeepLast = 1,
        KeepAll = 2,
    }

    public enum QosReliabilityPolicy
    {
        SystemDefault = 0,
        Reliable = 1,
        BestEffort = 2,
    }

    public enum QosDurabilityPolicy
    {
        SystemDefault = 0,
        TransientLocal = 1,
        Volatile = 2,
    }

    public enum QosLivelinessPolicy
    {
        SystemDefault = 0,
        Automatic = 1,
        ManualByTopic = 3,
    }

    public sealed class QosProfile
    {
        // no default constructor
        private QosProfile() {}

        public static TimeSpan InfiniteDuration { get; }
        public static QosProfile DefaultProfile { get; }
        public QosHistoryPolicy History { get; }
        public int Depth { get; }
        public QosReliabilityPolicy Reliability { get; }
        public QosDurabilityPolicy Durability { get; }
        public TimeSpan Deadline { get; }
        public TimeSpan Lifespan { get; }
        public QosLivelinessPolicy Liveliness { get; }
        public TimeSpan LivelinessLeaseDuration { get; }
        public bool AvoidRosNamespaceConventions { get; }

        // factory methods
        public static QosProfile KeepLast(int depth);
        public static QosProfile KeepAll();

        // "immutable setters"
        public QosProfile WithKeepLast(int depth);
        public QosProfile WithKeepAll();

        public QosProfile WithReliability(QosReliabilityPolicy reliability);
        public QosProfile WithReliable();
        public QosProfile WithBestEffort();
	
        public QosProfile WithDurability(QosDurabilityPolicy durability);
	public QosProfile WithTransientLocal();
        public QosProfile WithVolatile();

        public QosProfile WithDeadline(TimeSpan deadline);
        public QosProfile WithLifespan(TimeSpan lifespan);

        public QosProfile WithLiveliness(QosLivelinessPolicy liveliness);
        public QosProfile WithLivelinessLeaseDuration(TimeSpan livelinessLeaseDuration);

        public QosProfile WithAvoidRosNamespaceConventions(bool avoidRosNamespaceConventions);
    }
}
 namespace ROS2
 {
     public sealed partial class Node
     {
-        public Publisher<T> CreatePublisher<T>(string topic) where T : IRosMessage
+        public Publisher<T> CreatePublisher<T>(string topic, QosProfile qosProfile = null) where T : IRosMessage

-        public Subscription<T> CreateSubscription<T>(string topic, Action<T> callback) where T : IRosMessage, new()
+        public Subscription<T> CreateSubscription<T>(string topic, Action<T> callback, QosProfile qosProfile = null) where T : IRosMessage, new()
     }
 }

@hoffmann-stefan hoffmann-stefan changed the title Feature/qos Add Quality of Service (QOS) to publishers and subscribers May 19, 2023
@hoffmann-stefan hoffmann-stefan changed the title Add Quality of Service (QOS) to publishers and subscribers Add Quality of Service (QoS) to publishers and subscribers May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant