Exemplo n.º 1
0
def test_yaw_demand(target, expected):
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, 0, 0, 0, 0)
    config = sim_config('config/sim_config.csv')
    AUV.waypoints = [target]
    AUV.move_to_waypoint()
    assert AUV.yaw_demand == expected
Exemplo n.º 2
0
def test_pitch_demand(start, target, expected):
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, start[0], start[1], start[2], 0)
    config = sim_config('config/sim_config.csv')
    AUV.waypoints = [target]
    AUV.move_to_waypoint()
    assert abs(AUV.pitch_demand - expected) < 0.0000001
Exemplo n.º 3
0
def test_waypoint_setting(state, start, target, expected):
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, start[0], start[1], start[2], 0)
    config = sim_config('config/sim_config.csv')
    AUV.state = state
    AUV.set_waypoint(target, config)

    assert (abs(AUV.waypoints[0][0] - expected[0]) < 0.0000001 and
            abs(AUV.waypoints[0][1] - expected[1]) < 0.0000001 and
            abs(AUV.waypoints[0][2] - expected[2]) < 0.0000001)
Exemplo n.º 4
0
def test_time_checks(elps_time, state, expected):
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, 0, 0, -50, 0)
    config = sim_config('config/sim_config.csv')

    AUV.state = state

    #t_uw set to 1200
    AUV.time_checks(elps_time, config)

    assert AUV.state == expected
Exemplo n.º 5
0
def test_time_checks(elps_time, state, expected):
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, 0, 0, -50, 0)
    config = sim_config('config/sim_config.csv')

    AUV.state = state

    #t_uw set to 1200
    AUV.time_checks(elps_time, config)

    assert AUV.state == expected
Exemplo n.º 6
0
def prove_yaw_behaviour(config):
    print_time(0)
    start_loc = [0,0]
    start_yaw = 0
    AUV = Vehicle(config, 0, config.swarm_size, start_loc[0], start_loc[1], 0, start_yaw)
    AUV.waypoints = [[50,0,0],[50,50,0],[0,50,0],[0,0,0]]
    for elps_time in range(config.run_time):
        AUV.go(config, elps_time)
        update_progress(elps_time, config.run_time)
    # Outputs results
    print('\nWriting Results')
    write_proof(AUV, config)
    print_time(1)
Exemplo n.º 7
0
def test_surfacing(z, state, expected):
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, 0, 0, z, 0)
    config = sim_config('config/sim_config.csv')
    base = Base_Station(config.swarm_size)
    # AUV at 1m depth and surfacing
    AUV.state = state

    # Try to sat comm (this triggers state change to diving
    # should remain surfacing as deeper than conditional depth for sat (0.5m)
    AUV.sat_comms(base, config.swarm_size, 0)

    assert AUV.state == expected
Exemplo n.º 8
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])
Exemplo n.º 9
0
def test_uw_condition():
    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')
    base = Base_Station(3)


    AUV_A.sat_up(base, 1)

    # Assert nothing was uploaded due to not being on surface
    assert base.log[0].x == []
Exemplo n.º 10
0
def test_surfacing(z, state, expected):
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, 0, 0, z, 0)
    config = sim_config('config/sim_config.csv')
    base = Base_Station(config.swarm_size)
    # AUV at 1m depth and surfacing
    AUV.state = state

    # Try to sat comm (this triggers state change to diving
    # should remain surfacing as deeper than conditional depth for sat (0.5m)
    AUV.sat_comms(base, config.swarm_size, 0)

    assert AUV.state == expected
Exemplo n.º 11
0
def test_upload():
    AUV_A = Vehicle(0, 3, 10, 10, 0, 0)
    AUV_B = Vehicle(1, 3, 499, 0, 0, 0)
    AUV_C = Vehicle(2, 3, 998, 0, 0, 0)

    config = sim_config('tests/config/sim_config.csv')
    base = Base_Station(3)

    AUV_A.sat_up(base, 1)

    assert (base.log[0].x[-1] == AUV_A.x and
            base.log[0].y[-1] == AUV_A.y and
            base.log[0].z[-1] == AUV_A.z)
Exemplo n.º 12
0
def prove_yaw_behaviour(config):
    print_time(0)
    start_loc = [0, 0]
    start_yaw = 0
    AUV = Vehicle(config, 0, config.swarm_size, start_loc[0], start_loc[1], 0,
                  start_yaw)
    AUV.waypoints = [[50, 0, 0], [50, 50, 0], [0, 50, 0], [0, 0, 0]]
    for elps_time in range(config.run_time):
        AUV.go(config, elps_time)
        update_progress(elps_time, config.run_time)
    # Outputs results
    print('\nWriting Results')
    write_proof(AUV, config)
    print_time(1)
Exemplo n.º 13
0
def prove_vel_behaviour(config):
    print_time(0)
    start_loc = [0, 0]
    start_yaw = 0
    AUV = Vehicle(config, 0, config.swarm_size, start_loc[0], start_loc[1], 0, start_yaw)
    AUV.waypoints = [[50000, 0, 0]]
    v_demands = [1.0,1.5,0.75,0.25,0.0]

    for v in v_demands:
        AUV.v_demand = v
        for elps_time in range(100):
            AUV.go(config, elps_time)

    write_proof(AUV, config)
    print_time(1)
Exemplo n.º 14
0
def test_set_state(curr_state, desired_state, z, expected):
    AUV = Vehicle(0, 1, 50, 50, -10, 0)
    AUV.state = curr_state
    AUV.z = z

    if expected == 1:
        with pytest.raises(Exception) as e_info:
            AUV.set_state(desired_state)
    else:
        AUV.set_state(desired_state)
        assert AUV.state == desired_state
Exemplo n.º 15
0
def test_reached_waypoint():
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, 50, 50, -10, 0)
    config = sim_config('config/sim_config.csv')
    AUV.state = 0

    # AUV at 1m depth and surfacing
    AUV.waypoints = [[50, 50, -20]]
    AUV.move_to_waypoint()

    assert AUV.state == 0

    AUV.z = -19
    AUV.move_to_waypoint()

    assert AUV.state == 1
Exemplo n.º 16
0
def test_yaw_logic(yaw, yaw_demand, expected):
    init_x, init_y, init_z, init_yaw = 0, 0, 0, 0
    AUV = Vehicle(0, 1, init_x, init_y, init_z, init_yaw)
    config = sim_config('config/sim_config.csv')

    AUV.set_yaw(yaw)
    AUV.set_yaw_demand(yaw_demand)

    AUV.plant(config.time_step)

    if expected == 1:
        assert AUV.yaw > yaw
    elif expected == 0:
        assert AUV.yaw < yaw
Exemplo n.º 17
0
def test_set_state(curr_state, desired_state, z, expected):
    AUV = Vehicle(0, 1, 50, 50, -10, 0)
    AUV.state = curr_state
    AUV.z = z

    if expected == 1:
        with pytest.raises(Exception) as e_info:
            AUV.set_state(desired_state)
    else:
        AUV.set_state(desired_state)
        assert AUV.state == desired_state
Exemplo n.º 18
0
def test_reached_waypoint():
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, 50, 50,-10 , 0)
    config = sim_config('config/sim_config.csv')
    AUV.state = 0

    # AUV at 1m depth and surfacing
    AUV.waypoints = [[50,50,-20]]
    AUV.move_to_waypoint()

    assert AUV.state == 0

    AUV.z = -19
    AUV.move_to_waypoint()

    assert AUV.state == 1
Exemplo n.º 19
0
def test_pitch_yaw(z, yaw, pitch, expected):
    init_x, init_y = 0, 0
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, init_x, init_y, z, yaw)
    config = sim_config('config/sim_config.csv')
    AUV.set_yaw(yaw)
    AUV.set_pitch(pitch)

    AUV.dead_reckoner(config.time_step)

    x = expected[0]
    y = expected[1]
    z = expected[2]

    assert abs(AUV.x - x) < 0.0000001
    assert abs(AUV.y - y) < 0.0000001
    assert abs(AUV.z - z) < 0.0000001
Exemplo n.º 20
0
def test_v(v, v_demand, expected):
    AUV = Vehicle(0, 1, 0, 0, 0, 0)
    config = sim_config('config/sim_config.csv')

    AUV.set_v(v)
    AUV.set_v_demand(v_demand)
    AUV.plant(config.time_step)

    if expected == 1:
        # assert AUV pitches nose down
        assert AUV.v > v
    elif expected == 0:
        # assert AUV pitches nose up
        assert AUV.v < v
    elif expected == 2:
        # assert AUV pitches nose up
        assert AUV.v == v
Exemplo n.º 21
0
def test_yaw_logic(yaw, yaw_demand, expected):
    init_x, init_y, init_z, init_yaw = 0,0,0,0
    AUV = Vehicle(0, 1, init_x, init_y, init_z, init_yaw)
    config = sim_config('config/sim_config.csv')

    AUV.set_yaw(yaw)
    AUV.set_yaw_demand(yaw_demand)

    AUV.plant(config.time_step)

    if expected ==1:
        assert AUV.yaw > yaw
    elif expected == 0:
        assert AUV.yaw < yaw
Exemplo n.º 22
0
def prove_dive_behaviour(config):
    # INITALISATION
    comms_AUV = 0
    np.random.seed(42)
    start_locs = np.array([
        np.random.randint(50, size=config.swarm_size),
        np.random.randint(50, size=config.swarm_size)
    ])
    start_yaws = np.random.randint(360, size=config.swarm_size)
    Base = Base_Station(config.swarm_size)
    Acc_comms = V2V_comms(config)
    Swarm = [
        Vehicle(config, 0, config.swarm_size, start_locs[0][0],
                start_locs[1][0], 0, start_yaws[0])
    ]
    print_time(0)

    # Initial communication step to populate data on subs
    for AUV in Swarm:
        AUV.sat_up(Base, 0)
    for AUV in Swarm:
        AUV.sat_down(Base, config.swarm_size, 0)
    check = 0
    # MAIN LOOP

    AUV.waypoints = [[400, 0, -50], [500, 0, 0], [550, 0, -50]]

    for elps_time in range(config.run_time):

        Swarm[comms_AUV].send_acc_msg(Acc_comms, elps_time, config, Swarm)
        for AUV in Swarm:
            # Performs communication, sat if at surface, recieves acc if submerged
            AUV.sat_comms(Base, config, elps_time)
            AUV.receive_acc_msg(Acc_comms)

        for AUV in Swarm:

            AUV.time_checks(elps_time, config)

            AUV.go(config, elps_time)

        update_progress(elps_time, config.run_time)

    # Outputs results
    print('\nWriting Results')
    write_proof(Swarm[0], config)
    print_time(1)
Exemplo n.º 23
0
def test_pitch(start_loc, wayp, expected):
    AUV = Vehicle(0, 1, start_loc[0], start_loc[1], start_loc[2], 0)
    config = sim_config('config/sim_config.csv')

    AUV.waypoints = [wayp]
    AUV.current_waypoint = 0

    AUV.move_to_waypoint()
    AUV.plant(config.time_step)

    if expected == 1:
        # assert AUV pitches nose down
        assert AUV.pitch > 0
    elif expected == 0:
        # assert AUV pitches nose up
        assert AUV.pitch < 0
    elif expected == 2:
        # assert AUV pitches nose up
        assert AUV.pitch == 0
Exemplo n.º 24
0
def test_uw_condition():
    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')
    base = Base_Station(3)

    AUV_A.sat_up(base, 1)

    # Assert nothing was uploaded due to not being on surface
    assert base.log[0].x == []
Exemplo n.º 25
0
def test_upload():
    AUV_A = Vehicle(0, 3, 10, 10, 0, 0)
    AUV_B = Vehicle(1, 3, 499, 0, 0, 0)
    AUV_C = Vehicle(2, 3, 998, 0, 0, 0)

    config = sim_config('tests/config/sim_config.csv')
    base = Base_Station(3)

    AUV_A.sat_up(base, 1)

    assert (base.log[0].x[-1] == AUV_A.x and base.log[0].y[-1] == AUV_A.y
            and base.log[0].z[-1] == AUV_A.z)
Exemplo n.º 26
0
def main():
    Base = Base_Station(1)
    config = sim_config('config/sim_config.csv')
    AUV = Vehicle(0, 1, 0, 0, 0, 0)

    AUV.waypoints = [[50,0,-50], [100, 0, -50], [100, 0, 0], [150, 0, -50], [200, 0, 0]]

    for elps_time in range(5000):
        AUV.sat_comms(Base, config, elps_time)
        AUV.go(config, elps_time)

    write_proof(AUV, config, fn = 'results/sat_delay_test.csv')

    df = pd.read_csv('results/sat_delay_test.csv')
    plt.plot(df.index, df.z)
    plt.show()
Exemplo n.º 27
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
Exemplo n.º 28
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])
Exemplo n.º 29
0
def test_v(v, v_demand, expected):
    AUV = Vehicle(0, 1, 0, 0, 0, 0)
    config = sim_config('config/sim_config.csv')

    AUV.set_v(v)
    AUV.set_v_demand(v_demand)
    AUV.plant(config.time_step)

    if expected == 1:
        # assert AUV pitches nose down
        assert AUV.v > v
    elif expected == 0:
        # assert AUV pitches nose up
        assert AUV.v < v
    elif expected == 2:
        # assert AUV pitches nose up
        assert AUV.v == v
Exemplo n.º 30
0
def test_pitch_yaw(z, yaw, pitch, expected):
    init_x, init_y = 0,0
    # (self,i, Swarm_Size, start_x, start_y, start_z, start_yaw)
    AUV = Vehicle(0, 1, init_x, init_y, z, yaw)
    config = sim_config('config/sim_config.csv')
    AUV.set_yaw(yaw)
    AUV.set_pitch(pitch)

    AUV.dead_reckoner(config.time_step)

    x = expected[0]
    y = expected[1]
    z = expected[2]

    assert abs(AUV.x - x) < 0.0000001
    assert abs(AUV.y - y) < 0.0000001
    assert abs(AUV.z - z) < 0.0000001
Exemplo n.º 31
0
def test_pitch(start_loc, wayp, expected):
    AUV = Vehicle(0, 1, start_loc[0], start_loc[1], start_loc[2], 0)
    config = sim_config('config/sim_config.csv')

    AUV.waypoints = [wayp]
    AUV.current_waypoint = 0

    AUV.move_to_waypoint()
    AUV.plant(config.time_step)

    if expected == 1:
        # assert AUV pitches nose down
        assert AUV.pitch > 0
    elif expected == 0:
        # assert AUV pitches nose up
        assert AUV.pitch < 0
    elif expected == 2:
        # assert AUV pitches nose up
        assert AUV.pitch == 0
Exemplo n.º 32
0
def prove_vel_behaviour(config):
    print_time(0)
    start_loc = [0, 0]
    start_yaw = 0
    AUV = Vehicle(config, 0, config.swarm_size, start_loc[0], start_loc[1], 0,
                  start_yaw)
    AUV.waypoints = [[50000, 0, 0]]
    v_demands = [1.0, 1.5, 0.75, 0.25, 0.0]

    for v in v_demands:
        AUV.v_demand = v
        for elps_time in range(100):
            AUV.go(config, elps_time)

    write_proof(AUV, config)
    print_time(1)
Exemplo n.º 33
0
def test_sat_commd():
    AUV_A = Vehicle(0, 3, 10, 10, 0, 0)

    config = sim_config('tests/config/sim_config.csv')
    base = Base_Station(config.swarm_size)
    elps_time = 0

    AUV_A.sat_comms(base, config, elps_time)
    assert AUV_A.state == 3
    assert AUV_A.sat_commd == 0

    AUV_A.pitch = AUV_A.config.max_pitch
    AUV_A.v = 0

    AUV_A.sat_comms(base, config, elps_time)
    assert AUV_A.state == 3
    assert AUV_A.sat_commd == 1

    elps_time = 181 / config.time_step
    AUV_A.waypoints = [[2, 2, 2], [4, 4, 4], [5, 5, 5]]
    AUV_A.sat_comms(base, config, elps_time)
    assert AUV_A.state == 0
    assert AUV_A.sat_commd == 1

    AUV_A.z = -1
    AUV_A.sat_comms(base, config, elps_time)

    assert AUV_A.sat_commd == 0
Exemplo n.º 34
0
def test_sat_loc_vehicles():
    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)

    assert (AUV_A.loc_vehicles[0] == 0 and AUV_A.loc_vehicles[1] == 1
            and AUV_A.loc_vehicles[2] == 1)

    elps_time = 50

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

    # There has been no update from B or C since last 'surface'
    # hence data rendered uncertain and B & C removed from loc_vehicles

    assert (AUV_A.loc_vehicles[0] == 0 and AUV_A.loc_vehicles[1] == 0
            and AUV_A.loc_vehicles[2] == 0)

    AUV_B.sat_up(base, elps_time)
    AUV_B.sat_down(base, config.swarm_size, elps_time)

    # There has been an update from A since last sat comm hence A kept
    # in loc vehicles but no update from C means C is removed.

    assert (AUV_B.loc_vehicles[0] == 1 and AUV_B.loc_vehicles[1] == 0
            and AUV_B.loc_vehicles[2] == 0)
Exemplo n.º 35
0
def test_download():
    AUV_A = Vehicle(0, 3, 10, 10, 0, 0)
    AUV_B = Vehicle(1, 3, 499, 0, 0, 0)
    AUV_C = Vehicle(2, 3, 998, 0, 0, 0)

    config = sim_config('tests/config/sim_config.csv')
    base = Base_Station(3)

    AUV_A.sat_up(base, 1)
    AUV_B.sat_up(base, 1)
    AUV_C.sat_up(base, 1)

    AUV_A.sat_down(base, 3, 1)

    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)
Exemplo n.º 36
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)
Exemplo n.º 37
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
Exemplo n.º 38
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]
Exemplo n.º 39
0
# call methods and attributes to test

# create 2 car instances
# make car accelerate and make them break
# make car honk and park

# create 2 plane instances here
# make plane accelerate and make them break
# make plane fly and land

from Car_class import Car
from Plane_class import plane
from Vehicle_class import Vehicle

# create 2 vehicle instances
vehicle1 = Vehicle(8, 12)
vehicle2 = Vehicle(5, 9)

# call methods and attributes to test
print("Testing Vehicle acceleration - expected result 'Vroom'' ")
vehicle1.accelerate()
vehicle2.accelerate()

print("Testing Vehicle breaking - expected result 'Slow down'")
vehicle1.car_break()
vehicle2.car_break()

print(
    "Testing Vehicle with Passengers = 8 and Cargo = 12. Expected result: 8, 12"
)
print(vehicle1.n_passengers)
Exemplo n.º 40
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)
Exemplo n.º 41
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
Exemplo n.º 42
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]
Exemplo n.º 43
0
def test_waypoint_sequence():
    AUV = Vehicle(0, 1, 50, 50, -49, 0)
    config = sim_config('config/sim_config.csv')
    AUV.waypoints = [[50,50,-50],[100,100,0]]
    AUV.move_to_waypoint()
    assert AUV.current_waypoint == 1
Exemplo n.º 44
0
def test_download():
    AUV_A = Vehicle(0, 3, 10, 10, 0, 0)
    AUV_B = Vehicle(1, 3, 499, 0, 0, 0)
    AUV_C = Vehicle(2, 3, 998, 0, 0, 0)

    config = sim_config('tests/config/sim_config.csv')
    base = Base_Station(3)

    AUV_A.sat_up(base, 1)
    AUV_B.sat_up(base, 1)
    AUV_C.sat_up(base, 1)

    AUV_A.sat_down(base, 3, 1)

    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)
Exemplo n.º 45
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
Exemplo n.º 46
0
def test_sat_loc_vehicles():
    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)

    assert (AUV_A.loc_vehicles[0] == 0 and
            AUV_A.loc_vehicles[1] == 1 and
            AUV_A.loc_vehicles[2] == 1
            )

    elps_time = 50

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

    # There has been no update from B or C since last 'surface'
    # hence data rendered uncertain and B & C removed from loc_vehicles

    assert (AUV_A.loc_vehicles[0] == 0 and
            AUV_A.loc_vehicles[1] == 0 and
            AUV_A.loc_vehicles[2] == 0
            )

    AUV_B.sat_up(base, elps_time)
    AUV_B.sat_down(base, config.swarm_size, elps_time)

    # There has been an update from A since last sat comm hence A kept
    # in loc vehicles but no update from C means C is removed.

    assert (AUV_B.loc_vehicles[0] == 1 and
            AUV_B.loc_vehicles[1] == 0 and
            AUV_B.loc_vehicles[2] == 0
            )
Exemplo n.º 47
0
def test_sat_commd():
    AUV_A = Vehicle(0, 3, 10, 10, 0, 0)

    config = sim_config('tests/config/sim_config.csv')
    base = Base_Station(config.swarm_size)
    elps_time = 0

    AUV_A.sat_comms(base, config, elps_time)
    assert AUV_A.state == 3
    assert AUV_A.sat_commd == 0

    AUV_A.pitch = AUV_A.config.max_pitch
    AUV_A.v = 0

    AUV_A.sat_comms(base, config, elps_time)
    assert AUV_A.state == 3
    assert AUV_A.sat_commd == 1

    elps_time = 181/config.time_step
    AUV_A.waypoints = [[2,2,2],[4,4,4],[5,5,5]]
    AUV_A.sat_comms(base, config, elps_time)
    assert AUV_A.state == 0
    assert AUV_A.sat_commd == 1

    AUV_A.z = -1
    AUV_A.sat_comms(base, config, elps_time)

    assert AUV_A.sat_commd == 0