diff --git a/lg_sv/scripts/server.py b/lg_sv/scripts/server.py index b7ef518c2..3bd563115 100755 --- a/lg_sv/scripts/server.py +++ b/lg_sv/scripts/server.py @@ -35,10 +35,31 @@ DEFAULT_NAV_INTERVAL = 0.02 DEFAULT_TICK_RATE = 180 DEFAULT_IDLE_TIME_UNTIL_SNAP = 1.25 +DEFAULT_FILTER_FUNCTION= "new_sv_filter" X_THRESHOLD = 0.50 NODE_NAME = 'pano_viewer_server' +def old_sv_filter(panoid): + rospy.logdebug('doing old_sv function') + if panoid[0:2] == 'F:' or len(panoid) >= 60: + rospy.logdebug('returning true for old_sv') + return True + rospy.logdebug('returning false for old_sv') + return False + +def new_sv_filter(panoid): + rospy.logdebug('doing new_sv function') + if panoid[0:2] != 'F:' and len(panoid) < 60: + rospy.logerr('returning true for new_sv') + return True + rospy.logdebug('returning false for new_sv') + return False + +def both_sv_filter(panoid): + return True + + def main(): rospy.init_node('pano_viewer_server', anonymous=True) server_type = rospy.get_param('~server_type', 'streetview') @@ -66,8 +87,16 @@ def main(): tick_rate = rospy.get_param('~tick_rate', DEFAULT_TICK_RATE) idle_time_until_snap = rospy.get_param('~idle_time_until_snap', DEFAULT_IDLE_TIME_UNTIL_SNAP) + filter_functions = { + "old_sv_filter": old_sv_filter, + "new_sv_filter": new_sv_filter, + "both_sv_filter": both_sv_filter + } + sv_filter = rospy.get_param('~sv_filter', DEFAULT_FILTER_FUNCTION) + filter_function = filter_functions.get(sv_filter, new_sv_filter) + server = PanoViewerServer(location_pub, panoid_pub, pov_pub, tilt_min, tilt_max, - nav_sensitivity, space_nav_interval, idle_time_until_snap, x_threshold, + nav_sensitivity, space_nav_interval, idle_time_until_snap, filter_function, x_threshold, nearby, metadata_pub, zoom_max, zoom_min, tick_rate, director_pub=director_pub, server_type=server_type) @@ -77,7 +106,7 @@ def main(): server.handle_location_msg) rospy.Subscriber('/%s/metadata' % server_type, String, server.handle_metadata_msg) - rospy.Subscriber('/%s/panoid' % server_type, String, + rospy.Subscriber('/%s/panoid' % server_type.replace('_old', ''), String, server.handle_panoid_msg) rospy.Subscriber('/%s/pov' % server_type, Quaternion, server.handle_pov_msg) @@ -96,8 +125,10 @@ def main(): def handle_director_message(scene): rospy.loginfo('running handle director w/ scene: %s' % scene) _server_type = server_type + # streetview_old isn't an activity type, so check for "streetview" instead if _server_type == 'streetview_old': _server_type = 'streetview' + # check that director emssage has our activity _server_type or return has_asset = has_activity(scene, _server_type) has_no_activity = has_activity(scene, 'no_activity') if has_no_activity: @@ -107,21 +138,14 @@ def handle_director_message(scene): rospy.loginfo('hiding self') visibility_publisher.publish(ApplicationState(state='HIDDEN')) return + if scene.get('slug', '') == 'auto_generated_sv_scene': rospy.loginfo("Ignoring my own generated message") asset = get_activity_config_from_activity(scene, _server_type) panoid = asset.get('panoid', '') - rospy.logerr("length of panoid is %s server type %s" % (len(panoid), server_type)) - rospy.logerr("panoid is %s" % panoid) - if server_type == 'streetview' and (panoid[0:2] != 'F:' and len(panoid) < 60): - visibility_publisher.publish(ApplicationState(state='VISIBLE')) - rospy.logerr("publishing visible for {}".format(server_type)) - return - elif server_type == 'streetview_old' and (panoid[0:2] == 'F:' or len(panoid) >= 60): - rospy.logerr("publishing visible for {}".format(server_type)) - visibility_publisher.publish(ApplicationState(state='VISIBLE')) - return - elif server_type == 'panoviewer' or server_type == 'panovideo': + rospy.logdebug("length of panoid is %s server type %s" % (len(panoid), server_type)) + rospy.logdebug("panoid is %s" % panoid) + if filter_function(panoid): visibility_publisher.publish(ApplicationState(state='VISIBLE')) return visibility_publisher.publish(ApplicationState(state='HIDDEN')) @@ -130,11 +154,8 @@ def handle_director_message(scene): if server_type == 'streetview' or server_type == 'streetview_old': asset = get_activity_config_from_activity(scene, server_type) panoid = asset.get('panoid', '') - if server_type == 'streetview' and panoid[0:2] == 'F:': - rospy.logerr("leaving early for {}".format(server_type)) - return - elif server_type == 'streetview_old' and panoid[0:2] != 'F': - rospy.logerr("leaving early for {}".format(server_type)) + if not filter_function(panoid): + # TODO maybe hide? return else: panoid = scene['windows'][0]['assets'][0] diff --git a/lg_sv/src/lg_sv/server.py b/lg_sv/src/lg_sv/server.py index e9130a323..14184e2a6 100644 --- a/lg_sv/src/lg_sv/server.py +++ b/lg_sv/src/lg_sv/server.py @@ -118,10 +118,10 @@ def translate_server_metadata_to_client_form(metadata): class PanoViewerServer: def __init__(self, location_pub, panoid_pub, pov_pub, tilt_min, tilt_max, - nav_sensitivity, space_nav_interval, idle_time_until_snap, + nav_sensitivity, space_nav_interval, idle_time_until_snap, filter_function, x_threshold=X_THRESHOLD, nearby_panos=NearbyPanos(), metadata_pub=None, zoom_max=ZOOM_MAX, zoom_min=ZOOM_MIN, - tick_rate=180, director_pub=None, server_type=""): + tick_rate=180, director_pub=None, server_type="" ): self.location_pub = location_pub self.panoid_pub = panoid_pub self.pov_pub = pov_pub @@ -141,6 +141,7 @@ def __init__(self, location_pub, panoid_pub, pov_pub, tilt_min, tilt_max, self.tick_rate = tick_rate self.gutter_val = 0.0005 self.tick_period = 1.0 / float(self.tick_rate) + self.filter_function = filter_function self.state = True @@ -290,7 +291,9 @@ def handle_panoid_msg(self, panoid): Grabs the new panoid from a publisher """ # Nothing to do here... + rospy.logdebug('handling panoid for {}'.format(self.server_type)) if self.panoid == panoid.data: + rospy.logdebug('self.panoid was equal to panoid.data {}'.format(self.server_type)) self.nearby_panos.set_panoid(self.panoid) return self.generate_director_message(panoid.data) @@ -302,11 +305,10 @@ def generate_director_message(self, panoid, pov=None): if panoid == self.panoid: return server_type = self.server_type - if server_type == 'streetview' or server_type == 'streetview_old': - if panoid[0:2] == 'F:': - server_type = 'streetview_old' - else: - server_type = 'streetview' + rospy.logdebug('about to filter for {}'.format(server_type)) + if not self.filter_function(panoid): + rospy.logerr('error in filter function... returning {}'.format(server_type)) + return msg = GenericMessage() msg.type = 'json' if pov: @@ -319,7 +321,7 @@ def generate_director_message(self, panoid, pov=None): "slug": "auto_generated_sv_scene", "windows": [ { - "activity": self.server_type, + "activity": server_type.replace('_old', ''), "assets": [ panoid ],