Skip to content

Commit

Permalink
[jsk_robot_startup] add launch file for smach_to_mail
Browse files Browse the repository at this point in the history
  • Loading branch information
mqcmd196 committed Aug 27, 2022
1 parent 9bc7865 commit 011167e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
27 changes: 27 additions & 0 deletions jsk_robot_common/jsk_robot_startup/launch/smach_to_mail.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<launch>
<arg name="use_mail" default="true" />
<arg name="use_twitter" default="true" />
<arg name="use_google_chat" default="true" />
<arg name="email_sender_address" default="" />
<arg name="email_receiver_address" default="" />
<arg name="google_chat_space" default="" />
<arg name="namespace" default="smach_to_mail" />

<group if="$(arg use_mail)" ns="$(arg namespace)">
<param name="sender_address" value="$(arg email_sender_address)" />
<param name="receiver_address" value="$(arg email_reveiver_address)" />
</group>
<group if="$(arg use_google_chat)" ns="$(arg namespace)">
<param name="google_chat_space" value="$(arg google_chat_space)" />
</group>

<node name="$(arg namespace)" pkg="jsk_robot_startup" type="smach_to_mail.py" output="screen">
<rosparam subst_value="true">
use_mail: $(arg use_mail)
use_twitter: $(arg use_twitter)
use_google_chat: $(arg use_google_chat)
</rosparam>
</node>

</launch>
30 changes: 15 additions & 15 deletions jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ 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", True)
self.pub_email = rospy.Publisher("email", Email, queue_size=10)
self.pub_twitter = rospy.Publisher("tweet", String, queue_size=10)
rospy.Subscriber(
Expand All @@ -47,20 +50,14 @@ def __init__(self):
self.sender_address = self.email_info['sender_address']
self.receiver_address = self.email_info['receiver_address']
else:
if rospy.has_param("~sender_address"):
if self.use_mail:
self.sender_address = rospy.get_param("~sender_address")
else:
rospy.logerr("Please set rosparam {}/sender_address".format(
rospy.get_name()))
if rospy.has_param("~receiver_address"):
self.receiver_address = rospy.get_param("~receiver_address")
else:
rospy.logerr("Please set rosparam {}/receiver_address".format(
rospy.get_name()))
self.gchat_ac = actionlib.SimpleActionClient("/google_chat_ros/send", SendMessageAction)
self.chat_space = rospy.get_param("~google_chat_space", "spaces/AAAARE9CrfA") # default: fetch threaded space
self.gchat_image_dir = rospy.get_param("~google_chat_tmp_image_dir", "/tmp")
self._gchat_thread = None
if self.use_google_chat:
self.gchat_ac = actionlib.SimpleActionClient("/google_chat_ros/send", SendMessageAction)
self.chat_space = rospy.get_param("~google_chat_space")
self.gchat_image_dir = rospy.get_param("~google_chat_tmp_image_dir", "/tmp")
self._gchat_thread = None

def _status_cb(self, msg):
'''
Expand Down Expand Up @@ -142,9 +139,12 @@ def _status_cb(self, msg):
for x in self.smach_state_list[caller_id]:
rospy.loginfo(" - At {}, Active state is {}{}".format(x['TIME'], x['STATE'],
"({})".format(x['INFO']) if x['INFO'] else ''))
self._send_mail(self.smach_state_subject[caller_id], self.smach_state_list[caller_id])
self._send_twitter(self.smach_state_subject[caller_id], self.smach_state_list[caller_id])
self._send_google_chat(self.smach_state_subject[caller_id], self.smach_state_list[caller_id])
if self.use_mail:
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:
self._send_google_chat(self.smach_state_subject[caller_id], self.smach_state_list[caller_id])
self.smach_state_list[caller_id] = None

def _send_mail(self, subject, state_list):
Expand Down

0 comments on commit 011167e

Please sign in to comment.