jsk-ros-pkg / jsk_common

common programs for jsk-ros-pkg
43 stars 81 forks source link

Add boolean operation nodes (and, or, not) #1706

Closed iory closed 2 years ago

iory commented 2 years ago

What is this?

Add nodes that take bool values and return the result of the or, and and not operation. For example, or_node.py can be used to merge the results of a node that outputs whether the robot is speaking in English or Japanese.

708yamaguchi commented 2 years ago

Thank you very much for your quick response! I think this PR is OK to merge after tests passing.

I am sorry, but one last thing. Do you think we should make not_node and boolean_node common?

seperate reason

merge reason

iory commented 2 years ago

Do you think we should make not_node and boolean_node common?

Your idea that merging them is good. I merged not node to boolean node and add docs. https://github.com/jsk-ros-pkg/jsk_common/pull/1706/commits/50cc9bacbb78ad129a638cd0d5b0db4ee1b99471

mqcmd196 commented 2 years ago

I'm sorry I missed my launch file and send wrong change request... it works fine currently

knorth55 commented 2 years ago

can you support other message type like this? and also, I think we can publish all operators' result, not selecting one, i.e. ~output/and, ~output/or...

input0: /bool
input0_type: std_msgs/Bool
input0_cond: m.data
input1: /chatter
input1_type: std_msgs/String
input1_cond: m.data == 'hello'
iory commented 2 years ago

can you support other message type like this?

I'm not sure I understand this correctly, so can you explain more details?

knorth55 commented 2 years ago

this PR only supports std_msgs/Bool messages. I think we can subscribe other message type, and add check condition field for boolean.

input0: /bool
input0_type: std_msgs/Bool
input0_cond: "m.data"
input1: /chatter
input1_type: std_msgs/String
input1_cond: "m.data == 'hello'"
input2: /image
input2_type: sensor_msgs/Image
input2_cond: "m.header.frame_id in ['base', 'base_link']"

In this example, boolean node can return the boolean operated result like this.

(setq bool-msg (one-shot-subscribe "/bool" std_msgs::Bool))
(setq chatter-msg (one-shot-subscribe "/chatter" std_msgs::String))
(setq img-msg (one-shot-subscribe "/image" sensor_msgs::Image))
(setq res
  (and
    (send bool-msg :data)
    (string= (send chatter-msg :data) "hello")
    (find (send img-msg :header :frame_id) (list "base" "base_link) :test #'string=)))
(setq res-msg (instance std_msgs::Bool :init :data res))
(ros::publish "~output/and" res-msg)
(bool_msg.data and chatter_msg.data == 'hello' and img_msg.header.frame_id in ['base', 'base_link'])
iory commented 2 years ago

I see. I understand it.

iory commented 2 years ago

I think we can subscribe other message type, and add check condition field for boolean.

Enabled condition using python expressions. https://github.com/jsk-ros-pkg/jsk_common/pull/1706/commits/dfda476834e3a25ef336c139861406887886b5c6 You can easily try using following command.

roslaunch jsk_topic_tools sample_boolean_node.launch
Kanazawanaoaki commented 2 years ago

It is convenient to set conditions with rosparam and use it for any message! I was able to execute the new version of sample.

k-okada commented 2 years ago

@iory @708yamaguchi @mqcmd196 @knorth55 @Kanazawanaoaki Please add link to your use cases

iory commented 2 years ago

Originally, this node was supposed to be used when a person talks with a robot. When the robot is speaking, it can be used to prevent the robot from subscribing to audio because it does not recognize the robot's own voice. Use the case as follows. https://github.com/nakane11/teach_spot/blob/e5e74dd950361615c07642fd3358bceb9130309f/launch/speech_recognition.launch#L17-L58

k-okada commented 2 years ago

I see, to ignore robot speaking voice, we recommend to connect speaker to respeaker directly.

iory commented 2 years ago

we recommend to connect speaker to respeaker directly.

Yeah, it's a good solution if we can use respeaker and connect speaker to it directly. Thanks!