def goHome(self, stage): pysca.pan_tilt(1, 0, 0, blocking=True) pysca.pan_tilt(1, self.returnHomeSpeed, self.returnHomeSpeed, stage.homePan, stage.homeTilt, blocking=True) pysca.set_zoom(1, stage.homeZoom, blocking=True) self.atHome = True self.requestedZoomPos = stage.homeZoom time.sleep(self.homePauseSeconds)
def _main_loop(self): clock = pygame.time.Clock() prev_joystick_states = None prev_pressed_keys = None self.initialize_joystick_parameters() while self.keep_running: clock.tick(10) with self.state_read_lock: # self.joystick_states is updated by joystick_thread self.current_joystick_states = copy.deepcopy( self.joystick_states) self.pressed_keys = self.get_pressed_keys() # TODO not interested in pressed keys, but in found actions if prev_joystick_states == self.current_joystick_states and prev_pressed_keys == self.pressed_keys: continue prev_joystick_states = copy.deepcopy(self.current_joystick_states) prev_pressed_keys = copy.deepcopy(self.pressed_keys) ptz = self.get_ptz_from_axes() pan = ptz[0] tilt = ptz[1] zoom = ptz[2] actions = self.get_actions() actions = self.handle_zoom_and_focus(zoom, actions) modified = self.handle_pan_and_tilt(pan, tilt, actions) pan = modified[0] tilt = modified[1] actions = modified[2] # print("Actions: {}".format(actions)) # print("Pan: {}, tilt: {}".format(pan, tilt)) pysca.pan_tilt(1, pan=pan, tilt=tilt, blocking=True) for action, params in actions.iteritems(): handler = self.command_handlers.get(action) handler(action, **params)
def trackSubject(self, camera, stage, subject, face, faceCount): self.confidence = 100.0 / faceCount if faceCount else 0 self.subjectVolatile = subject.isVolatile() # Should we stay in motion? if self.confidence < self.minConfidence \ or not face.recentlyVisible \ or self.subjectVolatile \ or subject.isCentered: # Stop all tracking motion pysca.pan_tilt(1, 0, 0, blocking=True) # Should we return to home position? if not face.recentlyVisible \ and not self.atHome: self.goHome(camera, stage) return # Initiate no new tracking action unless face has been seen recently if not face.recentlyVisible: return # Adjust to tracking zoom and tilt (closer) if subject.isCentered \ and not self.subjectVolatile \ and self.requestedZoomPos > 0 \ and self.requestedZoomPos < stage.trackingZoom: pysca.pan_tilt(1, 0, 5, 0, stage.trackingTiltAdjustment, relative=True, blocking=True) pysca.set_zoom(1, stage.trackingZoom, blocking=True) self.requestedZoomPos = stage.trackingZoom if subject.isFarLeft: pysca.pan_tilt(1, -2) self.atHome = False elif subject.isFarRight: pysca.pan_tilt(1, 2) self.atHome = False return
def trackSubject(self, camera, stage, subject, face, faceCount): self.confidence = 100.0 / faceCount if faceCount else 0 self.subjectVolatile = subject.isVolatile() # Should we stay in motion? if self.confidence < self.minConfidence \ or not face.recentlyVisible \ or subject.isCentered: # Stop all tracking motion print "Stop tracking motion" pysca.pan_tilt(1, 0, 0, blocking=True) return # Should we return to home position? if not face.recentlyVisible and not self.atHome: print 'Go Home' self.goHome(stage) return # Initiate no new tracking action unless face has been seen recently if not face.recentlyVisible: return # Adjust to tracking zoom and tilt (closer) # if subject.isCentered \ # and self.requestedZoomPos > 0 \ # and self.requestedZoomPos < stage.trackingZoom: # pysca.pan_tilt(1, 0, 5, 0, stage.trackingTiltAdjustment, relative=True, blocking=True) # pysca.set_zoom(1, stage.trackingZoom, blocking=True) # self.requestedZoomPos = stage.trackingZoom SPEED = 10 speed_x = SPEED speed_y = SPEED if subject.offsetX + subject.offsetY > 0: speed_x = SPEED * (subject.offsetX / (subject.offsetX + subject.offsetY)) speed_y = SPEED * (subject.offsetY / (subject.offsetX + subject.offsetY)) speed_x = round(speed_x, 0) speed_y = round(speed_y, 0) # if self.REVERSE: # speed_x *= -1 # speed_y *= -1 # print 'Speed_x is:\t{}\tSpeed_y is:\t{}'.format(speed_x, speed_y) if subject.isFarLeft: if subject.isFarUp: print "Object left up" pysca.pan_tilt(1, -speed_x, +speed_y) elif subject.isFarDown: print "Object left down" pysca.pan_tilt(1, -speed_x, -speed_y) else: "Object left" pysca.pan_tilt(1, -SPEED) print 'Speed_x is:\t{}\tSpeed_y is:\t{}'.format(speed_x, speed_y) elif subject.isFarRight: if subject.isFarUp: print "Object right up" pysca.pan_tilt(1, speed_x, +speed_y) pass elif subject.isFarDown: print "Object right down" pysca.pan_tilt(1, speed_x, -speed_y) pass else: print "Object right" pysca.pan_tilt(1, SPEED) print 'Speed_x is:\t{}\tSpeed_y is:\t{}'.format(speed_x, speed_y) self.atHome = False return