Exemplo n.º 1
0
def test_nodes(Sample_Blackboard):

    # Create nodes
    print('\n\n     Let us start testing our basic node types')
    test_node_1 = task('Enter Carm', None, None, None)
    test_node_2 = task('Find Pizza', 'recive', 'PIZZA_LOCATION', None)
    test_node_3 = task('Eat Pizza', 'write', 'EAT_PIZZA', True)
    Condition_1 = condition('EAT_PIZZA')
    test_stack = []

    #Execute nodes and see if they work or not
    print('\n     Let us see if our pizza condition is corretly false:')
    if Condition_1.execute(Sample_Blackboard, test_stack) == 'FAILED':
        print('Condition is False!')
    print('\n     Now let us see our nodes run as expected:')
    if test_node_1.execute(Sample_Blackboard, test_stack) == 'SUCCEEDED':
        print('  Node 1 worked')
    if test_node_2.execute(Sample_Blackboard, test_stack) == 'SUCCEEDED':
        print('  Node 2 worked')
    if test_node_3.execute(Sample_Blackboard, test_stack) == 'SUCCEEDED':
        print('  Node 3 worked')

    print('\n     Finally our pizza condition should corretly succeede now:')
    if Condition_1.execute(Sample_Blackboard, test_stack) == 'SUCCEEDED':
        print('Condition is True!')
Exemplo n.º 2
0
def create_spot():

    # Create all tasks related to spot cleaning
    Spot_condition = condition('SPOT')
    Clean_Spot = task('Clean Spot', None, None, None)
    Spot_Timer = timer(20, Clean_Spot)
    Done_Spot = task('Done Spot', 'write', 'SPOT', False)

    # Create list of tasks and create/return squence
    Spot_tasks_list = [Spot_condition, Spot_Timer, Done_Spot]
    return sequence(Spot_tasks_list)
Exemplo n.º 3
0
def create_battery_branch():

    #Creating all tasks related to going home
    Battery_condition = condition('BATTERY_UNDER_30')
    Find_home = task('Find Home', 'write', 'HOME_PATH', 'It is over there!')
    Go_home = task('Go Home', 'recive', 'HOME_PATH', None)
    Dock = task('Dock', 'write', 'SIM_OVER', True)

    # Create list of tasks and create/return squence
    Battery_Task_List = [Battery_condition, Find_home, Go_home, Dock]
    return sequence(Battery_Task_List)
Exemplo n.º 4
0
def test_Decorators(Sample_Blackboard):
    print('\n\n     Finally we will test our Decorators types')

    test_node_1 = task('Enter Carm', None, None, None)
    test_node_3 = task('Eat Pizza', 'write', 'EAT_PIZZA', True)
    Condition_1 = condition('EAT_PIZZA')
    test_list_1 = [Condition_1, test_node_1]
    test_stack = []

    print('\n     Let us test our negations')
    Test_negation_1 = negation(Condition_1)
    Test_negation_2 = negation(test_node_3)
    if Test_negation_1.execute(Sample_Blackboard, test_stack) == 'SUCCEEDED':
        print('  Test_negation_1 returns SUCCEEDED, worked correctly')
    if Test_negation_2.execute(Sample_Blackboard, test_stack) == 'FAILED':
        print('  Test_negation_2 returns FAILED, worked correctly')
    if Test_negation_1.execute(Sample_Blackboard, test_stack) == 'FAILED':
        print('  Test_negation_1 returns FAILED now, worked correctly')

    print('\n     Let us test a timer')
    Test_timer = timer(10, test_node_1)
    Test_timer.execute(Sample_Blackboard, test_stack)
    print('  Timer is at:', Sample_Blackboard['TIMER'])
    while Test_timer.execute(Sample_Blackboard, test_stack) == 'RUNNING':
        print('  Timer is at:', Sample_Blackboard['TIMER'])

    print('\n     Let us test timer again, to make sure it works twice')
    Test_timer.execute(Sample_Blackboard, test_stack)
    print('  Timer is at:', Sample_Blackboard['TIMER'])
    while Test_timer.execute(Sample_Blackboard, test_stack) == 'RUNNING':
        print('  Timer is at:', Sample_Blackboard['TIMER'])

    Sample_Blackboard['EAT_PIZZA'] = True
    print('\n     Let us test our until false, should run 8 times')
    test_sequence_1 = sequence(test_list_1)
    Test_until_false = until_false(test_sequence_1)
    for x in range(1, 20):

        if Test_until_false.execute(Sample_Blackboard,
                                    test_stack) == 'RUNNING':
            print('  This is the', x, 'time untill_false has run')
        if x == 8:
            Sample_Blackboard['EAT_PIZZA'] = False
Exemplo n.º 5
0
def test_Composities(Sample_Blackboard):
    print('\n\n     Now let us test our composities types')

    #Create nodes and lists to use
    test_node_1 = task('Enter Carm', None, None, None)
    test_node_2 = task('Find Pizza', 'recive', 'PIZZA_LOCATION', None)
    test_node_3 = task('Eat Pizza', 'write', 'EAT_PIZZA', True)
    Condition_1 = condition('EAT_PIZZA')
    test_list_1 = [test_node_1, test_node_2]
    test_list_2 = [Condition_1, test_node_1, test_node_3]
    test_list_3 = [Condition_1]
    test_stack = []

    #Call functions that test different types of Composities
    test_selector(Sample_Blackboard, test_stack, test_list_1, test_list_2,
                  test_list_3)

    test_sequence(Sample_Blackboard, test_stack, test_list_1, test_list_2,
                  test_list_3)

    test_priority(Sample_Blackboard, test_stack, test_node_1, test_node_2,
                  Condition_1)
Exemplo n.º 6
0
def create_general():

    # Create dusty spot cleaner
    Dusty_condition = condition('DUSTY_SPOT')
    Clean_Dusty = task('Clean Spot', None, None, None)
    Dusty_Timer = timer(35, Clean_Dusty)
    Dusty_Clean_Sequence = sequence([Dusty_condition, Dusty_Timer])

    # Create branches that check battery and do a simlpe clean
    Clean = task('Clean', None, None, None)
    General_Selector = selector([Dusty_Clean_Sequence, Clean])
    Battery_condition = condition('BATTERY_UNDER_30')
    Battery_Negation = negation(Battery_condition)
    Untill_False_Sequence = sequence([Battery_Negation, General_Selector])
    Untill_False_Node = until_false(Untill_False_Sequence)

    # Create branches that check if the user wants to execute general then
    #create and return whole sequence
    Done_General = task('Done General', 'write', 'GENERAL', False)
    Execute_Sequence = sequence([Untill_False_Node, Done_General])
    General_condition = condition('GENERAL')
    return sequence([General_condition, Execute_Sequence])
Exemplo n.º 7
0
def create_roomba():

    #Create branches for some of the roomba's behaviors
    Battery_Task_Sequence = create_battery_branch()
    Spot_Clean_Sequence = create_spot()
    Genral_Sequence = create_general()

    #combining spot clean and General Clean together
    cleaning_list = [Spot_Clean_Sequence, Genral_Sequence]
    Cleaning_Selector = selector(cleaning_list)

    #Creating do nothing branch
    Do_Nothing = task('Do Nothing', None, None, None)

    #Creating Tree and it's root which will be a priority node
    Priority_tasks = [Battery_Task_Sequence, Cleaning_Selector, Do_Nothing]
    priority_root = priority(Priority_tasks)
    sim_roomba = Tree(priority_root)
    return sim_roomba