def shutdown_handler():
	""" Allows the Baxter to move to home position and disable its motors once 
	shutdown is called. """
	robot = Baxter()
	print "Exiting system..."
	if not robot._rs.state().enabled:
		robot.clean_shutdown()
	robot._rs.disable()
	return True
	def execute(self, userdata):
		global p
		c_goal = userdata.goal_from_ui
		c_result = userdata.result_for_ui
		robot = Baxter()

		if c_goal.ui_command.command == bdm.GetUserCommand.CANCEL_DEMO:
			if p is not None:
				nxr.terminate_process_and_children(p)
				p = None
				robot.set_neutral()
				c_result.sys_result.result = bdm.GetResult.DEMO_TERMINATED
				return 'demo_terminated'

		else:
			return 'different_request'
	def execute(self, userdata):
		hp_goal = userdata.goal_from_ui
		hp_result = userdata.result_for_ui
		robot = Baxter()

		if hp_goal.ui_command.command == bdm.GetUserCommand.MOVE_TO_HOME_POSITION:

			hp_start_time = rospy.Time.now().secs
			while rospy.Time.now().secs - hp_start_time < 10:
				if robot.set_neutral():
					hp_result.sys_result.result = bdm.GetResult.IS_IN_HOME_POSE
					return 'in_home'

			hp_result.sys_result.result = bdm.GetResult.IS_ABORTED
			return 'aborted'

		else:
			return 'different_request'
	def execute(self, userdata):
		idle_goal = userdata.goal_from_ui
		idle_result = userdata.result_for_ui
		robot = Baxter()

		if idle_goal.ui_command.command == bdm.GetUserCommand.MOVE_TO_IDLE_MODE:

			idle_start_time = rospy.Time.now().secs 
			while rospy.Time.now().secs - idle_start_time < 10:
				if robot._rs.state().enabled:
					robot.clean_shutdown()
					rospy.sleep(6)  # Wait for the robot to move arms to both sides and set the result field
					idle_result.sys_result.result = bdm.GetResult.IS_IN_IDLE_MODE
					return 'in_idle'
				robot.disable()
				idle_result.sys_result.result = bdm.GetResult.IS_IN_IDLE_MODE			
				return 'in_idle'

			idle_result.sys_result.result = bdm.GetResult.IS_ABORTED
			return 'aborted'

		else:
			return 'different_request'