ROS Package: duckietown

The duckietown package contains the duckietown.dtros library that supplies DTROS, the mother node for all Duckietown ROS nodes, and duckietown_utils, a number of convenient functions that you can use in your code.

Python Packages

duckietown.dtros

The duckietown.dtros library provides the parent class for all Duckietown ROS Nodes (i.e., DTROS), as well as decorated ROS Publisher (DTPublisher) and ROS Subscriber (DTSubscriber) classes. These classes extend the original ROS classes by adding extra functionalities.

class DTROS(node_name, node_type, pkg_name=None, help=None, dt_ghost=False)

Parent class for all Duckietown ROS nodes

All Duckietown ROS nodes should inherit this class. This class provides some basic common functionality that most of the ROS nodes need. By keeping these arguments and methods in a parent class, we can ensure consistent and reliable behaviour of all ROS nodes in the Duckietown universe.

In particular, the DTROS class provides:

  • Logging: By providing utility functions for logging such as loginfo, logwarn, etc.

  • Shutdown procedure: A common shutdown procedure for ROS nodes.

  • Switchable Subscribers and Publishers: publisher() and subscriber() return decorated subscribers and publishers that can be dynamically deactivated and reactivated.

  • Node deactivation and reactivation: through requesting False to the ~switch service all subscribers and publishers obtained through publisher() and subscriber() will be deactivated and the switch attribute will be set to False. This switch can be used by computationally expensive parts of the node code that are not in callbacks in order to pause their execution.

  • We look for a robot specific parameter file and overwrite the default parameters if it exists

Every children node should call the initializer of DTROS. This should be done by having the following line at the top of the children node __init__ method:

super(ChildrenNode, self).__init__(node_name='children_node_name')

The DTROS initializer will:

  • Initialize the ROS node with name node_name

  • Setup the node_name attribute to the node name passed by ROS (using rospy.get_name())

  • Add a rospy.on_shutdown hook to the node’s onShutdown() method

  • Setup a ~switch service that can be used to deactivate and reactivate the node

Parameters
  • node_name (str) – a unique, descriptive name for the ROS node

  • node_type (duckietown.dtros.NodeType) – a node type

  • help ( – obj: str): a node description

  • dt_ghost ( – obj: bool): (Internal use only) excludes the node from the diagnostics

node_name

the name of the node

Type

str

node_help

the description of the node

Type

str

node_type

the node type

Type

duckietown.dtros.NodeType

is_shutdown

whether the node is shutdown

Type

bool

Properties:

is_ghost: (bool): (Internal use only) whether the node is a ghost switch: (bool): current state of the switch (true=ON, false=OFF) parameters: (list): list of parameters defined within the node subscribers: (list): list of subscribers defined within the node publishers: (list): list of publishers defined within the node

Service:
~switch:

Switches the node between active state and inactive state.

input:

data (bool): The desired state. True for active, False for inactive.

outputs:

success (bool): True if the call succeeded message (str): Used to give details about success

class DTPublisher(*args, **kwargs)

A wrapper around rospy.Publisher.

This class is exactly the same as the standard rospy.Publisher with the only difference of an active attribute being added. Whenever the publish() method is used, an actual message will be send only if active is set to True.

Parameters
  • name (str) – resource name of topic, e.g. ‘laser’

  • data_class (ROS Message class) – message class for serialization

  • subscriber_listener (SubscribeListener) – listener for subscription events. May be None

  • tcp_nodelay (bool) – If True, sets TCP_NODELAY on the publisher’s socket (disables Nagle algorithm). This results in lower latency publishing at the cost of efficiency.

  • latch (bool) – will be sent that message immediately upon connection.

  • headers (dict) – used for future connections.

  • queue_size (int) – threads. A size of zero means an infinite queue, which can be dangerous. When the keyword is not being used or when None is passed all publishing will happen synchronously and a warning message will be printed.

All standard rospy.Publisher attributes
active

A flag that if set to True will allow publishing`. If set to False, any calls to publish() will not result in a message being sent. Can be directly assigned.

Type

bool

Raises

ROSException – if parameters are invalid

class DTSubscriber(name, data_class, callback=None, callback_args=None, queue_size=None, buff_size=65536, tcp_nodelay=False, **kwargs)

A wrapper around rospy.Subscriber.

This class is exactly the same as the standard rospy.Subscriber with the only difference of an active attribute being added. Whenever the publish() method is used, an actual message will be send only if active is set to True.

Parameters
  • name (str) – resource name of topic, e.g. ‘laser’

  • data_class (ROS Message class) – message class for serialization

  • subscriber_listener (SubscribeListener) – listener for subscription events. May be None

  • tcp_nodelay (bool) – If True, sets TCP_NODELAY on publisher’s socket (disables Nagle algorithm). This results in lower latency publishing at the cost of efficiency.

  • latch (bool) – will be sent that message immediately upon connection.

  • headers (dict) – used for future connections.

  • queue_size (int) – threads. A size of zero means an infinite queue, which can be dangerous. When the keyword is not being used or when None is passed all publishing will happen synchronously and a warning message will be printed.

All standard rospy.Publisher attributes
active

A flag that if set to True will allow publishing. If set to False, any calls to publish will not result in a message being sent. Can be directly assigned.

Type

bool

Raises

ROSException – if parameters are invalid

duckietown_utils

The duckietown_utils library provides utilities and common functionalities used by many Python modules in Duckietown.