How to use the traci.vehicle.getLaneIndex function in traci

To help you get started, we’ve selected a few traci examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse / sumo / tests / complex / sumo / ToCDevice / Accel_during_ToC_preparation / runner.py View on Github external
def run():
    """execute the TraCI control loop"""
    step = 0
    lastLane = traci.vehicle.getLaneIndex(ToC_vehicle)
    t = traci.simulation.getTime()
    print("Time %s: Current lane of veh '%s': %s" % (t, ToC_vehicle, lastLane))
    traci.simulationStep()
    while traci.simulation.getMinExpectedNumber() > 0:
        if step == 2:
            requestToC(ToC_vehicle, timeTillMRM)
            t = traci.simulation.getTime()
            print("Requested ToC of veh0 at t=%s (until t=%s)" % (t, t + timeTillMRM))
        newLane = traci.vehicle.getLaneIndex(ToC_vehicle)
        acceleration = traci.vehicle.getAcceleration(ToC_vehicle)
        accel = traci.vehicle.getAccel(ToC_vehicle)
        if newLane != lastLane:
            t = traci.simulation.getTime()
            print("Time %s: veh '%s' changed lanes. Current: %s" % (t, ToC_vehicle, newLane))
            lastLane = newLane
        print("Acceleration = %s" % acceleration)
        print("Accel = %s" % accel)
        printToCParams(ToC_vehicle, True)
        sys.stdout.flush()
        step += 1
        traci.simulationStep()
github eclipse / sumo / tests / complex / sumo / ToCDevice / Keep_right_during_MRM / runner.py View on Github external
def run():
    """execute the TraCI control loop"""
    step = 0
    lastLane = traci.vehicle.getLaneIndex(ToC_vehicle)
    t = traci.simulation.getTime()
    print("Time %s: Current lane of veh '%s': %s" % (t, ToC_vehicle, lastLane))
    traci.simulationStep()
    while traci.simulation.getMinExpectedNumber() > 0:
        if step == 30:
            requestToC(ToC_vehicle, timeTillMRM)
            t = traci.simulation.getTime()
            print("Requested ToC of veh0 at t=%s (until t=%s)" % (t, t + timeTillMRM))
        newLane = traci.vehicle.getLaneIndex(ToC_vehicle)
        if newLane != lastLane:
            t = traci.simulation.getTime()
            print("Time %s: veh '%s' changed lanes. Current: %s" % (t, ToC_vehicle, newLane))
            lastLane = newLane

        printToCParams(ToC_vehicle, True)
        sys.stdout.flush()
        step += 1
        traci.simulationStep()
github eclipse / sumo / tests / complex / traci / ContextSubscriptionFilters / leadFollow / laneChangeLeft / runner.py View on Github external
break

            print("[%03d] Context results for vehicle '%s':" % (step, objID))
            for v in sorted(traci.vehicle.getContextSubscriptionResults(objID) or []):
                print(v)

        if not subscribed:
            print("Subscribing to vehicle context of object '%s'" % (objID))
            traci.vehicle.subscribeContext(objID, traci.constants.CMD_GET_VEHICLE_VARIABLE,
                                           viewRange, [traci.constants.VAR_POSITION])
            sys.stdout.flush()

            traci.vehicle.addSubscriptionFilterLCManeuver(1)
            # advice all vehicle not to change lanes
            for vehID in traci.vehicle.getIDList():
                traci.vehicle.changeLane(vehID, traci.vehicle.getLaneIndex(vehID), 111)

            subscribed = True
        step += 1

    print("Print ended at step %s" % step)
    traci.close()
    sys.stdout.flush()
github eclipse / sumo / tests / complex / sumo / ToCDevice / LC_during_MRM / runner.py View on Github external
traci.vehicle.changeLane(ToC_vehicle, 0, 5.)
            t = traci.simulation.getTime()
            print("Time %s: Requested lanechange of veh '%s' to lane %s" % (t, ToC_vehicle, 0))
        if step == 53:
            traci.vehicle.changeLane(ToC_vehicle, 1, 4.)
            t = traci.simulation.getTime()
            print("Time %s: Requested lanechange of veh '%s' to lane %s" % (t, ToC_vehicle, 1))
        if step == 75:
            traci.vehicle.changeLane(ToC_vehicle, 0, 10.)
            t = traci.simulation.getTime()
            print("Time %s: Requested lanechange of veh '%s' to lane %s" % (t, ToC_vehicle, 0))
        if step == 78:
            traci.vehicle.changeLane(ToC_vehicle, 1, 2.)
            t = traci.simulation.getTime()
            print("Time %s: Requested lanechange of veh '%s' to lane %s" % (t, ToC_vehicle, 1))
        newLane = traci.vehicle.getLaneIndex(ToC_vehicle)
        if newLane != lastLane:
            t = traci.simulation.getTime()
            print("Time %s: veh '%s' changed lanes. Current: %s" % (t, ToC_vehicle, newLane))
            lastLane = newLane

        printToCParams(ToC_vehicle, True)
        sys.stdout.flush()
        step += 1
        traci.simulationStep()
github eclipse / sumo / tests / complex / sumo / ToCDevice / Accel_during_ToC_preparation / runner.py View on Github external
def run():
    """execute the TraCI control loop"""
    step = 0
    lastLane = traci.vehicle.getLaneIndex(ToC_vehicle)
    t = traci.simulation.getTime()
    print("Time %s: Current lane of veh '%s': %s" % (t, ToC_vehicle, lastLane))
    traci.simulationStep()
    while traci.simulation.getMinExpectedNumber() > 0:
        if step == 2:
            requestToC(ToC_vehicle, timeTillMRM)
            t = traci.simulation.getTime()
            print("Requested ToC of veh0 at t=%s (until t=%s)" % (t, t + timeTillMRM))
        newLane = traci.vehicle.getLaneIndex(ToC_vehicle)
        acceleration = traci.vehicle.getAcceleration(ToC_vehicle)
        accel = traci.vehicle.getAccel(ToC_vehicle)
        if newLane != lastLane:
            t = traci.simulation.getTime()
            print("Time %s: veh '%s' changed lanes. Current: %s" % (t, ToC_vehicle, newLane))
            lastLane = newLane
        print("Acceleration = %s" % acceleration)
github eclipse / sumo / tests / complex / sumo / ToCDevice / No_accel_during_ToC_preparation_default / runner.py View on Github external
def run():
    """execute the TraCI control loop"""
    step = 0
    lastLane = traci.vehicle.getLaneIndex(ToC_vehicle)
    t = traci.simulation.getTime()
    print("Time %s: Current lane of veh '%s': %s" % (t, ToC_vehicle, lastLane))
    traci.simulationStep()
    while traci.simulation.getMinExpectedNumber() > 0:
        if step == 2:
            requestToC(ToC_vehicle, timeTillMRM)
            t = traci.simulation.getTime()
            print("Requested ToC of veh0 at t=%s (until t=%s)" % (t, t + timeTillMRM))
        newLane = traci.vehicle.getLaneIndex(ToC_vehicle)
        acceleration = traci.vehicle.getAcceleration(ToC_vehicle)
        accel = traci.vehicle.getAccel(ToC_vehicle)
        if newLane != lastLane:
            t = traci.simulation.getTime()
            print("Time %s: veh '%s' changed lanes. Current: %s" % (t, ToC_vehicle, newLane))
            lastLane = newLane
        print("Acceleration = %s" % acceleration)
        print("Accel = %s" % accel)
        printToCParams(ToC_vehicle, True)
        sys.stdout.flush()
        step += 1
        traci.simulationStep()
github susomena / PERMIT / platooning.py View on Github external
# Conference on Intelligent Transportation Systems (ITSC), Las
                # Palmas, Spain, 2015, pp. 1964-1970
                lane = traci.vehicle.getLaneIndex(self._members[i])
                lane_front = traci.vehicle.getLaneIndex(self._members[i - 1])
                if lane != lane_front:
                    utils.set_par(self._members[i], cc.PAR_ACTIVE_CONTROLLER, cc.FAKED_CACC)

                if self._states[i - 2] is not self.WAITING and self._states[i - 2] is not self.GOING_TO_POSITION \
                        or i == 1:
                    self._topology[self._members[i]]["leader"] = self._members[0]
                    self._states[i] = self.GOING_TO_POSITION
                else:
                    self._topology[self._members[i]]["leader"] = self._members[i - 1]

            if self._states[i] is self.GOING_TO_POSITION:
                lane = traci.vehicle.getLaneIndex(self._members[i])
                lane_front = traci.vehicle.getLaneIndex(self._members[i - 1])
                if lane != lane_front:
                    utils.set_par(self._members[i], cc.PAR_ACTIVE_CONTROLLER, cc.FAKED_CACC)
                else:
                    utils.set_par(self._members[i], cc.PAR_ACTIVE_CONTROLLER, cc.CACC)

                front_distance = gap_between_vehicles(self._members[i], self._members[i - 1])[0]
                no_need_to_open_gap = already_in_lane(self._members[i], self._desired_lane)
                no_need_to_open_gap = no_need_to_open_gap and already_in_lane(self._members[i - 1], self._desired_lane)
                if self._safe_gap - 1 < front_distance < self._safe_gap + 1 \
                        and self._states[i - 1] is not self.GOING_TO_POSITION or no_need_to_open_gap:
                    self._states[i] = self.CHECK_LANE
                else:
                    utils.set_par(self._members[i], cc.PAR_CACC_SPACING, self._safe_gap)

            if self._states[i] is self.CHECK_LANE:
github flow-project / flow / cistar-dev / cistar / core / vehicle.py View on Github external
def __init__(self, veh_id):
        self.veh_id = veh_id
        self.type = traci.vehicle.getTypeID(veh_id)
        self.edge = traci.vehicle.getRoadID(veh_id)
        self.position = traci.vehicle.getLanePosition(veh_id)
        self.lane = traci.vehicle.getLaneIndex(veh_id)
        self.speed = traci.vehicle.getSpeed(veh_id)
        self.length = traci.vehicle.getLength(veh_id)
        self.max_speed = traci.vehicle.getMaxSpeed(veh_id)
        self.traci.vehicle.setSpeedMode(veh_id, 0)
github susomena / PERMIT / platooning.py View on Github external
lanes = [traci.vehicle.getLaneIndex(vehicles[0])]
        lane_ids = [traci.vehicle.getLaneID(vehicles[0])]

        for i in range(1, len(vehicles)):
            traci.vehicle.setLaneChangeMode(vehicles[i], utils.FIX_LC)
            self._topology[vehicles[i]] = {"leader": vehicles[0], "front": vehicles[i - 1]}
            self._states.append(self.WAITING)
            utils.set_par(vehicles[i], cc.PAR_ACTIVE_CONTROLLER, cc.CACC)
            min_gap = traci.vehicle.getMinGap(vehicles[i])
            # The CACC controller tries to keep (desired_gap + min_gap)
            # meters as intra-platoon spacing
            utils.set_par(vehicles[i], cc.PAR_CACC_SPACING, desired_gap - min_gap)
            traci.vehicle.setSpeedFactor(vehicles[i], 1.05)

            lanes.append(traci.vehicle.getLaneIndex(vehicles[i]))
            lane_ids.append(traci.vehicle.getLaneID(vehicles[i]))

        self._members = vehicles
        self._desired_gap = desired_gap
        self._safe_gap = safe_gap
        self._merging = merging
        self._splitting = False
        self._vehicles_splitting = [False] * len(vehicles)

        leader_max_speed = traci.vehicle.getAllowedSpeed(vehicles[0])
        lane = traci.vehicle.getLaneID(vehicles[0])
        road_max_speed = traci.lane.getMaxSpeed(lane)
        # If the platoon is fast enough merge all vehicles to the leftmost
        # lane, else merge to the rightmost lane
        self._desired_lane = max(lanes) if leader_max_speed > 0.9 * road_max_speed else min(lanes)
        self._desired_lane_id = lane_ids[lanes.index(self._desired_lane)]