visualize_move_base.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # Author: Yuki Furuta <furushchev@jsk.imi.i.u-tokyo.ac.jp>
00004 
00005 import rospy
00006 from mongodb_store.message_store import MessageStoreProxy
00007 from posedetection_msgs.msg import Object6DPose
00008 from visualization_msgs.msg import MarkerArray
00009 from geometry_msgs.msg import TransformStamped
00010 from datetime import datetime, timedelta
00011 import tf
00012 
00013 from transform_utils import TransformationUtils as T
00014 from visualization_utils import VisualizationUtils as V
00015 
00016 class DBPlay(object):
00017     def __init__(self):
00018         self.db_name = rospy.get_param('~db_name','jsk_robot_lifelog')
00019         self.col_name = rospy.get_param('~col_name', 'pr1012')
00020         self.use_ros_time = rospy.get_param('~use_ros_time', True)
00021         self.use_sim_time = rospy.get_param('use_sim_time', False)
00022         self.downsample = rospy.get_param("~downsample", 3)
00023         self.label_downsample = rospy.get_param("~label_downsample", 10)
00024         self.duration = rospy.get_param('~duration', 10) # days
00025         self.limit = rospy.get_param("~limit", 1000)
00026         self.msg_store = MessageStoreProxy(database=self.db_name,
00027                                            collection=self.col_name)
00028         rospy.loginfo("connected to %s.%s" % (self.db_name, self.col_name))
00029         self.pub = rospy.Publisher('/move_base_marker_array', MarkerArray)
00030         self.marker_count = 0
00031 
00032     def run(self):
00033         while not rospy.is_shutdown():
00034             rospy.loginfo("$gt: %d" % (rospy.Time.now().secs - self.duration * 60 * 60 * 24))
00035             if self.use_ros_time or self.use_sim_time:
00036                 rospy.loginfo("fetching data")
00037                 trans = self.msg_store.query(type=TransformStamped._type,
00038                                              message_query={"header.stamp.secs": {
00039                                                  "$lte": rospy.Time.now().secs,
00040                                                  "$gt": rospy.Time.now().secs - self.duration * 60 * 60 * 24
00041                                              }},
00042                                              sort_query=[("$natural", 1)],
00043                                              limit=self.limit)
00044             else:
00045                 trans = self.msg_store.query(type=TransformStamped._type,
00046                                              meta_query={"inserted_at": {
00047                             "$gt": datetime.utcnow() - timedelta(days=self.duration)
00048                             }},
00049                                              sort_query=[("$natural", 1)])
00050             rospy.loginfo("found %d msgs" % len(trans))
00051             m_arr = MarkerArray()
00052             m_arr.markers = V.transformStampedArrayToLabeledLineStripMarker(trans[::self.downsample], label_downsample=self.label_downsample, discrete=True)
00053             m_arr.markers = V.transformStampedArrayToLabeledArrayMarker(trans[::self.downsample], label_downsample=self.label_downsample, discrete=True)
00054             self.pub.publish(m_arr)
00055             rospy.sleep(1.0)
00056             rospy.loginfo("publishing move_base_marker_array")
00057 
00058 
00059 if __name__ == '__main__':
00060     rospy.init_node('visualize_move_base')
00061     o = DBPlay()
00062     o.run()


jsk_pr2_startup
Author(s):
autogenerated on Sat Jul 1 2017 02:43:24