def add(routeID, edges): traci._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID, 1+4+sum(map(len, edges))+4*len(edges)) traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(edges)) for e in edges: traci._message.string += struct.pack("!i", len(e)) + e traci._sendExact()
def addFull(vehID, routeID, typeID="DEFAULT_VEHTYPE", depart=None, departLane="0", departPos="base", departSpeed="0", arrivalLane="current", arrivalPos="max", arrivalSpeed="current", fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0): messageString = struct.pack("!Bi", tc.TYPE_COMPOUND, 14) if depart is None: depart = str(traci.simulation.getCurrentTime() / 1000.) for val in (routeID, typeID, depart, departLane, departPos, departSpeed, arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line): messageString += struct.pack("!Bi", tc.TYPE_STRING, len(val)) + str(val) messageString += struct.pack("!Bi", tc.TYPE_INTEGER, personCapacity) messageString += struct.pack("!Bi", tc.TYPE_INTEGER, personNumber) traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.ADD_FULL, vehID, len(messageString)) traci._message.string += messageString traci._sendExact()
def setCompleteRedYellowGreenDefinition(tlsID, tls): """setCompleteRedYellowGreenDefinition(string, ) -> None . """ length = 1 + 4 + 1 + 4 + \ len(tls._subID) + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 # tls parameter itemNo = 1 + 1 + 1 + 1 + 1 for p in tls._phases: length += 1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + len(p._phaseDef) itemNo += 4 traci._beginMessage( tc.CMD_SET_TL_VARIABLE, tc.TL_COMPLETE_PROGRAM_RYG, tlsID, length) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, itemNo) # programID traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(tls._subID)) + str(tls._subID) traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, 0) # type # subitems traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0) # index traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, tls._currentPhaseIndex) # phaseNo traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, len(tls._phases)) for p in tls._phases: traci._message.string += struct.pack("!BiBiBi", tc.TYPE_INTEGER, p._duration, tc.TYPE_INTEGER, p._duration1, tc.TYPE_INTEGER, p._duration2) traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(p._phaseDef)) + str(p._phaseDef) traci._sendExact()
def getDistance2D(x1, y1, x2, y2, isGeo=False, isDriving=False): """getDistance2D(double, double, double, double, boolean, boolean) -> double Returns the distance between the two coordinate pairs (x1,y1) and (x2,y2) If isGeo=True, coordinates are interpreted as longitude and latitude rather than cartesian coordinates in meters. If isDriving=True, the coordinates are mapped onto the road network and the length of the shortest route in the network is returned. Otherwise, the straight-line distance is returned. """ posType = tc.POSITION_2D if isGeo: posType = tc.POSITION_LON_LAT distType = tc.REQUEST_AIRDIST if isDriving: distType = tc.REQUEST_DRIVINGDIST traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.DISTANCE_REQUEST, "", 1 + 4 + 1 + 8 + 8 + 1 + 8 + 8 + 1) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 3) traci._message.string += struct.pack("!Bdd", posType, x1, y1) traci._message.string += struct.pack("!BddB", posType, x2, y2, distType) return traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.DISTANCE_REQUEST, "").readDouble()
def slowDown(vehID, speed, duration): traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_SLOWDOWN, vehID, 1 + 4 + 1 + 8 + 1 + 4) traci._message.string += struct.pack("!BiBdBi", tc.TYPE_COMPOUND, 2, tc.TYPE_DOUBLE, speed, tc.TYPE_INTEGER, duration) traci._sendExact()
def changeLane(vehID, laneIndex, duration): traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_CHANGELANE, vehID, 1 + 4 + 1 + 1 + 1 + 4) traci._message.string += struct.pack("!BiBBBi", tc.TYPE_COMPOUND, 2, tc.TYPE_BYTE, laneIndex, tc.TYPE_INTEGER, duration) traci._sendExact()
def setStop(vehID, edgeID, pos=1., laneIndex=0, duration=2**31 - 1, flags=STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, until=-1): """setStop(string, string, double, integer, integer, integer, double, integer) -> None Adds or modifies a stop with the given parameters. The duration and the until attribute are in milliseconds. """ traci._beginMessage( tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_STOP, vehID, 1 + 4 + 1 + 4 + len(edgeID) + 1 + 8 + 1 + 1 + 1 + 4 + 1 + 1 + 1 + 8 + 1 + 4) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 7) traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(edgeID)) + str(edgeID) traci._message.string += struct.pack("!BdBBBiBB", tc.TYPE_DOUBLE, pos, tc.TYPE_BYTE, laneIndex, tc.TYPE_INTEGER, duration, tc.TYPE_BYTE, flags) traci._message.string += struct.pack("!BdBi", tc.TYPE_DOUBLE, startPos, tc.TYPE_INTEGER, until) traci._sendExact()
def moveTo(vehID, laneID, pos): traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_MOVE_TO, vehID, 1 + 4 + 1 + 4 + len(laneID) + 1 + 8) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) traci._message.packString(laneID) traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, pos) traci._sendExact()
def setColor(poiID, color): traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_COLOR, poiID, 1 + 1 + 1 + 1 + 1) traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3])) traci._sendExact()
def setEffort(vehID, begTime, endTime, edgeID, effort): traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID) + 1 + 4) traci._message.string += struct.pack( "!BiBiBiBi", tc.TYPE_COMPOUND, 4, tc.TYPE_INTEGER, begTime, tc.TYPE_INTEGER, endTime, tc.TYPE_STRING, len(edgeID)) + edgeID traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, effort) traci._sendExact()
def setColor(typeID, color): """setColor(string, (integer, integer, integer, integer)) -> None Sets the color of this type. """ traci._beginMessage(tc.CMD_SET_VEHICLETYPE_VARIABLE, tc.VAR_COLOR, typeID, 1+1+1+1+1) traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3])) traci._sendExact()
def add(poiID, x, y, color, poiType="", layer=0): traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.ADD, poiID, 1+4 + 1+4+len(poiType) + 1+1+1+1+1 + 1+4 + 1+8+8) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4) traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(poiType)) + poiType traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3])) traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, layer) traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y) traci._sendExact()
def moveTo(vehID, laneID, pos): traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_MOVE_TO, vehID, 1 + 4 + 1 + 4 + len(laneID) + 1 + 8) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(laneID)) + laneID traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, pos) traci._sendExact()
def setEffort(edgeID, effort): """setEffort(string, double) -> None Adapt the effort value used for (re-)routing for the given edge. """ traci._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1+4+1+8) traci._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, effort) traci._sendExact()
def adaptTraveltime(edgeID, time): """adaptTraveltime(string, double) -> None Adapt the travel time value (in s) used for (re-)routing for the given edge. """ traci._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1+4+1+8) traci._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, time) traci._sendExact()
def moveToVTD(vehID, edgeID, lane, x, y): traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_MOVE_TO_VTD, vehID, 1+4+1+4+len(edgeID)+1+4+1+8+1+8) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4) traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(edgeID)) + edgeID traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, lane) traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, x) traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, y) traci._sendExact()
def setType(poiID, poiType): """setType(string, string) -> None Sets the (abstract) type of the poi. """ traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_TYPE, poiID, 1+4+len(poiType)) traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(poiType)) + poiType traci._sendExact()
def setPosition(poiID, x, y): """setPosition(string, (double, double)) -> None Sets the position coordinates of the poi. """ traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_POSITION, poiID, 1+8+8) traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y) traci._sendExact()
def adaptTraveltime(edgeID, time): """adaptTraveltime(string, double) -> None Adapt the travel time value (in s) used for (re-)routing for the given edge. """ traci._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1 + 4 + 1 + 8) traci._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, time) traci._sendExact()
def setEffort(edgeID, effort): """setEffort(string, double) -> None Adapt the effort value used for (re-)routing for the given edge. """ traci._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1 + 4 + 1 + 8) traci._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, effort) traci._sendExact()
def setColor(poiID, color): """setColor(string, (integer, integer, integer, integer)) -> None Sets the rgba color of the poi. """ traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_COLOR, poiID, 1+1+1+1+1) traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3])) traci._sendExact()
def setOffset(viewID, x, y): """setOffset(string, double, double) -> None Set the current offset for the given view. """ traci._beginMessage(tc.CMD_SET_GUI_VARIABLE, tc.VAR_VIEW_OFFSET, viewID, 1+8+8) traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y) traci._sendExact()
def setBoundary(viewID, xmin, ymin, xmax, ymax): """setBoundary(string, double, double, double, double) -> None Set the current boundary for the given view (see getBoundary()). """ traci._beginMessage(tc.CMD_SET_GUI_VARIABLE, tc.VAR_VIEW_BOUNDARY, viewID, 1+8+8+8+8) traci._message.string += struct.pack("!Bdddd", tc.TYPE_BOUNDINGBOX, xmin, ymin, xmax, ymax) traci._sendExact()
def convert2D(edgeID, pos, laneIndex=0, toGeo=False): posType = tc.POSITION_2D if toGeo: posType = tc.POSITION_LAT_LON traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+4+len(edgeID)+8+1 + 1+8+8) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) traci._message.string += struct.pack("!Bi", tc.POSITION_ROADMAP, len(edgeID)) + edgeID traci._message.string += struct.pack("!dBBdd", pos, laneIndex, posType, 0., 0.) return traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "").read("!dd")
def setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time): traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID, 1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID) + 1 + 8) traci._message.string += struct.pack( "!BiBiBiBi", tc.TYPE_COMPOUND, 4, tc.TYPE_INTEGER, begTime, tc.TYPE_INTEGER, endTime, tc.TYPE_STRING, len(edgeID)) + edgeID traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, time) traci._sendExact()
def getEffort(vehID, time, edgeID): """getEffort(string, double, string) -> double . """ traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1+4+1+4+1+4+len(edgeID)) traci._message.string += struct.pack("!BiBiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time, tc.TYPE_STRING, len(edgeID)) + edgeID return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID).readDouble()
def setPosition(poiID, x, y): """setPosition(string, (double, double)) -> None Sets the position coordinates of the poi. """ traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_POSITION, poiID, 1 + 8 + 8) traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y) traci._sendExact()
def resume(vehID): """resume(string) -> None Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped). """ traci._beginMessage( tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_RESUME, vehID, 1 + 4) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0) traci._sendExact()
def add(routeID, edges): """add(string, list(string)) -> None Adds a new route with the given id consisting of the given list of edge IDs. """ traci._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID, 1 + 4 + sum(map(len, edges)) + 4 * len(edges)) traci._message.packStringList(edges) traci._sendExact()
def setType(poiID, poiType): """setType(string, string) -> None Sets the (abstract) type of the poi. """ traci._beginMessage( tc.CMD_SET_POI_VARIABLE, tc.VAR_TYPE, poiID, 1 + 4 + len(poiType)) traci._message.packString(poiType) traci._sendExact()
def getDrivingDistance2D(vehID, x, y): """getDrivingDistance2D(string, double, double) -> integer . """ traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1+4+1+4+4+1) traci._message.string += struct.pack("!BiBddB", tc.TYPE_COMPOUND, 2, tc.POSITION_2D, x, y, REQUEST_DRIVINGDIST) return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
def convert2D(edgeID, pos, laneIndex=0, toGeo=False): posType = tc.POSITION_2D if toGeo: posType = tc.POSITION_LAT_LON traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+4+len(edgeID)+8+1 + 1+1) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) traci._message.string += struct.pack("!Bi", tc.POSITION_ROADMAP, len(edgeID)) + edgeID traci._message.string += struct.pack("!dBBB", pos, laneIndex, tc.TYPE_UBYTE, posType) return traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "").read("!dd")
def setDisallowed(laneID, disallowedClasses): traci._beginMessage( tc.CMD_SET_LANE_VARIABLE, tc.LANE_DISALLOWED, laneID, 1 + 4 + sum(map(len, disallowedClasses)) + 4 * len(disallowedClasses)) traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(disallowedClasses)) for c in disallowedClasses: traci._message.string += struct.pack("!i", len(c)) + c traci._sendExact()
def setColor(vehID, color): """setColor(string, (integer, integer, integer, integer)) sets color for vehicle with the given ID. i.e. (255,0,0,0) for the color red. The fourth integer (alpha) is currently ignored """ traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_COLOR, vehID, 1+1+1+1+1) traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3])) traci._sendExact()
def getDrivingDistance2D(vehID, x, y): """getDrivingDistance2D(string, double, double) -> integer . """ traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1+4+1+8+8+1) traci._message.string += struct.pack("!BiBddB", tc.TYPE_COMPOUND, 2, tc.POSITION_2D, x, y, tc.REQUEST_DRIVINGDIST) return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
def getLeader(vehID, dist=0.): """getLeader(string, double) -> (string, double) Return the leading vehicle id together with the distance. The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap. """ traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_LEADER, vehID, 1+8) traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, dist) return _readLeader(traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_LEADER, vehID))
def getEffort(edgeID, time): """getEffort(string, double) -> double Returns the effort value used for (re-)routing which is valid on the edge at the given time. """ traci._beginMessage(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1 + 4) traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, traci._TIME2STEPS(time)) return traci._checkResult(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID).readDouble()
def getAdaptedTraveltime(edgeID, time): """getAdaptedTraveltime(string, double) -> double Returns the travel time value (in s) used for (re-)routing which is valid on the edge at the given time. """ traci._beginMessage(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1 + 4) traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, traci._TIME2STEPS(time)) return traci._checkResult(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID).readDouble()
def setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time): """setAdaptedTraveltime(string, double, string, double) -> None . """ traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID, 1+4+1+4+1+4+1+4+len(edgeID)+1+8) traci._message.string += struct.pack("!BiBiBiBi", tc.TYPE_COMPOUND, 4, tc.TYPE_INTEGER, begTime, tc.TYPE_INTEGER, endTime, tc.TYPE_STRING, len(edgeID)) + edgeID traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, time) traci._sendExact()
def convertRoad(x, y, isGeo=False): posType = tc.POSITION_2D if isGeo: posType = tc.POSITION_LAT_LON traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+8+8 + 1+4+8+1) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) traci._message.string += struct.pack("!Bdd", posType, x, y) traci._message.string += struct.pack("!BidB", tc.POSITION_ROADMAP, 0, 0., 0) result = traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "") return result.readString(), result.readDouble(), result.read("!B")[0]
def getDrivingDistance(vehID, edgeID, pos, laneID=0): """getDrivingDistance(string, string, double, integer) -> double . """ traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1+4+1+4+len(edgeID)+4+1+1) traci._message.string += struct.pack("!BiBi", tc.TYPE_COMPOUND, 2, tc.POSITION_ROADMAP, len(edgeID)) + edgeID traci._message.string += struct.pack("!dBB", pos, laneID, REQUEST_DRIVINGDIST) return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
def setType(polygonID, polygonType): """setType(string, string) -> None Sets the (abstract) type of the polygon. """ traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_TYPE, polygonID, 1 + 4 + len(polygonType)) traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(polygonType)) + polygonType traci._sendExact()
def setShape(polygonID, shape): """setShape(string, list((double, double))) -> None Sets the shape (list of 2D-positions) of this polygon. """ traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_SHAPE, polygonID, 1 + 1 + len(shape) * (8 + 8)) traci._message.string += struct.pack("!BB", tc.TYPE_POLYGON, len(shape)) for p in shape: traci._message.string += struct.pack("!dd", p) traci._sendExact()
def setEffort(vehID, begTime, endTime, edgeID, effort): """setEffort(string, double, string, double) -> None . """ traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1+4+1+4+1+4+1+4+len(edgeID)+1+4) traci._message.string += struct.pack("!BiBiBiBi", tc.TYPE_COMPOUND, 4, tc.TYPE_INTEGER, begTime, tc.TYPE_INTEGER, endTime, tc.TYPE_STRING, len(edgeID)) + edgeID traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, effort) traci._sendExact()
def getDrivingDistance(vehID, edgeID, pos, laneID=0): """getDrivingDistance(string, string, double, integer) -> double . """ traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1+4+1+4+len(edgeID) + 8+1+1) traci._message.string += struct.pack("!BiBi", tc.TYPE_COMPOUND, 2, tc.POSITION_ROADMAP, len(edgeID)) + edgeID traci._message.string += struct.pack("!dBB", pos, laneID, tc.REQUEST_DRIVINGDIST) return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
def getLeader(vehID, dist=0.): """getLeader(string, double) -> (string, double) Return the leading vehicle id together with the distance. The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap. """ traci._beginMessage( tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_LEADER, vehID, 1 + 8) traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, dist) return _readLeader(traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_LEADER, vehID))
def setStop(vehID, edgeID, pos=1., laneIndex=0, duration=2**31 - 1): traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_STOP, vehID, 1 + 4 + 1 + 4 + len(edgeID) + 1 + 8 + 1 + 1 + 1 + 4) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4) traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(edgeID)) + edgeID traci._message.string += struct.pack("!BdBBBi", tc.TYPE_DOUBLE, pos, tc.TYPE_BYTE, laneIndex, tc.TYPE_INTEGER, duration) traci._sendExact()
def convertRoad(x, y, isGeo=False): posType = tc.POSITION_2D if isGeo: posType = tc.POSITION_LAT_LON traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+8+8 + 1+1) traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) traci._message.string += struct.pack("!Bdd", posType, x, y) traci._message.string += struct.pack("!BB", tc.TYPE_UBYTE, tc.POSITION_ROADMAP) result = traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "") return result.readString(), result.readDouble(), result.read("!B")[0]
def getAdaptedTraveltime(vehID, time, edgeID): """getAdaptedTraveltime(string, double, string) -> double . """ traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID, 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID)) traci._message.string += struct.pack("!BiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time) traci._message.packString(edgeID) return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID).readDouble()
def getAdaptedTraveltime(vehID, time, edgeID): """getAdaptedTraveltime(string, double, string) -> double . """ traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID, 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID)) traci._message.string += struct.pack("!BiBiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time, tc.TYPE_STRING, len(edgeID)) + str(edgeID) return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID).readDouble()
def add(routeID, edges): """add(string, list(string)) -> None Adds a new route with the given id consisting of the given list of edge IDs. """ traci._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID, 1 + 4 + sum(map(len, edges)) + 4 * len(edges)) traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(edges)) for e in edges: traci._message.string += struct.pack("!i", len(e)) + str(e) traci._sendExact()
def setColor(polygonID, color): """setColor(string, (integer, integer, integer, integer)) -> None Sets the rgba color of this polygon. """ traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_COLOR, polygonID, 1 + 1 + 1 + 1 + 1) traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3])) traci._sendExact()