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)
def grasp_status_changed(stat): self.logger.debug('call grasp_status_changed: {}'.format(stat)) if not self.run: return utils.stop_periodic_say() if stat == 'present': self.motion.stiffnessInterpolation("RArm", 1.0, 0.5) self.say_and_animate('thanks', 'Grasping', 'ThankYou') self.grasp_object.setValue(1) elif stat == 'absent': self.say_and_animate('missed', 'Grasping', 'Missed') self.run_anim('OpenHand') self.motion.stiffnessInterpolation("RArm", 1.0, 0.5) self.missed_count += 1 if self.missed_count >= 3: self.grasp_object.setCanceled() else: self.run_anim('ExtendHand') self.wait_for_object()