Skip to content

Commit

Permalink
add launch/aibo_example.launch to work with ./make_aibo_diary.py --test
Browse files Browse the repository at this point in the history
  • Loading branch information
k-okada committed Nov 28, 2023
1 parent fb3921c commit e9debce
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
41 changes: 41 additions & 0 deletions database_talker/aibo.rosinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# database talker for aibo
- git:
local-name: jsk_demos
uri: https://github.com/sktometometo/jsk_demos
version: PR/hoge-py
# use k-okada' version of aibo_driver (for message)
- git:
local-name: aibo_driver
uri: https://gitlab.jsk.imi.i.u-tokyo.ac.jp/k-okada/aibo_status
version: driver
#
# use latest google_chat_ros, until noetic is synced
# armhf users need to use https://github.com/k-okada/jsk_3rdparty/commit/8524aaa4118cb7ab02c65f47c46343bbb4f7147c
# rosinstall_generator google_chat_ros --rosdistro noetic
#
- git:
local-name: google_chat_ros
uri: https://github.com/tork-a/jsk_3rdparty-release.git
version: release/noetic/google_chat_ros/2.1.28-1
#
# use latest jsk_recognition_msgs, until noetic is synced
#
- git:
local-name: jsk_recognition/jsk_recognition_msgs
uri: https://github.com/tork-a/jsk_recognition-release.git
version: release/noetic/jsk_recognition_msgs/1.2.17-1
#
# need releasing
# https://github.com/davesarmoury/openai_ros/pulls?q=is%3Apr
#
- git:
local-name: openai_ros
uri: https://github.com/davesarmoury/openai_ros
#
# add sample launch code for database_talker #1792
# https://github.com/jsk-ros-pkg/jsk_robot/pull/1792
#
- git:
local-name: jsk_robot
uri: https://github.com/k-okada/jsk_robot.git
version: ichikura_sample
19 changes: 19 additions & 0 deletions database_talker/launch/aibo_example.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<launch>
<arg name="openai_credentials_json" default="$(find aibo_driver)/auth/openai_credentials.json" />
<param name="robot/name" value="aibo" />


<param name="mongodb_host" value="musca.jsk.imi.i.u-tokyo.ac.jp" />
<param name="mongodb_port" value="27017" />
<node name="message_store" pkg="mongodb_store" type="message_store_node.py" >
<param name="mongodb_use_localdatacenter" value="false" />
<param name="queue_size" value="100" />
</node>

<!-- openai -->
<group ns="openai">
<node pkg="openai_ros" type="openai_node.py" name="openai" output="screen" >
<rosparam command="load" file="$(arg openai_credentials_json)" />
</node>
</group>
</launch>
22 changes: 16 additions & 6 deletions database_talker/scripts/make_aibo_diary.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

class MessageListener(object):

def __init__(self):
def __init__(self, wait_for_chat_server=True):
#self.pickle_file = tempfile.NamedTemporaryFile(suffix='.pickle')
self.pickle_file = "/tmp/activities.pickle"
self.robot_name = rospy.get_param('robot/name')
Expand All @@ -69,7 +69,8 @@ def __init__(self):

rospy.loginfo("wait for '/google_chat_ros/send'")
self.chat_ros_ac = actionlib.SimpleActionClient('/google_chat_ros/send', SendMessageAction)
self.chat_ros_ac.wait_for_server()
if wait_for_chat_server:
self.chat_ros_ac.wait_for_server()

rospy.loginfo("wait for '/message_store/query_messages'")
rospy.wait_for_service('/message_store/query_messages')
Expand Down Expand Up @@ -242,8 +243,12 @@ def make_image_activities(self, mongo_data_days = None):
for mongo_data in mongo_data_days:
rospy.loginfo("Found {} mongo data".format(len(mongo_data)))
mongo_data_type = list(set([meta['stored_type'] for _, meta in mongo_data]))
if (len(mongo_data)) > 0:
from_date = datetime.datetime.fromtimestamp(mongo_data[-1][1]['timestamp']//1000000000, JST)
to_date = datetime.datetime.fromtimestamp(mongo_data[0][1]['timestamp']//1000000000, JST)
rospy.logwarn(" period : {} {}".format(from_date, to_date))
if len(mongo_data_type) > 1 and 'jsk_recognition_msgs/VQATaskActionResult' in mongo_data_type:
rospy.loginfo("Found {} image data".format(len(list(filter(lambda x: 'jsk_recognition_msgs/VQATaskActionResult' in x['stored_type'], [meta for _, meta in mongo_data])))))
rospy.loginfo(" : {} image data".format(len(list(filter(lambda x: 'jsk_recognition_msgs/VQATaskActionResult' in x['stored_type'], [meta for _, meta in mongo_data])))))
image_activities = {}
for msg, meta in mongo_data:
if meta['stored_type'] == 'jsk_recognition_msgs/VQATaskActionResult':
Expand All @@ -252,7 +257,11 @@ def make_image_activities(self, mongo_data_days = None):
answer = msg.result.result.result[0].answer
if len(answer.split()) > 3 and answer not in image_activities.keys():
image_activities.update({answer : timestamp})
break
if (len(image_activities)) > 0:
break
else:
rospy.logwarn(" no valid image description is found...")

#
prompt = "From the list below, please select the most memorable and illuminating event by number.\n\n"
n = 0
Expand Down Expand Up @@ -753,8 +762,9 @@ def cb(self, msg):
logger = logging.getLogger('rosout')
logger.setLevel(rospy.impl.rosout._rospy_to_logging_levels[rospy.DEBUG])

ml = MessageListener()
ml = MessageListener(wait_for_chat_server=not args.test)
if args.test:
ml.make_diary()
ret = ml.make_diary()
rospy.loginfo("image is saved at {}".format(ret['filename']))
sys.exit(0)
rospy.spin()

0 comments on commit e9debce

Please sign in to comment.