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] Eval at every timer callback #1758

Merged
merged 2 commits into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/jsk_topic_tools/scripts/boolean_node.rst
Expand Up @@ -66,6 +66,15 @@ Parameters
input1_condition: m.header.frame_id in ['base', 'base_link']


Note that this condition is evaluated each time a topic is published. For example, a condition that checks whether a certain topic has arrived within one second look like this.

.. code-block:: bash

input1_condition: "(rospy.Time.now() - t).to_sec() < 1.0"
nakane11 marked this conversation as resolved.
Show resolved Hide resolved

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


* ``~rate`` (Int, Default: ``100``)

Publishing rate [Hz].
Expand Down
12 changes: 7 additions & 5 deletions jsk_topic_tools/scripts/boolean_node.py
Expand Up @@ -78,18 +78,20 @@ def callback(self, topic_name, msg):
lambda msg, tn=topic_name: self.callback(tn, msg))
self.subs[topic_name] = deserialized_sub
return
filter_fn = self.filter_fns[topic_name]
result = filter_fn(topic_name, msg, rospy.Time.now())
self.data[topic_name] = result
self.data[topic_name] = topic_name, msg, rospy.Time.now()

def timer_cb(self, timer):
if len(self.data) != self.n_input:
return
eval_values = []
for topic_name, msg, received_time in self.data.values():
filter_fn = self.filter_fns[topic_name]
eval_values.append(filter_fn(topic_name, msg, received_time))
for op_str, pub in self.pubs.items():
if op_str == 'not':
flag = not list(self.data.values())[0]
flag = not list(eval_values)[0]
else:
flag = reduce(OPERATORS[op_str], self.data.values())
flag = reduce(OPERATORS[op_str], eval_values)
pub.publish(std_msgs.msg.Bool(flag))


Expand Down