From 799a4c534aa4b9dbc64cdb8a1105770f5388fc36 Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Mon, 27 Mar 2023 08:44:24 +0900 Subject: [PATCH 01/10] fix python3 decode error in description and info in smach_to_mail.py --- .../jsk_robot_startup/scripts/smach_to_mail.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py index d280b55398..000e33d788 100755 --- a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py +++ b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py @@ -201,7 +201,10 @@ def _send_mail(self, subject, state_list): if 'DESCRIPTION' in x: description = EmailBody() description.type = 'text' - description.message = x['DESCRIPTION'] + description_txt = x['DESCRIPTION'] + if isinstance(description_txt, bytes): + description_txt = description_txt.decode('utf-8') + description.message = description_txt email_msg.body.append(description) email_msg.body.append(changeline) if 'IMAGE' in x and x['IMAGE']: @@ -222,7 +225,10 @@ def _send_mail(self, subject, state_list): if 'INFO' in x: info = EmailBody() info.type = 'text' - info.message = x['INFO'] + info_txt = x['INFO'] + if isinstance(info_txt, bytes): + info_txt = info_txt.decode('utf-8') + info.message = info_txt email_msg.body.append(info) email_msg.body.append(changeline) # rospy.loginfo("body:{}".format(email_msg.body)) From 1bf68ab2010d97c6a7ec60e6ee084512dc975054 Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Wed, 16 Nov 2022 23:44:28 +0900 Subject: [PATCH 02/10] [jsk_robot_startup] Fix unintended smach notification when demo fails --- jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py index 000e33d788..2fc8ff2f85 100755 --- a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py +++ b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py @@ -91,6 +91,7 @@ def _stop_timer_cb(self, event): self._send_twitter( self.smach_state_subject[key], self.smach_state_list[key]) self.smach_state_subject[key] = None + self.smach_state_list[key] = None rospy.logwarn( "SmachToMail timer publishes stop signal. Send Notification.") From 7e2aa482a867cb9d8d80feff6baddf7ac4c998f4 Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Wed, 16 Nov 2022 23:46:19 +0900 Subject: [PATCH 03/10] [jsk_robot_startup] Consolidate format about remove smach notification data --- jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py index 2fc8ff2f85..10ee525772 100755 --- a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py +++ b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py @@ -188,6 +188,7 @@ def _status_cb(self, msg): if self.use_google_chat: self._send_google_chat(self.smach_state_subject[caller_id], self.smach_state_list[caller_id]) self.smach_state_list[caller_id] = None + self.smach_state_subject[caller_id] = None def _send_mail(self, subject, state_list): email_msg = Email() From db3b9eadf2234c46aa540bef422f3d98803a1e1b Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Fri, 18 Nov 2022 18:52:26 +0900 Subject: [PATCH 04/10] [jsk_robot_startup] Use checking node status for timeout --- .../scripts/smach_to_mail.py | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py index 10ee525772..d33253d7a2 100755 --- a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py +++ b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py @@ -9,6 +9,7 @@ import os import pickle import rospy +import rosnode import sys from cv_bridge import CvBridge @@ -50,7 +51,6 @@ def __init__(self): self.bridge = CvBridge() self.smach_state_list = {} # for status list self.smach_state_subject = {} # for status subject - self.smach_start_time = {} self.timeout = rospy.get_param("~timeout", 1200) if rospy.has_param("~sender_address"): self.sender_address = rospy.get_param("~sender_address") @@ -78,22 +78,25 @@ def _stop_timer_cb(self, event): If smach does not go to finish/end state, this is forced to send notification. ''' - now = rospy.Time.now() rospy.logdebug("SmachToMail stop timer called") - if (self.smach_state_list and - self.smach_state_subject and - self.timeout is not None and - self.smach_start_time is not None): + if (self.smach_state_list and self.smach_state_subject): for key in self.smach_state_list.keys(): - if (now - self.smach_start_time[key]).to_sec() > self.timeout: - self._send_mail( - self.smach_state_subject[key], self.smach_state_list[key]) - self._send_twitter( - self.smach_state_subject[key], self.smach_state_list[key]) - self.smach_state_subject[key] = None - self.smach_state_list[key] = None + # Check node status and force to send notification + if not rosnode.rosnode_ping( + key, max_count=30, verbose=False): rospy.logwarn( "SmachToMail timer publishes stop signal. Send Notification.") + if self.use_mail: + self._send_mail( + self.smach_state_subject[key], self.smach_state_list[key]) + if self.use_twitter: + self._send_twitter( + self.smach_state_subject[key], self.smach_state_list[key]) + if self.use_google_chat: + self._send_google_chat( + self.smach_state_subject[key], self.smach_state_list[key]) + del self.smach_state_subject[key] + del self.smach_state_list[key] def _status_cb(self, msg): ''' @@ -135,7 +138,6 @@ def _status_cb(self, msg): # If we received START/INIT status, restart storing smach_state_list if status_str in ["START", "INIT"]: - self.smach_start_time[caller_id] = rospy.Time.now() self.smach_state_list[caller_id] = [] # DESCRIPTION of START is MAIL SUBJECT if 'DESCRIPTION' in local_data_str: From a9747dd7f5a8d88601308f3285a39224ec5c9717 Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Thu, 8 Dec 2022 18:53:17 +0900 Subject: [PATCH 05/10] [jsk_robot_startup] Display sendng gchat thread --- jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py index d33253d7a2..3cf5dd14c7 100755 --- a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py +++ b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py @@ -306,7 +306,7 @@ def _send_google_chat(self, subject, state_list): result = self.gchat_ac.get_result() if not self._gchat_thread: self._gchat_thread = result.message_result.thread_name - rospy.loginfo("Sending google chat messsage: {} to {} chat space".format(text, self.chat_space)) + rospy.loginfo("Sending google chat messsage:{} chat space, {} thread".format(self.chat_space, self._gchat_thread)) rospy.logdebug("Google Chat result: {}".format(self.gchat_ac.get_result())) if __name__ == '__main__': From 9efdbd20bb5ed971c2cb795633cc83d9d8d340bd Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Thu, 8 Dec 2022 14:42:53 +0900 Subject: [PATCH 06/10] [jsk_robot_startup] Enable to send notification in every transition --- .../scripts/smach_to_mail.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py index 3cf5dd14c7..62513386ae 100755 --- a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py +++ b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py @@ -13,6 +13,8 @@ import sys from cv_bridge import CvBridge +from dynamic_reconfigure.server import Server +from jsk_robot_startup.cfg import SmachNotificationReconfigureConfig from jsk_robot_startup.msg import Email from jsk_robot_startup.msg import EmailBody from sensor_msgs.msg import CompressedImage @@ -42,8 +44,12 @@ def __init__(self): self.use_twitter = rospy.get_param("~use_twitter", True) self.use_google_chat = rospy.get_param( "~use_google_chat", _enable_google_chat) + self.send_every_transition = rospy.get_param( + "~send_every_transition", False) self.pub_email = rospy.Publisher("email", Email, queue_size=10) self.pub_twitter = rospy.Publisher("tweet", String, queue_size=10) + self.reconfigure_server = Server( + SmachNotificationReconfigureConfig, self._reconfigure_cb) rospy.Subscriber( "~smach/container_status", SmachContainerStatus, self._status_cb) rospy.Timer(rospy.Duration( @@ -73,6 +79,18 @@ def __init__(self): self.gchat_image_dir = rospy.get_param("~google_chat_tmp_image_dir", "/tmp") self._gchat_thread = None + def _reconfigure_cb(self, config, level): + self.use_mail = config['use_mail'] + self.use_twitter = config['use_twitter'] + self.use_google_chat = config['use_google_chat'] + self.send_every_transition = config['send_every_transition'] + rospy.loginfo( + "Switched parameters; use_mail: {send_every_transition}, " + "use_twitter: {use_twitter}, " + "use_google_chat: {use_google_chat}, " + "send_every_transition: {send_every_transition}".format(**config)) + return config + def _stop_timer_cb(self, event): ''' If smach does not go to finish/end state, @@ -172,6 +190,13 @@ def _status_cb(self, msg): else: self.smach_state_list[caller_id].append(status_dict) + if self.send_every_transition: + if (self.use_google_chat + and not self.smach_state_list[caller_id] is None): + rospy.loginfo("Send every transition called") + self._send_google_chat( + self.smach_state_subject[caller_id], [status_dict]) + # If we received END/FINISH status, send email, etc... if status_str in ["END", "FINISH", "FINISH-SUCCESS", "FINISH-FAILURE"]: if (caller_id not in self.smach_state_list) or self.smach_state_list[caller_id] is None: @@ -187,7 +212,7 @@ def _status_cb(self, msg): self._send_mail(self.smach_state_subject[caller_id], self.smach_state_list[caller_id]) if self.use_twitter: self._send_twitter(self.smach_state_subject[caller_id], self.smach_state_list[caller_id]) - if self.use_google_chat: + if self.use_google_chat and not self.send_every_transition: self._send_google_chat(self.smach_state_subject[caller_id], self.smach_state_list[caller_id]) self.smach_state_list[caller_id] = None self.smach_state_subject[caller_id] = None From 79e27110c7dd5f45d44dda722901653660e4d285 Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Thu, 8 Dec 2022 21:28:15 +0900 Subject: [PATCH 07/10] [jsk_robot_startup] Remove rospy.get_param which uses dynamic_reconfigure --- jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py index 62513386ae..4f9e017f0b 100755 --- a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py +++ b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py @@ -40,12 +40,6 @@ def __init__(self): rospy.init_node('server_name') # it should be 'smach_to_mail', but 'server_name' # is the default name of smach_ros - self.use_mail = rospy.get_param("~use_mail", True) - self.use_twitter = rospy.get_param("~use_twitter", True) - self.use_google_chat = rospy.get_param( - "~use_google_chat", _enable_google_chat) - self.send_every_transition = rospy.get_param( - "~send_every_transition", False) self.pub_email = rospy.Publisher("email", Email, queue_size=10) self.pub_twitter = rospy.Publisher("tweet", String, queue_size=10) self.reconfigure_server = Server( From 46895dbcd24ec953a7ddb67c027e41af58e4494a Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Thu, 8 Dec 2022 21:29:08 +0900 Subject: [PATCH 08/10] [jsk_robot_startup] Combine two if to one --- .../jsk_robot_startup/scripts/smach_to_mail.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py index 4f9e017f0b..c98cadc1f0 100755 --- a/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py +++ b/jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py @@ -184,12 +184,13 @@ def _status_cb(self, msg): else: self.smach_state_list[caller_id].append(status_dict) - if self.send_every_transition: - if (self.use_google_chat - and not self.smach_state_list[caller_id] is None): - rospy.loginfo("Send every transition called") - self._send_google_chat( - self.smach_state_subject[caller_id], [status_dict]) + # send notification every transition + if (self.send_every_transition + and self.use_google_chat + and not self.smach_state_list[caller_id] is None): + rospy.loginfo("Send every transition called") + self._send_google_chat( + self.smach_state_subject[caller_id], [status_dict]) # If we received END/FINISH status, send email, etc... if status_str in ["END", "FINISH", "FINISH-SUCCESS", "FINISH-FAILURE"]: From d11c60cb70f34ebf9cbac8854a8759b3a26939b0 Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Thu, 8 Dec 2022 14:34:51 +0900 Subject: [PATCH 09/10] [jsk_robot_startup] Support dynamic reconfigure in smach_to_mail --- jsk_robot_common/jsk_robot_startup/CMakeLists.txt | 1 + .../cfg/SmachNotificationReconfigure.cfg | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 jsk_robot_common/jsk_robot_startup/cfg/SmachNotificationReconfigure.cfg diff --git a/jsk_robot_common/jsk_robot_startup/CMakeLists.txt b/jsk_robot_common/jsk_robot_startup/CMakeLists.txt index 76ce6de029..bf9d8a55cb 100644 --- a/jsk_robot_common/jsk_robot_startup/CMakeLists.txt +++ b/jsk_robot_common/jsk_robot_startup/CMakeLists.txt @@ -53,6 +53,7 @@ generate_dynamic_reconfigure_options( cfg/OdometryFeedbackWrapperReconfigure.cfg cfg/ConstantHeightFramePublisherReconfigure.cfg cfg/JointStatesThrottle.cfg + cfg/SmachNotificationReconfigure.cfg ) add_message_files( diff --git a/jsk_robot_common/jsk_robot_startup/cfg/SmachNotificationReconfigure.cfg b/jsk_robot_common/jsk_robot_startup/cfg/SmachNotificationReconfigure.cfg new file mode 100644 index 0000000000..0109f4b94d --- /dev/null +++ b/jsk_robot_common/jsk_robot_startup/cfg/SmachNotificationReconfigure.cfg @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +from dynamic_reconfigure.parameter_generator_catkin import * + +PKG = "jsk_robot_startup" + +gen = ParameterGenerator() + +gen.add("send_every_transition", bool_t, 0, "Send notification every transition", False) +gen.add("use_mail", bool_t, 0, "Use mail for smach notification", True) +gen.add("use_twitter", bool_t, 0, "Use twitter for smach notification", True) +gen.add("use_google_chat", bool_t, 0, "Use google chat for smach notification", True) + +exit(gen.generate(PKG, PKG, "SmachNotificationReconfigure")) From d2afba13096bae5096f1be3fa0b748a38104202d Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Fri, 9 Dec 2022 12:12:10 +0900 Subject: [PATCH 10/10] [jsk_robot_startup] Change permission of SmachNotificationReconfigure to avoid build error --- .../jsk_robot_startup/cfg/SmachNotificationReconfigure.cfg | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 jsk_robot_common/jsk_robot_startup/cfg/SmachNotificationReconfigure.cfg diff --git a/jsk_robot_common/jsk_robot_startup/cfg/SmachNotificationReconfigure.cfg b/jsk_robot_common/jsk_robot_startup/cfg/SmachNotificationReconfigure.cfg old mode 100644 new mode 100755