예제 #1
0
def test_transmit(loc_1, loc_2, loc_3, expected):
    AUV_A = Vehicle(0, 3, loc_1[0], loc_1[1], loc_1[2], 0)
    AUV_B = Vehicle(1, 3, loc_2[0], loc_2[1], loc_2[2], 0)
    AUV_C = Vehicle(2, 3, loc_3[0], loc_3[1], loc_3[2], 0)

    config = sim_config('tests/config/sim_config.csv')
    achannel = V2V_comms(config)

    AUV_A.send_acc_msg(achannel, 5, config, [AUV_A, AUV_B, AUV_C])

    assert (achannel.receive_msg[0] == expected[0]
            and achannel.receive_msg[1] == expected[1]
            and achannel.receive_msg[2] == expected[2])
예제 #2
0
def test_transmit(loc_1, loc_2, loc_3, expected):
    AUV_A = Vehicle(0, 3, loc_1[0], loc_1[1], loc_1[2], 0)
    AUV_B = Vehicle(1, 3, loc_2[0], loc_2[1], loc_2[2], 0)
    AUV_C = Vehicle(2, 3, loc_3[0], loc_3[1], loc_3[2], 0)

    config = sim_config('tests/config/sim_config.csv')
    achannel = V2V_comms(config)

    AUV_A.send_acc_msg(achannel, 5, config, [AUV_A, AUV_B, AUV_C])

    assert (achannel.receive_msg[0] == expected[0] and
            achannel.receive_msg[1] == expected[1] and
            achannel.receive_msg[2] == expected[2])
예제 #3
0
def test_sent_time(msg_time, time_1, time_2, expected):
    # Examines the condition of accepting messages based on the message timestamp
    # and the timestamp of the corresponding data held by the AUV
    AUV_A = Vehicle(0, 3, 1, 1, -1, 0)
    AUV_B = Vehicle(1, 3, 50, 50, -1, 0)
    AUV_C = Vehicle(2, 3, 30, 50, -1, 0)

    config = sim_config('tests/config/sim_config.csv')
    achannel = V2V_comms(config)

    AUV_B.time_stamps[0] = time_1
    AUV_C.time_stamps[0] = time_2

    AUV_A.send_acc_msg(achannel, msg_time, config, [AUV_A, AUV_B, AUV_C])
    AUV_B.receive_acc_msg(achannel)
    AUV_C.receive_acc_msg(achannel)

    assert AUV_B.time_stamps[0] == expected[0]
    assert AUV_C.time_stamps[0] == expected[1]
예제 #4
0
def test_sent_time(msg_time, time_1, time_2, expected):
    # Examines the condition of accepting messages based on the message timestamp
    # and the timestamp of the corresponding data held by the AUV
    AUV_A = Vehicle(0, 3, 1, 1, -1, 0)
    AUV_B = Vehicle(1, 3, 50, 50, -1, 0)
    AUV_C = Vehicle(2, 3, 30, 50, -1, 0)

    config = sim_config('tests/config/sim_config.csv')
    achannel = V2V_comms(config)

    AUV_B.time_stamps[0] = time_1
    AUV_C.time_stamps[0] = time_2

    AUV_A.send_acc_msg(achannel, msg_time, config, [AUV_A, AUV_B, AUV_C])
    AUV_B.receive_acc_msg(achannel)
    AUV_C.receive_acc_msg(achannel)

    assert AUV_B.time_stamps[0] == expected[0]
    assert AUV_C.time_stamps[0] == expected[1]
예제 #5
0
def test_acc_loc_vehicles(comms_AUV):
    # B is in range of A and C
    # A is out of range of C
    AUV_A = Vehicle(0, 3, 1, 1, -1, 0)
    AUV_B = Vehicle(1, 3, 50, 50, -1, 0)
    AUV_C = Vehicle(2, 3, 401, 401, -1, 0)

    config = sim_config('tests/config/sim_config.csv')
    achannel = V2V_comms(config)
    if comms_AUV == 0:
        AUV_A.send_acc_msg(achannel, 0, config, [AUV_A, AUV_B, AUV_C])
    elif comms_AUV == 1:
        AUV_B.send_acc_msg(achannel, 0, config, [AUV_A, AUV_B, AUV_C])
    elif comms_AUV == 2:
        AUV_C.send_acc_msg(achannel, 0, config, [AUV_A, AUV_B, AUV_C])

    AUV_A.receive_acc_msg(achannel)
    AUV_B.receive_acc_msg(achannel)
    AUV_C.receive_acc_msg(achannel)

    if comms_AUV == 0:
        # B is in range hence As index in Bs loc_vehicles = 1
        # C is out of range: As index in B.loc_vehicles = 0
        assert AUV_B.loc_vehicles[0] == 1
        assert AUV_C.loc_vehicles[0] == 0
    elif comms_AUV == 1:
        assert AUV_A.loc_vehicles[1] == 1
        assert AUV_C.loc_vehicles[1] == 1
    elif comms_AUV == 2:
        assert AUV_A.loc_vehicles[2] == 0
        assert AUV_B.loc_vehicles[2] == 1
예제 #6
0
def test_acc_loc_vehicles(comms_AUV):
    # B is in range of A and C
    # A is out of range of C
    AUV_A = Vehicle(0, 3, 1, 1, -1, 0)
    AUV_B = Vehicle(1, 3, 50, 50, -1, 0)
    AUV_C = Vehicle(2, 3, 401, 401, -1, 0)

    config = sim_config('tests/config/sim_config.csv')
    achannel = V2V_comms(config)
    if comms_AUV == 0:
        AUV_A.send_acc_msg(achannel,0,config, [AUV_A, AUV_B, AUV_C])
    elif comms_AUV == 1:
        AUV_B.send_acc_msg(achannel, 0, config, [AUV_A, AUV_B, AUV_C])
    elif comms_AUV == 2:
        AUV_C.send_acc_msg(achannel,0,config, [AUV_A, AUV_B, AUV_C])

    AUV_A.receive_acc_msg(achannel)
    AUV_B.receive_acc_msg(achannel)
    AUV_C.receive_acc_msg(achannel)

    if comms_AUV == 0:
        # B is in range hence As index in Bs loc_vehicles = 1
        # C is out of range: As index in B.loc_vehicles = 0
        assert AUV_B.loc_vehicles[0] == 1
        assert AUV_C.loc_vehicles[0] == 0
    elif comms_AUV == 1:
        assert AUV_A.loc_vehicles[1] == 1
        assert AUV_C.loc_vehicles[1] == 1
    elif comms_AUV == 2:
        assert AUV_A.loc_vehicles[2] == 0
        assert AUV_B.loc_vehicles[2] == 1
예제 #7
0
def test_range():
    AUV_A = Vehicle(0, 3, 10, 10, -10, 0)
    AUV_B = Vehicle(1, 3, 499, 0, -10, 0)
    AUV_C = Vehicle(2, 3, 998, 0, -10, 0)

    config = sim_config('tests/config/sim_config.csv')
    achannel = V2V_comms(config)

    AUV_A.send_acc_msg(achannel, 1, config, [AUV_A, AUV_B, AUV_C])

    AUV_B.receive_acc_msg(achannel)
    AUV_C.receive_acc_msg(achannel)

    # assert B received the message
    assert AUV_B.loc_pos[0][0] == AUV_A.x
    assert AUV_B.loc_pos[0][1] == AUV_A.y
    assert AUV_B.loc_pos[0][2] == AUV_A.z

    # assert C did not receive the message
    assert AUV_C.loc_pos[0][0] != AUV_A.x
    assert AUV_C.loc_pos[0][1] != AUV_A.y
    assert AUV_C.loc_pos[0][2] != AUV_A.z
예제 #8
0
def test_range():
    AUV_A = Vehicle(0, 3, 10, 10, -10, 0)
    AUV_B = Vehicle(1, 3, 499, 0, -10, 0)
    AUV_C = Vehicle(2, 3, 998, 0, -10, 0)

    config = sim_config('tests/config/sim_config.csv')
    achannel = V2V_comms(config)


    AUV_A.send_acc_msg(achannel, 1, config, [AUV_A, AUV_B, AUV_C])

    AUV_B.receive_acc_msg(achannel)
    AUV_C.receive_acc_msg(achannel)

    # assert B received the message
    assert AUV_B.loc_pos[0][0] == AUV_A.x
    assert AUV_B.loc_pos[0][1] == AUV_A.y
    assert AUV_B.loc_pos[0][2] == AUV_A.z

    # assert C did not receive the message
    assert AUV_C.loc_pos[0][0] != AUV_A.x
    assert AUV_C.loc_pos[0][1] != AUV_A.y
    assert AUV_C.loc_pos[0][2] != AUV_A.z
예제 #9
0
def test_time_stamps():
    AUV_A = Vehicle(0, 3, 10, 10, 0, 0)
    AUV_B = Vehicle(1, 3, 50, 50, 0, 0)
    AUV_C = Vehicle(2, 3, 501, 501, 0, 0)

    config = sim_config('tests/config/sim_config.csv')
    base = Base_Station(config.swarm_size)
    achannel = V2V_comms(config)
    elps_time = 0
    # Information exchanged via satellite
    AUV_A.sat_up(base, elps_time)
    AUV_B.sat_up(base, elps_time)
    AUV_C.sat_up(base, elps_time)
    AUV_A.sat_down(base, config.swarm_size, elps_time)
    AUV_B.sat_down(base, config.swarm_size, elps_time)
    AUV_C.sat_down(base, config.swarm_size, elps_time)

    for i in range(100):
        AUV_A.go(config, 0)
        AUV_B.go(config, 0)
        AUV_C.go(config, 0)
        elps_time += 1

    # Information exchanged via satellite
    AUV_A.sat_up(base, elps_time)
    AUV_B.sat_up(base, elps_time)
    AUV_C.sat_up(base, elps_time)
    AUV_A.sat_down(base, config.swarm_size, elps_time)
    AUV_B.sat_down(base, config.swarm_size, elps_time)
    AUV_C.sat_down(base, config.swarm_size, elps_time)

    for i in range(100):
        AUV_A.go(config, 0)
        AUV_B.go(config, 0)
        AUV_C.go(config, 0)
        elps_time += 1
    # Condition AUVs must be more than 0.5m deep to transmit & receive acc
    AUV_A.z, AUV_B.z, AUV_C.z = -1, -1, -1
    AUV_B.send_acc_msg(achannel, elps_time, config, [AUV_A, AUV_B, AUV_C])
    # A should receive the acc data and update the timestamp
    AUV_A.receive_acc_msg(achannel)
    # C will not receieve the data as it is out of acc range
    AUV_C.receive_acc_msg(achannel)

    # A received the acoustic message therefore has a newer timestamp
    assert AUV_A.time_stamps[1] == 200
    # C was out of range hence has the timestamp from sat comms
    assert AUV_C.time_stamps[1] == 100

    # B has not moved since acc comms hence...
    assert (AUV_A.loc_pos[1][0] == AUV_B.x and AUV_A.loc_pos[1][1] == AUV_B.y
            and AUV_A.loc_pos[1][2] == AUV_B.z)

    # Cs knowledge of B should be the same as that on the server
    assert (AUV_C.loc_pos[1][0] == base.log[1].x[-1]
            and AUV_C.loc_pos[1][1] == base.log[1].y[-1]
            and AUV_C.loc_pos[1][2] == base.log[1].z[-1])

    # C should not know where B is currently
    assert (AUV_C.loc_pos[1][0] != AUV_B.x and AUV_C.loc_pos[1][1] != AUV_B.y
            and AUV_C.loc_pos[1][2] != AUV_B.z)
예제 #10
0
def test_time_stamps():
    AUV_A = Vehicle(0, 3, 10, 10, 0, 0)
    AUV_B = Vehicle(1, 3, 50, 50, 0, 0)
    AUV_C = Vehicle(2, 3, 501, 501, 0, 0)

    config = sim_config('tests/config/sim_config.csv')
    base = Base_Station(config.swarm_size)
    achannel = V2V_comms(config)
    elps_time = 0
    # Information exchanged via satellite
    AUV_A.sat_up(base, elps_time)
    AUV_B.sat_up(base, elps_time)
    AUV_C.sat_up(base, elps_time)
    AUV_A.sat_down(base, config.swarm_size, elps_time)
    AUV_B.sat_down(base, config.swarm_size, elps_time)
    AUV_C.sat_down(base, config.swarm_size, elps_time)

    for i in range(100):
        AUV_A.go(config, 0)
        AUV_B.go(config, 0)
        AUV_C.go(config, 0)
        elps_time += 1

    # Information exchanged via satellite
    AUV_A.sat_up(base, elps_time)
    AUV_B.sat_up(base, elps_time)
    AUV_C.sat_up(base, elps_time)
    AUV_A.sat_down(base, config.swarm_size, elps_time)
    AUV_B.sat_down(base, config.swarm_size, elps_time)
    AUV_C.sat_down(base, config.swarm_size, elps_time)

    for i in range(100):
        AUV_A.go(config, 0)
        AUV_B.go(config, 0)
        AUV_C.go(config, 0)
        elps_time += 1
    # Condition AUVs must be more than 0.5m deep to transmit & receive acc
    AUV_A.z, AUV_B.z, AUV_C.z = -1,-1,-1
    AUV_B.send_acc_msg(achannel, elps_time, config, [AUV_A, AUV_B, AUV_C])
    # A should receive the acc data and update the timestamp
    AUV_A.receive_acc_msg(achannel)
    # C will not receieve the data as it is out of acc range
    AUV_C.receive_acc_msg(achannel)

    # A received the acoustic message therefore has a newer timestamp
    assert AUV_A.time_stamps[1] == 200
    # C was out of range hence has the timestamp from sat comms
    assert AUV_C.time_stamps[1] == 100

    # B has not moved since acc comms hence...
    assert (AUV_A.loc_pos[1][0] == AUV_B.x and
            AUV_A.loc_pos[1][1] == AUV_B.y and
            AUV_A.loc_pos[1][2] == AUV_B.z)

    # Cs knowledge of B should be the same as that on the server
    assert (AUV_C.loc_pos[1][0] == base.log[1].x[-1] and
            AUV_C.loc_pos[1][1] == base.log[1].y[-1] and
            AUV_C.loc_pos[1][2] == base.log[1].z[-1])

    # C should not know where B is currently
    assert (AUV_C.loc_pos[1][0] != AUV_B.x and
            AUV_C.loc_pos[1][1] != AUV_B.y and
            AUV_C.loc_pos[1][2] != AUV_B.z)