How to use the traci.vehicle.getPosition 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 / traci / vehicle / vehicle / runner.py View on Github external
def check(vehID):
    print("vehicles", traci.vehicle.getIDList())
    print("vehicle count", traci.vehicle.getIDCount())
    print("examining", vehID)
    print("speed", traci.vehicle.getSpeed(vehID))
    print("speedLat", traci.vehicle.getLateralSpeed(vehID))
    print("speed w/o traci", traci.vehicle.getSpeedWithoutTraCI(vehID))
    print("acceleration", traci.vehicle.getAcceleration(vehID))
    print("pos", posToString(traci.vehicle.getPosition(vehID)))
    print("pos3D", posToString(traci.vehicle.getPosition3D(vehID)))
    print("angle", traci.vehicle.getAngle(vehID))
    print("road", traci.vehicle.getRoadID(vehID))
    print("lane", traci.vehicle.getLaneID(vehID))
    print("laneIndex", traci.vehicle.getLaneIndex(vehID))
    print("type", traci.vehicle.getTypeID(vehID))
    print("routeID", traci.vehicle.getRouteID(vehID))
    print("routeIndex", traci.vehicle.getRouteIndex(vehID))
    print("route", traci.vehicle.getRoute(vehID))
    print("lanePos", traci.vehicle.getLanePosition(vehID))
    print("color", traci.vehicle.getColor(vehID))
    print("bestLanes", traci.vehicle.getBestLanes(vehID))
    print("CO2", traci.vehicle.getCO2Emission(vehID))
    print("CO", traci.vehicle.getCOEmission(vehID))
    print("HC", traci.vehicle.getHCEmission(vehID))
    print("PMx", traci.vehicle.getPMxEmission(vehID))
github eclipse / sumo / tests / complex / traci / bugs / ticket2321 / runner.py View on Github external
import sumolib  # noqa

traci.start([sumolib.checkBinary('sumo'), "-c", "sumo.sumocfg"])
firstPos = None
endPos = None

vehID = "v0"
traci.simulationStep()
traci.route.add("r0", ["SC", "CN"])
traci.vehicle.addLegacy(vehID, "r0")
traci.vehicle.setImperfection(vehID, 0)
while traci.simulation.getMinExpectedNumber() > 0:
    traci.simulationStep()
    try:
        if firstPos is None:
            firstPos = traci.vehicle.getPosition(vehID)
            endPos = traci.simulation.convert2D("CN", 90)
        currPos = traci.vehicle.getPosition(vehID)
        currEdge = traci.vehicle.getRoadID(vehID)
        currLanePos = traci.vehicle.getLanePosition(vehID)
        print(("step=%s road=%s lane=%s pos=%.2f dist=%.2f simDist=%.2f simDistToEnd=%.2f distToInt=%.2f " +
               "distToEnd=%.2f simDist2DToInt=%.2f simDist2DToEnd=%.2f") % (
            traci.simulation.getTime(),
            currEdge,
            traci.vehicle.getLaneID(vehID),
            traci.vehicle.getLanePosition(vehID),
            traci.vehicle.getDistance(vehID),
            traci.simulation.getDistance2D(firstPos[0], firstPos[1], currPos[0], currPos[1], isDriving=True),
            traci.simulation.getDistance2D(currPos[0], currPos[1], endPos[0], endPos[1], isDriving=True),
            traci.vehicle.getDrivingDistance(vehID, ":C_10", 13.8),
            traci.vehicle.getDrivingDistance(vehID, "CN", 90),
            traci.simulation.getDistanceRoad(currEdge, currLanePos, ":C_10", 13.8),
github eclipse / sumo / tests / complex / traci / contextSubscriptions / runner.py View on Github external
traci.poi.add("poi", 400, 500, (1, 0, 0, 0))
    traci.polygon.add("poly", ((400, 400), (450, 400), (450, 400)), (1, 0, 0, 0))
    subscribed = False
    while not step > traciEndTime:
        # print(step)
        responses = traci.simulationStep()
        near1 = set()
        if objID in module.getAllContextSubscriptionResults():
            for v in module.getContextSubscriptionResults(objID):
                near1.add(v)
            # print(objID, "context:", sorted(near1))
        vehs = traci.vehicle.getIDList()
        persons = traci.person.getIDList()
        pos = {}
        for v in vehs:
            pos[v] = traci.vehicle.getPosition(v)
        for p in persons:
            pos[p] = traci.person.getPosition(p)
        shape = None
        egoPos = None
        if hasattr(module, "getPosition"):
            egoPos = module.getPosition(objID)
        elif hasattr(module, "getShape"):
            shape = module.getShape(objID)
        elif module == traci.edge:
            # it's a hack, I know,  but do we really need to introduce
            # edge.getShape?
            shape = traci.lane.getShape(objID + "_0")
        near2 = set()
        for v in pos:
            if egoPos:
                if math.sqrt(dist2(egoPos, pos[v])) < viewRange:
github eclipse / sumo / tests / complex / traci / pythonApi / moveToXY / short_edges / runner.py View on Github external
def check(x, y, angle, exLane, exPos, exPosLat, comment):
    traci.vehicle.moveToXY(vehID, "", 0, x, y, angle, keepRoute=2)
    traci.simulationStep()
    x2, y2 = traci.vehicle.getPosition(vehID)
    lane2 = traci.vehicle.getLaneID(vehID)
    pos2 = traci.vehicle.getLanePosition(vehID)
    posLat2 = traci.vehicle.getLateralLanePosition(vehID)
    if (abs(x - x2) > 0.1 or
            abs(y - y2) > 0.1 or
            (exLane is not None and exLane != lane2) or
            (exPos is not None and abs(exPos - pos2) > 0.1) or
            (exPosLat is not None and abs(exPosLat - posLat2) > 0.1)):
        print(comment, ("failed: x=%s, x2=%s,   y=%s, y2=%s,   lane=%s, lane2=%s, pos=%s, pos2=%s   " +
                        "posLat=%s posLat2=%s") % (x, x2, y, y2, exLane, lane2, exPos, pos2, exPosLat, posLat2))
    else:
        # print(comment, "success")
        pass
github eclipse / sumo / tests / complex / traci / vehicle / vehicle / runner.py View on Github external
def checkOffRoad(vehID):
    print(("veh", vehID,
           "speed", traci.vehicle.getSpeed(vehID),
           "pos", posToString(traci.vehicle.getPosition(vehID)),
           "pos3d", posToString(traci.vehicle.getPosition3D(vehID)),
           "angle", traci.vehicle.getAngle(vehID),
           "road", traci.vehicle.getRoadID(vehID),
           "lane", traci.vehicle.getLaneID(vehID),
           "lanePos", traci.vehicle.getLanePosition(vehID),
           "CO2", traci.vehicle.getCO2Emission(vehID)
           ))
github eclipse / sumo / tests / complex / traci / pythonApi / moveToXY / multi_lane_sublane / runner.py View on Github external
def check(x, y, angle, exLane, exPos, exPosLat, comment):
    traci.vehicle.moveToXY(vehID, "", 0, x, y, angle)
    traci.simulationStep()
    x2, y2 = traci.vehicle.getPosition(vehID)
    lane2 = traci.vehicle.getLaneID(vehID)
    pos2 = traci.vehicle.getLanePosition(vehID)
    posLat2 = traci.vehicle.getLateralLanePosition(vehID)
    if (abs(x - x2) > 0.1 or
            abs(y - y2) > 0.1 or
            (exLane != lane2 and exLane is not None) or
            (exPos is not None and abs(exPos - pos2) > 0.1) or
            (exPosLat is not None and abs(exPosLat - posLat2) > 0.1)):
        print(comment, ("failed: x=%s, x2=%s,   y=%s, y2=%s,   lane=%s, lane2=%s, pos=%s, pos2=%s   " +
                        "posLat=%s posLat2=%s") % (x, x2, y, y2, exLane, lane2, exPos, pos2, exPosLat, posLat2))
    else:
        # (comment, "success")
        pass
    print(traci.simulation.getTime(),
          " lane=%s" % lane2,
          # " route=%s" % str(traci.vehicle.getRoute(vehID)),
github remidomingues / ASTra / astra / vehicle.py View on Github external
def sendVehiclesCoordinates(vehiclesId, mtraci, outputSocket, mVehicles):
    """
    Gets every vehicles position from SUMO and send then these ones to the remote client by an output socket
    """
    # If the simulated vehicles number we have to take into account is not 0
    vehiclesPos = []
    vehiclesPos.append(constants.VEHICLE_COORDS_RESPONSE_HEADER)
    
    mVehicles.acquire()
    for vehicleId in vehiclesId:
        try:
            mtraci.acquire()
            coords = traci.vehicle.getPosition(vehicleId)
            coordsGeo = traci.simulation.convertGeo(coords[0], coords[1], False)
            mtraci.release()
    
            # Build the message to send by the output socket
            vehiclesPos.append(constants.SEPARATOR)
            vehiclesPos.append(vehicleId)
            vehiclesPos.append(constants.SEPARATOR)
            vehiclesPos.append(str(coordsGeo[0]))
            vehiclesPos.append(constants.SEPARATOR)
            vehiclesPos.append(str(coordsGeo[1]))
        except:
            mtraci.release()
        
    mVehicles.release()
    
    # Send the position of each vehicle by the output socket
github Ujwal2910 / Smart-Traffic-Signals-in-India-using-Deep-Reinforcement-Learning-and-Advanced-Computer-Vision / Traffic Modeling Real Vision Based / dual_intersection.py View on Github external
]
        '''
        l_leftcount = 0
        l_rightcount = 0
        l_topcount = 0
        l_bottomcount = 0

        r_leftcount = 0
        r_rightcount = 0
        r_topcount = 0
        r_bottomcount = 0

        vehicleList = traci.vehicle.getIDList()

        for id in vehicleList:
            x, y = traci.vehicle.getPosition(id)

            if x < 500 and x > 450 and y < 520 and y > 510:
                l_leftcount += 1
            else:
                if x < 510 and x > 500 and y < 500 and y > 450:
                    l_bottomcount += 1
                else:
                    if x < 570 and x > 520 and y < 510 and y > 500:
                        l_rightcount += 1
                    else:
                        if x < 520 and x > 510 and y < 570 and y > 520:
                            l_topcount += 1

            if x < 600 and x > 550 and y < 520 and y > 510:
                r_leftcount += 1
            else:
github Ujwal2910 / Smart-Traffic-Signals-in-India-using-Deep-Reinforcement-Learning-and-Advanced-Computer-Vision / Traffic Modeling Real Vision Based / baseline_single_intersection.py View on Github external
for _ in range(transition_time):
        traci.simulationStep()




        leftcount = 0
        rightcount = 0
        topcount = 0
        bottomcount = 0
        vehicleList = traci.vehicle.getIDList()

        print("Traffic : ")

        for id in vehicleList:
            x, y = traci.vehicle.getPosition(id)

            if x < 110 and x > 60 and y < 130 and y > 120:
                leftcount += 1
            else:
                if x < 120 and x > 110 and y < 110 and y > 600:
                    bottomcount += 1
                else:
                    if x < 180 and x > 130 and y < 120 and y > 110:
                        rightcount += 1
                    else:
                        if x < 130 and x > 120 and y < 180 and y > 130:
                            topcount += 1

        print("Left : ", leftcount)
        print("Right : ", rightcount)
        print("Top : ", topcount)
github Ujwal2910 / Smart-Traffic-Signals-in-India-using-Deep-Reinforcement-Learning-and-Advanced-Computer-Vision / Traffic Modeling Real Vision Based / single_intersection.py View on Github external
for _ in range(transition_time):
        traci.simulationStep()




        leftcount = 0
        rightcount = 0
        topcount = 0
        bottomcount = 0
        vehicleList = traci.vehicle.getIDList()

        print("Traffic : ")

        for id in vehicleList:
            x, y = traci.vehicle.getPosition(id)

            if x < 110 and x > 60 and y < 130 and y > 120:
                leftcount += 1
            else:
                if x < 120 and x > 110 and y < 110 and y > 60:
                    bottomcount += 1
                else:
                    if x < 180 and x > 130 and y < 120 and y > 110:
                        rightcount += 1
                    else:
                        if x < 130 and x > 120 and y < 180 and y > 130:
                            topcount += 1

        print("Left : ", leftcount)
        print("Right : ", rightcount)
        print("Top : ", topcount)