|
| 1 | +REP: 106 |
| 2 | +Title: Polled topics |
| 3 | +Version: $Revision$ |
| 4 | +Last-Modified: $Date$ |
| 5 | +Author: Dirk Thomas |
| 6 | +Status: Draft |
| 7 | +Type: Standards Track |
| 8 | +Content-Type: text/x-rst |
| 9 | +Created: 20-Dec-2010 |
| 10 | +ROS-Version: 1.6 |
| 11 | +Post-History: 20-Dec-2010 |
| 12 | + |
| 13 | + |
| 14 | +Abstract |
| 15 | +======== |
| 16 | + |
| 17 | +This REP adds support for filtering messages directly at |
| 18 | +the publishing node. The filtering configuration can be modified |
| 19 | +dynamically at runtime. It does not require additional nodes to be |
| 20 | +integrated for performing the filtering. |
| 21 | + |
| 22 | +Motivation |
| 23 | +========== |
| 24 | + |
| 25 | +In several scenarios a subscriber needs only a subset of messages |
| 26 | +published on a particular topic. Example use cases are: |
| 27 | + |
| 28 | +* Reduce frequency of messages, e.g., a lower number messages per |
| 29 | + second might be sufficient for visualizing the information. |
| 30 | + |
| 31 | +* Polling messages from topics, e.g. requesting only a single |
| 32 | + (or any other fixed number of) message(s). |
| 33 | + |
| 34 | +The filtering cannot be performed after receiving the messages since |
| 35 | +the available bandwidth between publisher (e.g. running on the mobile |
| 36 | +robot) and subscriber (e.g. the GUI) running on an external computer |
| 37 | +might be (severly) constrained. |
| 38 | + |
| 39 | +Use Cases |
| 40 | +========= |
| 41 | + |
| 42 | +Any scenario where a subscribing node does not require all messages |
| 43 | +from a particular topic. |
| 44 | + |
| 45 | +Since polling is only one use case of this proposal (the other is |
| 46 | +filtering data on a time- or count-base) the title should be |
| 47 | +reconsidered. *Polled topics* is misleading if the filtering is used |
| 48 | +to receive every 10-th message (which is indeed the opposite: |
| 49 | +*pushed*). |
| 50 | + |
| 51 | +Rationale |
| 52 | +========= |
| 53 | + |
| 54 | +The utilization of an additional filter node is not an optimal |
| 55 | +solution. Any topic in a large application might be subscribed to |
| 56 | +with particular filter constraints. The filtering should solely |
| 57 | +depend on the subscriber: |
| 58 | + |
| 59 | +* Filtering should not require manual adaption of the communication |
| 60 | + graph (e.g. by introducing a new filtering node). |
| 61 | + |
| 62 | +Currently the package message_filters is used to filter messages. |
| 63 | +Even when it is running on the same host as the publisher it |
| 64 | +implies an overhead which would be avoided with this REP: |
| 65 | + |
| 66 | +* All messages need to be marshaled and transfered to the filtering |
| 67 | + node (even if skipped / not relayed by the filter). For high |
| 68 | + update rate topics, large complex messages or resource restricted |
| 69 | + platforms the overhead is significant. |
| 70 | + |
| 71 | +* The publisher is not aware of the *real* current subscribers. |
| 72 | + The (optional) awareness of the publisher of the subsequent |
| 73 | + filtering enables skipping resource intensive computations. E.g. |
| 74 | + a node compresses images (received with 30fps) to JPG format, but |
| 75 | + the GUI requests only one image per second. |
| 76 | + |
| 77 | +Implementation |
| 78 | +============== |
| 79 | + |
| 80 | +The described functionality has been implemented on-top of ROS in |
| 81 | +student work. It is only a proof-of-concept and should not be |
| 82 | +applied to ROS as-is. |
| 83 | + |
| 84 | +Implementation on-top of ROS (proof-of-concept) customization |
| 85 | +------------------------------------------------------------- |
| 86 | + |
| 87 | +The pub/sub mechanism of ROS involves the three operations |
| 88 | +*advertise*, *subscribe* and *publish*: |
| 89 | + |
| 90 | +.. image:: http://ros.org/reps/rep-0106/ros-pub-sub.png |
| 91 | + |
| 92 | +The filter configuration is transfered from the subscriber-side to |
| 93 | +the publisher using an additional anti-parallel topic. The filter |
| 94 | +configuration is sent at subscription time as well as when the filter |
| 95 | +configuration is changed. The publisher side can then perform the |
| 96 | +requested filtering per subscriber. |
| 97 | + |
| 98 | +.. image:: http://ros.org/reps/rep-0106/ros-pub-sub-enh.png |
| 99 | + |
| 100 | +The interface for the suscriber is enhanced with an optional |
| 101 | +parameter during subscription as well as with an additional method |
| 102 | +for setting an filter configuration at runtime. |
| 103 | + |
| 104 | +As the filtering should not be performed by the publisher the |
| 105 | +behavior of the involved ROS classes needed to be modified. Since |
| 106 | +these classes are not *friendly* to be exchanged/subclassed, several |
| 107 | +modifications have been applied in order to enable exchanging the |
| 108 | +classes with custom subclasses: |
| 109 | + |
| 110 | +.. image:: http://ros.org/reps/rep-0106/ros-class-hierarchy.png |
| 111 | +.. image:: http://ros.org/reps/rep-0106/ros-custom-class-hierarchy.png |
| 112 | + |
| 113 | +While this approach looked promising, several issues came up due to |
| 114 | +missing virtual functions, internal use of singletons etc. It |
| 115 | +required extensive modifications of the ROS sources. |
| 116 | + |
| 117 | +The source code and the modification should only be viewed as a |
| 118 | +proof-of-concept and not as a patch sources_. |
| 119 | + |
| 120 | +Implementation in ROS |
| 121 | +--------------------- |
| 122 | + |
| 123 | +For integration into ROS a better approach should be used. The |
| 124 | +filter configuration may be sent using the already existing TCP |
| 125 | +connection between the publisher and the subscriber, avoiding an |
| 126 | +additional anti-parallel topic. |
| 127 | + |
| 128 | +The new features are not yet implemented in ROS. First a consensus |
| 129 | +should be reached before investing the coding effort. |
| 130 | + |
| 131 | +API changed / enhancements |
| 132 | +========================== |
| 133 | + |
| 134 | +GenericFilter (new class) |
| 135 | +------------------------- |
| 136 | + |
| 137 | +The new class *GenericFilter* acts as the interface for the filter |
| 138 | +and contains the filter configuration. This class is used by ROS |
| 139 | +and is subclassed for specific filter implementations. |
| 140 | + |
| 141 | +The following filters has been implemented for testing the behavior: |
| 142 | + |
| 143 | +* *PassThroughFilter* simply passes every messages. |
| 144 | + |
| 145 | +* *CounterFilter* passes every N-th message and skips the other. |
| 146 | + |
| 147 | +* *FrequencyFilter* passes one message every N milliseconds. This |
| 148 | + is similar to the CounterFilter but indepenent of the frequency of |
| 149 | + the published messages. |
| 150 | + |
| 151 | +Another easy to implement filter (not implemented done): |
| 152 | + |
| 153 | +* *FixedNumberFilter* passes the first N messages and skips any |
| 154 | + further. This would fit the title polled topics. |
| 155 | + |
| 156 | +Subscriber |
| 157 | +---------- |
| 158 | + |
| 159 | +The subscriber has a new public method *setFilter* which has a |
| 160 | +*GenericFilterPtr* as an argument. |
| 161 | + |
| 162 | +Internally it advertises the anti-parallel topic and publishes the |
| 163 | +filter configuration. This has to be repeated when new publishers |
| 164 | +are registered or the filter configuration changes. |
| 165 | + |
| 166 | +Publisher |
| 167 | +--------- |
| 168 | + |
| 169 | +Internally it subscribes to the anti-parallel topic and receives the |
| 170 | +filter configuration from each subscriber. The method |
| 171 | +*passCurrentMessage* utilizes the filter configuration of each |
| 172 | +subscriber to decide if the message is passed to that endpoint. |
| 173 | + |
| 174 | +A public method *getCurrentNumSubscribers* can be introduced (not yet |
| 175 | +implemented) which returns the number of subscribers which would |
| 176 | +receive the next published message. If this method returns zero the |
| 177 | +publisher could skip any computation to create the message as it |
| 178 | +would be skipped anyway. This skipping must still be reflected in |
| 179 | +the current filter configuration. |
| 180 | + |
| 181 | +Backwards Compatibility |
| 182 | +======================= |
| 183 | + |
| 184 | +Existing nodes not using the newly introduced filtering functionality |
| 185 | +continue to work with no changes. |
| 186 | + |
| 187 | +The message_filters package might utilize this new functionality when |
| 188 | +appropriate. |
| 189 | + |
| 190 | +References |
| 191 | +========== |
| 192 | + |
| 193 | +.. _sources: http://ros.org/reps/rep-0106/rep-polled-topics-sources.zip |
| 194 | + |
| 195 | +Copyright |
| 196 | +========= |
| 197 | + |
| 198 | +This document has been placed in the public domain. |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | +.. |
| 203 | + Local Variables: |
| 204 | + mode: indented-text |
| 205 | + indent-tabs-mode: nil |
| 206 | + sentence-end-double-space: t |
| 207 | + fill-column: 70 |
| 208 | + coding: utf-8 |
| 209 | + End: |
0 commit comments