|
| 1 | +# filtered_relay.py |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +`rostopic echo` has a filter function, but it cannot publish a topic. |
| 6 | +`topic_tools/transform` can format a topic and publish it, but it does not have the ability to filter. |
| 7 | +Transforming while filtering a topic is simple and powerful. |
| 8 | +This node provides a filter and publish (i.e. relay) functions. |
| 9 | + |
| 10 | +## Subscribing Topic |
| 11 | + |
| 12 | +* `~input` (`rospy/AnyMsg`) |
| 13 | + |
| 14 | + Input message. |
| 15 | + |
| 16 | +## Publishing Topic |
| 17 | + |
| 18 | +* `~output` (`~output_type`) |
| 19 | + |
| 20 | + Output topic. You can specify `~output_type` param to publish topic. |
| 21 | + |
| 22 | +## Parameters |
| 23 | + |
| 24 | +* `~output_type` (`String`, required) |
| 25 | + |
| 26 | + Message type of output_topic like `std_msgs/Float32`. This is the input for the [get_message_class](http://docs.ros.org/en/diamondback/api/roslib/html/python/roslib.message-module.html#get_message_class) function. |
| 27 | + |
| 28 | +* `~filter` (`String`, default: `None`) |
| 29 | + |
| 30 | + Condition of messages that match a specified Python expression. |
| 31 | + |
| 32 | + The Python expression can access any of the Python builtins plus: ``topic`` (the topic of the message), ``m`` (the message) and ``t`` (time of message). |
| 33 | + |
| 34 | + For example, ``~input`` topic is ``std_msgs/String`` and if you want to check whether a sentence is a ``hello``, you can do the following. |
| 35 | + |
| 36 | +```bash |
| 37 | +filter: m.data == 'hello' |
| 38 | +``` |
| 39 | + |
| 40 | + Note that, use escape sequence when using the following symbols ``<(<)``, ``>(>)``, ``&(&)``, ``'(')`` and ``"(")`` in launch file. |
| 41 | + |
| 42 | +* `~transform` (`String`, default: `m`) |
| 43 | + |
| 44 | + Python expression that transform the input messages, which are given in the variable m. The default expression is `m`, which results in forwarding input (which can be a topic field) into output_topic. |
| 45 | + |
| 46 | +* `~import` (`List[String]`, default: `[]`) |
| 47 | + |
| 48 | + List of Python modules to import and use in the expression. |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +```bash |
| 53 | +$ rosrun jsk_topic_tools filtered_relay.py ~input:=/right_endeffector/wrench \ |
| 54 | + ~output:=/right_endeffector/force_norm \ |
| 55 | + _filter:='numpy.linalg.norm([m.wrench.force.x, m.wrench.force.y, m.wrench.force.z]) > 10.0' \ |
| 56 | + _output_type:=geometry_msgs/WrenchStamped _import:="[geometry_msgs, numpy]" |
| 57 | +``` |
| 58 | + |
| 59 | +## Example |
| 60 | + |
| 61 | +The following example subscribe to `/right_endeffector/wrench` and only those with a force norm greater than 10 are published as `/right_endeffector/force_norm`. |
| 62 | + |
| 63 | +```bash |
| 64 | +roslaunch jsk_topic_tools sample_filtered_relay.launch |
| 65 | +``` |
0 commit comments