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()
andsubscriber()
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 throughpublisher()
andsubscriber()
will be deactivated and theswitch
attribute will be set toFalse
. 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 (usingrospy.get_name()
)Add a
rospy.on_shutdown
hook to the node’sonShutdown()
methodSetup a
~switch
service that can be used to deactivate and reactivate the node
- Parameters
node_name (
str
) – a unique, descriptive name for the ROS nodenode_type (
duckietown.dtros.NodeType
) – a node typehelp ( – obj: str): a node description
dt_ghost ( – obj: bool): (Internal use only) excludes the node from the diagnostics
-
node_type
¶ the node type
- Type
duckietown.dtros.NodeType
- 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 thepublish()
method is used, an actual message will be send only ifactive
is set toTrue
.- Parameters
name (
str
) – resource name of topic, e.g. ‘laser’data_class (
ROS Message class
) – message class for serializationsubscriber_listener (
SubscribeListener
) – listener for subscription events. May beNone
tcp_nodelay (
bool
) – IfTrue
, setsTCP_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 whenNone
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 toFalse
, any calls topublish()
will not result in a message being sent. Can be directly assigned.- Type
- 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 thepublish()
method is used, an actual message will be send only ifactive
is set toTrue
.- Parameters
name (
str
) – resource name of topic, e.g. ‘laser’data_class (
ROS Message class
) – message class for serializationsubscriber_listener (
SubscribeListener
) – listener for subscription events. May be Nonetcp_nodelay (
bool
) – IfTrue
, setsTCP_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 whenNone
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 toFalse
, any calls to publish will not result in a message being sent. Can be directly assigned.- Type
- Raises
ROSException – if parameters are invalid
duckietown_utils¶
The duckietown_utils library provides utilities and common functionalities used by many Python modules in Duckietown.