Class Ros2Factory

java.lang.Object
edu.tufts.hrilab.ros2.Ros2Factory

public class Ros2Factory extends Object
Factory class to allow users to generate ROS 2 objects without needing to know a specific underlying implementation. The main purpose of this class is so we can implement different ROS2 Java implementations without changing classes that use ROS2
  • Constructor Details

    • Ros2Factory

      public Ros2Factory()
  • Method Details

    • getDefaultNode

      public static Ros2Node getDefaultNode()
      Returns an instance of a Ros2 Node with the default implementation
      Returns:
      Generic Ros2 Node
    • getDefaultNode

      public static Ros2Node getDefaultNode(int domainId)
      Parameters:
      domainId - Domain ID to create the node in
      Returns:
      Generic Ros2 Node
      See Also:
    • getDefaultPublisher

      public static <T extends id.jrosmessages.Message> Ros2Publisher<T> getDefaultPublisher(Class<T> messageType, String topicName)
      Returns an instance of a Ros2 publisher with the default implementation
      Type Parameters:
      T - Message type
      Parameters:
      messageType - Type of the message this publisher will publish, e.g. StringMessage
      topicName - Topic on which to publish
      Returns:
      Generic ROS2 Publisher
    • getDefaultPublisher

      public static <T extends id.jrosmessages.Message> Ros2Publisher<T> getDefaultPublisher(Class<T> messageType, String topicName, T msg)
      Returns an instance of a Ros2 Node with the default implementation, with a pre-initialized message.
      Type Parameters:
      T - Message type
      Parameters:
      messageType - Type of the message this publisher will publish, e.g. StringMessage
      topicName - Topic on which to publish
      msg - Initialized message to publish
      Returns:
      Generic ROS2 Publisher
    • getDefaultSubscriber

      public static <T extends id.jrosmessages.Message> Ros2Subscriber<T> getDefaultSubscriber(Class<T> messageType, String topic, SubscriberCallback<T> callback)
      Type Parameters:
      T - Message type
      Parameters:
      messageType - Type of the message this publisher will publish, e.g. StringMessage
      topic - Topic on which to publish
      callback - Function to execute on received message
      Returns:
      Generic ROS2 Subscriber