Пример #1
0
def conflict_detection(owner, intruders):
    conflict_UAV = []
    antecedent = [None] * 3
    for i in intruders:
        temp_conflict = []
        d = get_distance([owner[0], owner[1]], [i[0], i[1]])
        if d <= 4:
            print('Collision')
            break
        if d < 24:
            Relative_location = Get_Relative_Location([owner[0], owner[1]],
                                                      [i[0], i[1]], owner[3])
            # print(Relative_location)
            if Relative_location:
                temp_conflict.append(Relative_location)

        if temp_conflict:
            conflict_UAV.append(temp_conflict)
            if temp_conflict[0] == 'F':
                if d < 6:
                    antecedent[1] = 'N'
                elif d > 16:
                    antecedent[1] = 'F'
                else:
                    antecedent[1] = 'M'
            if temp_conflict[0] == 'R':
                if d < 10:
                    antecedent[2] = 'N'
                else:
                    antecedent[2] = 'M'
            if temp_conflict[0] == 'L':
                if d < 10:
                    antecedent[0] = 'N'
                else:
                    antecedent[0] = 'M'

    if conflict_UAV:
        # print(conflict_UAV)
        if antecedent[0] == None:
            antecedent[0] = 'M'
        if antecedent[1] == None:
            antecedent[1] = 'F'
        if antecedent[2] == None:
            antecedent[2] = 'M'
        print(antecedent)
        consequence = fuzzy_control(antecedent)
        print(consequence)
        print(defuzzificztion(consequence))

        return defuzzificztion(consequence)[0], defuzzificztion(consequence)[1]
Пример #2
0
             [r3.location_x, r3.location_y, r3.velocity, r3.heading]])
        if order4:
            r4.move_heading_velocity(order4[1], order4[0])
        else:
            r4.move()

        tr_r1[0].append(r1.location_x)
        tr_r1[1].append(r1.location_y)
        tr_r2[0].append(r2.location_x)
        tr_r2[1].append(r2.location_y)
        tr_r3[0].append(r3.location_x)
        tr_r3[1].append(r3.location_y)
        tr_r4[0].append(r4.location_x)
        tr_r4[1].append(r4.location_y)

        if get_distance([r1.location_x, r1.location_y],
                        [r1.target_x, r1.target_y]) < 3 and get_distance([
                            r2.location_x, r2.location_y
                        ], [r2.target_x, r2.target_y]) < 3 and get_distance(
                            [r3.location_x, r3.location_y],
                            [r3.target_x, r3.target_y]) < 3 and get_distance(
                                [r4.location_x, r4.location_y],
                                [r4.target_x, r4.target_y]) < 3:
            break

    elapsed = (time.time() - start)
    print("Time used:", elapsed)

    fig = plt.figure()
    plt.plot(tr_r1[0], tr_r1[1], color='red', label='r1')
    plt.plot(tr_r2[0], tr_r2[1], color='blue', label='r2')
    plt.plot(tr_r3[0], tr_r3[1], color='green', label='r3')