Skip to content

Commit 92da344

Browse files
authored
Merge pull request #1758 from iory/boolean-node
[jsk_topic_tools] Eval at every timer callback
2 parents 880a9e1 + 7435a08 commit 92da344

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

doc/jsk_topic_tools/scripts/boolean_node.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ Parameters
6666
input1_condition: m.header.frame_id in ['base', 'base_link']
6767
6868
69+
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.
70+
71+
.. code-block:: bash
72+
73+
input1_condition: "(rospy.Time.now() - t).to_sec() < 1.0"
74+
75+
Use escape sequence when using the following symbols <(``&lt;``), >(``&gt;``), &(``&amp;``), '(``&apos;``) and "(``&quot;``) in launch file.
76+
77+
6978
* ``~rate`` (Int, Default: ``100``)
7079

7180
Publishing rate [Hz].

jsk_topic_tools/scripts/boolean_node.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,20 @@ def callback(self, topic_name, msg):
7878
lambda msg, tn=topic_name: self.callback(tn, msg))
7979
self.subs[topic_name] = deserialized_sub
8080
return
81-
filter_fn = self.filter_fns[topic_name]
82-
result = filter_fn(topic_name, msg, rospy.Time.now())
83-
self.data[topic_name] = result
81+
self.data[topic_name] = topic_name, msg, rospy.Time.now()
8482

8583
def timer_cb(self, timer):
8684
if len(self.data) != self.n_input:
8785
return
86+
eval_values = []
87+
for topic_name, msg, received_time in self.data.values():
88+
filter_fn = self.filter_fns[topic_name]
89+
eval_values.append(filter_fn(topic_name, msg, received_time))
8890
for op_str, pub in self.pubs.items():
8991
if op_str == 'not':
90-
flag = not list(self.data.values())[0]
92+
flag = not list(eval_values)[0]
9193
else:
92-
flag = reduce(OPERATORS[op_str], self.data.values())
94+
flag = reduce(OPERATORS[op_str], eval_values)
9395
pub.publish(std_msgs.msg.Bool(flag))
9496

9597

0 commit comments

Comments
 (0)