def main(demo_mode, real_engine, setter=None):
    # used to randomly color the vehicles
    random.seed(1)
    start_sumo("cfg/freeway.sumo.cfg", False)
    plexe = Plexe()
    traci.addStepListener(plexe)
    step = 0
    while running(demo_mode, step, 6000):

        # when reaching 60 seconds, reset the simulation when in demo_mode
        if demo_mode and step == 6000:
            start_sumo("cfg/freeway.sumo.cfg", True)
            step = 0
            random.seed(1)

        traci.simulationStep()

        if step == 1:
            add_vehicles(plexe, N_VEHICLES, 150, real_engine)
            add_vehicle(plexe, "v0", 140, 1, 25, "passenger")
            add_vehicle(plexe, "v1", 250, 0, 20, "passenger2")
            traci.gui.trackVehicle("View #0", LEADER)
            traci.gui.setZoom("View #0", 50000)

        if real_engine and setter is not None:
            # if we are running with the dashboard, update its values
            tracked_id = traci.gui.getTrackedVehicle("View #0")
            if tracked_id != "":
                ed = plexe.get_engine_data(tracked_id)
                vd = plexe.get_vehicle_data(tracked_id)
                setter(ed[RPM], ed[GEAR], vd.speed, vd.acceleration)

        step += 1

    traci.close()
예제 #2
0
def add_vehicles(n, real_engine=False):
    """
    Adds a platoon of n vehicles to the simulation, plus an additional one
    farther away that wants to join the platoon
    :param n: number of vehicles of the platoon
    :param real_engine: set to true to use the realistic engine model,
    false to use a first order lag model
    :return: returns the topology of the platoon, i.e., a dictionary which
    indicates, for each vehicle, who is its leader and who is its front
    vehicle. The topology can the be used by the data exchange logic to
    automatically fetch data from leading and front vehicle to feed the CACC
    """
    # add a platoon of n vehicles
    topology = {}
    for i in range(n):
        vid = "v.%d" % i
        add_vehicle(vid, (n - i + 1) * (DISTANCE + LENGTH) + 50, 0, SPEED,
                    DISTANCE, real_engine)
        change_lane(vid, 0)
        if i == 0:
            set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
        else:
            set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.CACC)
        if i > 0:
            topology[vid] = {"front": "v.%d" % (i - 1), "leader": LEADER}
    # add a vehicle that wants to join the platoon
    vid = "v.%d" % n
    add_vehicle(vid, 10, 1, SPEED, DISTANCE, real_engine)
    change_lane(vid, 1)
    set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
    set_par(vid, cc.PAR_CACC_SPACING, JOIN_DISTANCE)
    return topology
def main(demo_mode, real_engine, setter=None):

    start_sumo("cfg/freeway.sumo.cfg", False)
    plexe = Plexe()
    traci.addStepListener(plexe)
    step = 0
    state_left = None
    state_right = None
    random.seed(1)
    while running(demo_mode, step, 6000):

        if demo_mode and step == 6000:
            start_sumo("cfg/freeway.sumo.cfg", True)
            step = 0
            random.seed(1)

        traci.simulationStep()

        if step == 1:
            add_platooning_vehicle(plexe, "p0", 150, 0, 25, 5, real_engine)
            add_vehicle(plexe, "v0", 140, 1, 25, "passenger")
            add_vehicle(plexe, "v1", 250, 0, 20, "passenger2")
            traci.gui.trackVehicle("View #0", "p0")
            traci.gui.setZoom("View #0", 50000)
            plexe.set_active_controller("p0", ACC)
            plexe.set_cc_desired_speed("p0", 25)
            traci.vehicle.setSpeedMode("p0", 0)

        if step > 1:
            state = traci.vehicle.getLaneChangeState("p0", 1)[0]
            if state_left != state:
                state_left = state
                str_status = get_status(state)
                print("Step %d, vehicle p0. Lane change status (LEFT ): %s" %
                      (step, str_status))
            state = traci.vehicle.getLaneChangeState("p0", -1)[0]
            if state_right != state:
                state_right = state
                str_status = get_status(state)
                print("Step %d, vehicle p0. Lane change status (RIGHT): %s" %
                      (step, str_status))

        if real_engine and setter is not None:
            # if we are running with the dashboard, update its values
            tracked_id = traci.gui.getTrackedVehicle("View #0")
            if tracked_id != "":
                ed = plexe.get_engine_data(tracked_id)
                vd = plexe.get_vehicle_data(tracked_id)
                setter(ed[RPM], ed[GEAR], vd.speed, vd.acceleration)

        step += 1

    traci.close()
예제 #4
0
def add_vehicles():
    """
    Adds the vehicles to the simulation
    """
    for i in range(len(VEHICLES)):
        vid = VEHICLES[i]
        add_vehicle(vid, 10, i, 0, 5)
        change_lane(vid, i)
        set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
        set_par(vid, cc.CC_PAR_VEHICLE_ENGINE_MODEL,
                cc.CC_ENGINE_MODEL_REALISTIC)
        set_par(vid, cc.CC_PAR_VEHICLES_FILE, "vehicles.xml")
        set_par(vid, cc.CC_PAR_VEHICLE_MODEL, vid)
        set_par(vid, cc.PAR_FIXED_ACCELERATION, cc.pack(1, 0))
예제 #5
0
def client_choose_command_list(client):
    command = ''
    while command != 'exit':
        command = input('command> : ')
        if command == 'list all free hours':
            list_all_free_hours()
        if command == 'list free hours for date':
            list_free_hours_date()
        if command == 'save repair hour':
            save_repair_hour()
        if command == 'update repair hour':
            update_repair_hour()
        if command == 'delete repair hour':
            delete_repair_hour()
        if command == 'add vehicle':
            add_vehicle(client)
        if command == 'update vehicle':
            update_vehicle()
        if command == 'delete vehicle':
            delete_vehicle(client)

    print('Goodbye!')
def add_vehicles(n, batch_num, list_of_leaders, platoon_len, fromEdge,
                 real_engine):
    """
    This function adds n number of vehicles as a platoon
    to 3 lanes of the source edge
    It also assigns the route of each member of a lane platoon
    based on the lane it is found on
    Param n : Total len of platoon
    Param batch num: nth batch of planes inserted so far starting
    for the particular lane
    Param platoon_len: len of platoon in secondary formation
    Param sourceEdge: Which sourcr to add vehicles to
    """
    start_from = n * batch_num  # start naming vehs from this number
    end_at = start_from + platoon_len  # stop at this number
    index = fromEdge.split("e")[1]
    if index == "0":
        exitEdges = ['exit0', 'exit1', 'exit2']
    elif index == "1":
        exitEdges = ['exit1', 'exit2', 'exit3']
    elif index == "2":
        exitEdges = ['exit2', 'exit3', 'exit1']
    else:
        exitEdges = ['exit3', 'exit1', 'exit2']
    # Add vehicles to lane 1 of the source edge and assign them 1st exit ramp
    for i in range(start_from, end_at):
        lane = 1
        vid = "v.%d" % i
        toEdge = exitEdges[0]
        route = "route_" + index + "_" + str(lane - 1)
        add_vehicle(vid, route, (end_at - i + 1) * (DISTANCE + LENGTH) + 100,
                    lane, SPEED, DISTANCE, real_engine)
        set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
        change_lane(vid, lane)
    start_from = start_from + platoon_len  # start naming vehs from this num
    end_at = start_from + platoon_len  # stop here
    # Add vehicles to lane 2 of the source edge and assign them 2nd exit ramp
    for i in range(start_from, end_at):
        lane = 2
        vid = "v.%d" % i
        toEdge = exitEdges[1]
        route = "route_" + index + "_" + str(lane - 1)
        add_vehicle(vid, route, (end_at - i + 1) * (DISTANCE + LENGTH) + 100,
                    lane, SPEED, DISTANCE, real_engine)
        set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
        change_lane(vid, lane)
    start_from = start_from + platoon_len  # start naming from this number
    end_at = start_from + platoon_len  # stop naming from this
    # Add vehicles to lane 3 of the source edge and assign them 3rd exit ramp
    for i in range(start_from, end_at):
        lane = 3
        vid = "v.%d" % i
        toEdge = exitEdges[2]
        route = route = "route_" + index + "_" + str(lane - 1)
        add_vehicle(vid, route, (end_at - i + 1) * (DISTANCE + LENGTH) + 100,
                    lane, SPEED, DISTANCE, real_engine)
        set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
        change_lane(vid, lane)
def add_vehicles(n, batch_num, platoon_len, fromEdge, real_engine):
    # route param: for each source edge there are four possible routes
    start_from = n*batch_num
    end_at = start_from + platoon_len
    
    index = fromEdge.split("e")[1]
    if index == "0":
        exitEdges =['exit0', 'exit1', 'exit2']
    elif index=="1":
        exitEdges =['exit1', 'exit2', 'exit3']
    elif index == "2":
        exitEdges =['exit2', 'exit3', 'exit1']
    else: # index = "3"
        exitEdges =['exit3', 'exit1', 'exit2']

    for i in range(start_from, end_at):
        lane = 1
        vid = "v.%d" % i
        toEdge= exitEdges[0]
        route = "route_"+index+"_"+str(lane-1)
        add_vehicle(vid, route, (end_at - i + 1) * (DISTANCE + LENGTH) +
                    100, lane, SPEED, DISTANCE, real_engine)
        set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
        change_lane(vid, lane)

    start_from = start_from + platoon_len
    end_at = start_from + platoon_len

    for i in range(start_from, end_at):
        lane = 2
        vid = "v.%d" % i
        toEdge= exitEdges[1]
        route = "route_"+index+"_"+str(lane-1)
        add_vehicle(vid, route, (end_at - i + 1) * (DISTANCE + LENGTH) +
                    100, lane, SPEED, DISTANCE, real_engine)
        set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
        change_lane(vid, lane)

    start_from = start_from + platoon_len
    end_at = start_from + platoon_len

    for i in range(start_from, end_at):
        lane = 3
        vid = "v.%d" % i
        toEdge= exitEdges[2]
        route = route = "route_"+index+"_"+str(lane-1)
        add_vehicle(vid, route, (end_at - i + 1) * (DISTANCE + LENGTH) +
                    100, lane, SPEED, DISTANCE, real_engine)
        set_par(vid, cc.PAR_ACTIVE_CONTROLLER, cc.ACC)
        change_lane(vid, lane)