Example #1
0
 def close_and_check_hand(value):
     self.logger.debug('call close_and_check_hand')
     if not self.run:
         return
     utils.nearly_close_hand(self, 'RHand')
     signal = utils.start_monitoring_grasp_status(self.sesh, 'moving')
     signal.connect(grasp_status_changed)
Example #2
0
 def grasp_status_changed(object_dropped, stat):
     self.logger.debug('call grasp_status_changed: {}'.format(stat))
     if not self.run:
         return
     utils.nearly_close_hand(self, 'RHand')
     if stat == 'absent':
         utils.stop_monitoring_arm_move()
         object_dropped.setValue(1)
Example #3
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