Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic/cleanup sv #395

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions lg_sv/scripts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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'))
Expand All @@ -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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

return
else:
panoid = scene['windows'][0]['assets'][0]
Expand Down
18 changes: 10 additions & 8 deletions lg_sv/src/lg_sv/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
],
Expand Down