Skip to content

Commit

Permalink
add more typecheck, use rospy.loginfo for message
Browse files Browse the repository at this point in the history
  • Loading branch information
k-okada authored and knorth55 committed Aug 26, 2022
1 parent 1be6c98 commit fa0f2f5
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions jsk_robot_common/jsk_robot_startup/scripts/smach_to_mail.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,27 @@ def _status_cb(self, msg):
'''
Recording starts when smach_state becomes start.
'''
rospy.loginfo("Received SMACH status")
if len(msg.active_states) == 0:
return
file_path = None
status_str = ', '.join(msg.active_states);
local_data_str = pickle.loads(msg.local_data)
info_str = msg.info
print("status -> {}".format(status_str))
print("description_str -> {}".format(local_data_str['DESCRIPTION']))
if not type(local_data_str) is dict:
rospy.logerr("local_data_str:({}) is not dictionary".format(local_data_str))
rospy.logerr("May be you forget to pass user data in exec-state-machine ?")
rospy.logerr("please check your program execute smach with (exec-state-machine (sm) '((description . "")(image . "")))")

rospy.loginfo("- status -> {}".format(status_str))
if local_data_str.has_key('DESCRIPTION'):
rospy.loginfo("- description_str -> {}".format(local_data_str['DESCRIPTION']))
else:
rospy.logwarn("smach does not have DESCRIPTION, see https://github.com/jsk-ros-pkg/jsk_robot/tree/master/jsk_robot_common/jsk_robot_startup#smach_to_mailpy for more info")

if status_str == "START" or "INIT":
self.smach_state_list = []
if local_data_str['IMAGE']:
if local_data_str.has_key('IMAGE') and local_data_str['IMAGE']:
imgmsg = CompressedImage()
imgmsg.deserialize(base64.b64decode(local_data_str['IMAGE']))
cv_image = self.bridge.compressed_imgmsg_to_cv2(imgmsg, "bgr8")
Expand All @@ -54,7 +63,7 @@ def _status_cb(self, msg):

file_path = "/tmp/{}_{}.jpg".format(
status_str.lower(), dt_now.strftime('%y%m%d%H%M%S'))
rospy.loginfo("filepath:{}".format(file_path))
rospy.loginfo("- filepath:{}".format(file_path))
# if (next((x for x in self.smach_state_list if x["IMAGE"] == file_path), None)):
# rospy.loginfo("same file name!!!!")
# else:
Expand All @@ -65,13 +74,16 @@ def _status_cb(self, msg):
else:
file_path = ""

status_dict = {'DESCRIPTION': local_data_str['DESCRIPTION'],
'IMAGE': file_path} # dict is complicated?
status_dict = {}
if local_data_str.has_key('DESCRIPTION'):
status_dict.update({'DESCRIPTION': local_data_str['DESCRIPTION']})
if file_path != "":
status_dict.update({'IMAGE': file_path}) # dict is complicated?

self.smach_state_list.append(status_dict)
print(self.smach_state_list)
print("info_str -> {}".format(info_str))
rospy.loginfo("- info_str -> {}".format(info_str))

if status_str == "END" or "FINISH":
if status_str in ["END", "FINISH"]:
rospy.loginfo("END!!")
self._send_mail()

Expand All @@ -85,10 +97,11 @@ def _send_mail(self):
description = EmailBody()
image = EmailBody()
description.type = 'text'
description.message = x['DESCRIPTION']
if x.has_key('DESCRIPTION'):
description.message = x['DESCRIPTION']
email_msg.body.append(description)
email_msg.body.append(changeline)
if x['IMAGE']:
if x.has_key('IMAGE') and x['IMAGE']:
image.type = 'img'
image.img_size = 50
image.file_path = x['IMAGE']
Expand Down

0 comments on commit fa0f2f5

Please sign in to comment.