示例#1
0
def testNaoConnection(NAOip, NAOport):
    worked = False
    try:
        print NAOip, NAOport
        # naoBehavior = connectToProxy(NAOip, NAOport, "ALBehaviorManager")
        # names = naoBehavior.getInstalledBehaviors()
        # print "Names: ", names
    
        naoMotions = BasicMotions(NAOip, NAOport)
        print "Made Basic Motions"
        naoMotions.naoSay("Connected!")
        # naoMotions.naoSit()
        # naoMotions.naoShadeHeadSay("Hello, the connection worked!")

        testExpressions = False
        if testExpressions:
            genUtil = GenUtil(naoMotions)
            genUtil.testExpressions()

        worked = True
    except Exception as e:
        print "Connection Failed, maybe wrong IP and/or Port"
        print e
        
    print "Connection Test Finished"
    return worked
示例#2
0
def main(NAOip, NAOport, name):

    print "***************************************************************************"
    print "***************************************************************************"
    print "Have You updated the _FSM_INPUT File for this interaction? (1) yes, (2) no: ",
    textInput = str(raw_input()).lower()
    print "***************************************************************************"

    if textInput == "1":
        naoMotions = BasicMotions(NAOip, NAOport)
        robotName = name
        genUtil = GenUtil(naoMotions)
        genUtil.showFoodDB()

        myBroker = ALBroker("myBroker", "0.0.0.0", 0, NAOip, NAOport)
        global naoReactionChecker
        naoReactionChecker = NAOReactionChecker.NAOReactionChecker(genUtil, NAOip, NAOport)

        thread1 = ThreadedChecker(1, "Main Checker #1", genUtil)
        thread2 = UserAffectGenerator(2, "User Affect Generator #1", 3, genUtil)

        dateTime = genUtil.getDateTime()
        [userName, userNumber, activityInteractionType, lastInteraction] = getFSMInputVars()

        userInfo = initiateUserInfo(userName, userNumber, activityInteractionType, dateTime)

        # runSomeTest(genUtil)

        genUtil.showHappyEyes()
        # naoMotions.naoSit()
        print "NAO is currently: ", naoMotions.getPostureFamily()
        speed = 0.2
        if naoMotions.getPostureFamily() == "Sitting":
            speed = 0.7

        global sitTest
        sitTest = False
        if not sitTest:
            naoMotions.naoStand(speed)
        # naoMotions.naoWaveBoth()
        naoMotions.naoAliveON()

        # ============================================================= Start Functionality
        print("State Machine Started")
        print
        print
        thread1.start()
        # thread2.start()

        dietFitnessFSM = DietFitnessFSM(genUtil, robotName, userName, userNumber, activityInteractionType, lastInteraction)
        [currentState, robotEmotionNum, obserExpresNum] = dietFitnessFSM.getFSMState()

        appraiseState = False
        user_input = "Start"
        while currentState != 0:
            print("=========================================================================================")
            print "FSM Info: ", [currentState, robotEmotionNum, obserExpresNum]
            if appraiseState:
                genUtil.expressEmotion(obserExpresNum)

            [currentState, robotEmotionNum, obserExpresNum, appraiseState] = dietFitnessFSM.activityFSM()
        thread1.quit()
        # thread2.quit()
        genUtil.naoTurnOffEyes()
        # naoMotions.naoSit()
        NAOReactionChecker.ActuallyUnsubscribeAllEvents()
        myBroker.shutdown()
        naoMotions.naoAliveOff()

        print
        [stateTimeStamp, stateDateTime, fsmStateHist,
         reHist, oeHist, driveStatHist, fsmStateNameHist] = dietFitnessFSM.getHistories()
        print "History of TimeStamps: ", stateTimeStamp
        print "History of DateTimes: ", stateDateTime
        print "History of FSM States: ", fsmStateHist
        print "History of FSM State Names: ", fsmStateNameHist
        print "History of Robot Emotions: ", reHist
        print "History of Observable Expressions: ", oeHist
        print "History of Drive Statuses: ", driveStatHist
        writeUserHistories(userName, userNumber, userInfo, dateTime,
                           stateTimeStamp, stateDateTime, fsmStateHist, reHist, oeHist, driveStatHist, fsmStateNameHist)

    else:
        print "Go updated the input file for this interaction"
        print "It can be found at: ProgramDataFiles\_FSM_INPUT.json"

    print
    print("State Machine Finished")