Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_topic_tools] Add filtered relay node which can filter a topic and transform it. #1757

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

iory
Copy link
Member

@iory iory commented Aug 23, 2022

What is this?

rostopic echo has a filter function, but it cannot publish a topic.
topic_tools/transform can format a topic and publish it, but it does not have the ability to filter.
Transforming while filtering a topic is simple and powerful.
This node provides a filter and publish (i.e. relay) functions.

Subscribing Topic

  • ~input (rospy/AnyMsg)

    Input message.

Publishing Topic

  • ~output (~output_type)

    Output topic. You can specify ~output_type param to publish topic.

Parameters

  • ~output_type (String, required)

    Message type of output_topic like std_msgs/Float32. This is the input for the get_message_class function.

  • ~filter (String, default: None)

    Condition of messages that match a specified Python expression.

    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).

    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.

filter: m.data == 'hello'

Note that, use escape sequence when using the following symbols <(&lt;), >(&gt;), &(&amp;), '(&apos;) and "(&quot;) in launch file.

  • ~transform (String, default: m)

    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.

  • ~import (List[String], default: [])

    List of Python modules to import and use in the expression.

Usage

$ rosrun jsk_topic_tools filtered_relay.py ~input:=/right_endeffector/wrench \
    ~output:=/right_endeffector/force_norm \
    _filter:='numpy.linalg.norm([m.wrench.force.x, m.wrench.force.y, m.wrench.force.z]) > 10.0' \
    _output_type:=geometry_msgs/WrenchStamped _import:="[geometry_msgs, numpy]"

Example

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.

roslaunch jsk_topic_tools sample_filtered_relay.launch

Use case

jsk-ros-pkg/jsk_robot#1570

@iory iory changed the title [WIP] Add filtered relay [jsk_topic_tools] Add filtered relay node which can filter a topic and transform it. Aug 23, 2022
Copy link
Member

@nakane11 nakane11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this node works well.
I cannot come up with real example like jsk-ros-pkg/jsk_robot#1570 right now because input and filter should be simple, but in such cases this node is useful.

jsk_topic_tools/scripts/filtered_relay.py Show resolved Hide resolved
jsk_topic_tools/scripts/filtered_relay.py Show resolved Hide resolved
@k-okada
Copy link
Member

k-okada commented Aug 25, 2022

since jsk-ros-pkg/jsk_robot#1570 has been closed and currently we do not have usage for this node. So may be we can leave this PR and re-start discussion / review until we found another use cases.

@iory
Copy link
Member Author

iory commented Aug 25, 2022

OK. We will wait until someone needs this node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants