Beispiel #1
0
    def look_at_object(self):
        """Look at the object in Nao's hand.
        If we lose the object while we're inspecting it...
        - new grasp_status is 'absent'
        - we stop the animation and say something about losing it
        - restart the grasp demo
        Otherwise wait for the animation to finish (fut.wait)
        """
        self.logger.debug('call look_at_object')
        if not self.run:
            return
        object_dropped = qi.Promise()
        self.thinking_sound_fut_1 = None
        self.thinking_sound_fut_2 = None

        def handle_object_dropped(object_dropped, stat):
            """Handle the object being dropped."""
            self.logger.debug('call handle_object_dropped: {}'.format(stat))
            if not self.run:
                return
            if stat == 'absent':
                self.logger.warning('grasped object was dropped!')
                object_dropped.setValue(1)

        utils.nearly_close_hand(self, 'RHand')
        signal = utils.start_monitoring_grasp_status(self.sesh, 'present')
        signal.connect(partial(handle_object_dropped, object_dropped))
        self.anim = random.randint(1, 3)

        def inspect_object(object_dropped):
            """Observe the object with ooohs and ahhhs."""
            if not self.run:
                return
            self.thinking_sound_fut_1 = utils.play_rand_thinking_sound(self, 1.5)
            self.thinking_sound_fut_2 = utils.play_rand_thinking_sound(self, 5)
            self.run_anim('ObserveObject{}'.format(self.anim))
            try:
                object_dropped.setValue(0)
            except RuntimeError:
                self.logger.warning('"ObserveObject" animation was canceled ' +
                                    'because object was dropped.')

        qi.async(inspect_object, object_dropped)

        if object_dropped.future().value() == 1:  # dropped the object
            self.thinking_sound_fut_1.cancel()
            self.thinking_sound_fut_2.cancel()
            self.stop_anim('ObserveObject{}'.format(self.anim))
            self.say_and_animate('ohno', 'Grasping', 'LostIt')
            return False
        else:  # done looking at the object
            utils.stop_monitoring_grasp_status()
            return True
Beispiel #2
0
    def stop_all(self):
        """Stop all active processes and handle fall."""
        self.run = False

        # Stop all processes, cancel promises, disconnect callbacks
        try:
            utils.stop_monitoring_arm_move()
            utils.stop_monitoring_grasp_status()
            utils.stop_periodic_say()
        except AttributeError:
            pass
        try:
            self.thinking_sound_fut_1.cancel()
        except (AttributeError, RuntimeError):
            pass
        try:
            self.thinking_sound_fut_2.cancel()
        except (AttributeError, RuntimeError):
            pass
        try:
            self.grasp_object.setCanceled()
            self.grasp_object = None
        except (AttributeError, RuntimeError):
            pass
        try:
            self.stop_sub.signal.disconnect(self.stop_sub_id)
        except:
            pass
        try:
            self.fall_sub.signal.disconnect(self.fall_sub_id)
        except:
            pass

        # Handle a fall: quit app
        if self.fell:
            self.logger.debug('handling fall...')
            time.sleep(3)
            self.stand_up(3)
            self.box.onStopped(1)

        # UGH: be robust to launching from Choregraphe without life
        elif self.memory.getData('AutonomousLife/State') == 'disabled':
            self.motion.setBreathEnabled('Legs', False)
            self.motion.setIdlePostureEnabled('Body', True)
            self.stand_up(3)
Beispiel #3
0
 def handle_arm_moved(object_dropped, value):
     self.logger.debug('call handle_arm_moved')
     if not self.run:
         return
     utils.stop_monitoring_grasp_status()
     object_dropped.setValue(1)