traci._vehicle
1# -*- coding: utf-8 -*- 2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3# Copyright (C) 2011-2026 German Aerospace Center (DLR) and others. 4# This program and the accompanying materials are made available under the 5# terms of the Eclipse Public License 2.0 which is available at 6# https://www.eclipse.org/legal/epl-2.0/ 7# This Source Code may also be made available under the following Secondary 8# Licenses when the conditions for such availability set forth in the Eclipse 9# Public License 2.0 are satisfied: GNU General Public License, version 2 10# or later which is available at 11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 14# @file _vehicle.py 15# @author Michael Behrisch 16# @author Lena Kalleske 17# @author Mario Krumnow 18# @author Lena Kalleske 19# @author Jakob Erdmann 20# @author Laura Bieker 21# @author Daniel Krajzewicz 22# @author Leonhard Luecken 23# @author Mirko Barthauer 24# @date 2011-03-09 25 26from __future__ import absolute_import 27import warnings 28from ._vehicletype import VTypeDomain 29from . import constants as tc 30from .exceptions import TraCIException, deprecated, alias_param 31from ._lane import _readLinks 32 33 34_legacyGetLeader = True 35 36 37class StopData(object): 38 39 def __init__(self, 40 lane="", 41 startPos=-1, 42 endPos=-1, 43 stoppingPlaceID="", 44 stopFlags=0, 45 duration=-1, 46 until=-1, 47 intendedArrival=-1, 48 arrival=-1, 49 depart=-1, 50 split="", 51 join="", 52 actType="", 53 tripId="", 54 line="", 55 speed=0): 56 self.lane = lane 57 self.startPos = startPos 58 self.endPos = endPos 59 self.stoppingPlaceID = stoppingPlaceID 60 self.stopFlags = stopFlags 61 self.duration = duration 62 self.until = until 63 self.intendedArrival = intendedArrival 64 self.arrival = arrival 65 self.depart = depart 66 self.split = split 67 self.join = join 68 self.actType = actType 69 self.tripId = tripId 70 self.line = line 71 self.speed = speed 72 73 def __attr_repr__(self, attrname, default=""): 74 if getattr(self, attrname) == default: 75 return "" 76 else: 77 val = getattr(self, attrname) 78 if val == tc.INVALID_DOUBLE_VALUE: 79 val = "INVALID" 80 return "%s=%s" % (attrname, val) 81 82 def __repr__(self): 83 return "StopData(%s)" % ', '.join([v for v in [ 84 self.__attr_repr__("lane"), 85 self.__attr_repr__("startPos"), 86 self.__attr_repr__("endPos"), 87 self.__attr_repr__("stoppingPlaceID"), 88 self.__attr_repr__("stopFlags"), 89 self.__attr_repr__("duration", tc.INVALID_DOUBLE_VALUE), 90 self.__attr_repr__("until", tc.INVALID_DOUBLE_VALUE), 91 self.__attr_repr__("intendedArrival", tc.INVALID_DOUBLE_VALUE), 92 self.__attr_repr__("arrival", tc.INVALID_DOUBLE_VALUE), 93 self.__attr_repr__("depart", tc.INVALID_DOUBLE_VALUE), 94 self.__attr_repr__("split"), 95 self.__attr_repr__("join"), 96 self.__attr_repr__("actType"), 97 self.__attr_repr__("tripId"), 98 self.__attr_repr__("line"), 99 self.__attr_repr__("speed", 0), 100 ] if v != ""]) 101 102 103def _readStopData(result): 104 result.read("!iB") # numCompounds, TYPE_INT 105 numStops = result.read("!i")[0] 106 nextStops = [] 107 for _ in range(numStops): 108 lane = result.readTypedString() 109 endPos = result.readTypedDouble() 110 stoppingPlaceID = result.readTypedString() 111 stopFlags = result.readTypedInt() 112 duration = result.readTypedDouble() 113 until = result.readTypedDouble() 114 startPos = result.readTypedDouble() 115 intendedArrival = result.readTypedDouble() 116 arrival = result.readTypedDouble() 117 depart = result.readTypedDouble() 118 split = result.readTypedString() 119 join = result.readTypedString() 120 actType = result.readTypedString() 121 tripId = result.readTypedString() 122 line = result.readTypedString() 123 speed = result.readTypedDouble() 124 nextStops.append(StopData(lane, startPos, endPos, stoppingPlaceID, 125 stopFlags, duration, until, intendedArrival, arrival, depart, split, join, 126 actType, tripId, line, speed)) 127 return tuple(nextStops) 128 129 130def _readBestLanes(result): 131 result.read("!iB") 132 nbLanes = result.read("!i")[0] # Length 133 lanes = [] 134 for _ in range(nbLanes): 135 laneID = result.readTypedString() 136 length, occupation, offset = result.read("!BdBdBb")[1::2] 137 allowsContinuation = bool(result.read("!BB")[1]) 138 numNextLanes = result.read("!Bi")[1] 139 nextLanes = [result.readString() for __ in range(numNextLanes)] 140 lanes.append((laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes))) 141 return tuple(lanes) 142 143 144def _readLeader(result): 145 assert result.read("!i")[0] == 2 # compound size 146 vehicleID = result.readTypedString() 147 dist = result.readTypedDouble() 148 if vehicleID == "" and _legacyGetLeader: 149 return None 150 return vehicleID, dist 151 152 153def _readFollower(result): 154 # note: merge this with _readLeader once the default of _legacyGetLeader has 155 # been changed to False 156 assert result.read("!i")[0] == 2 # compound size 157 vehicleID = result.readTypedString() 158 dist = result.readTypedDouble() 159 return vehicleID, dist 160 161 162def _readNeighbors(result): 163 """ result has structure: 164 byte(TYPE_COMPOUND) | length(neighList) | Per list entry: string(vehID) | double(dist) 165 """ 166 num = result.readInt() # length of the vehicle list 167 neighs = [] 168 for _ in range(num): 169 vehID = result.readString() 170 dist = result.readDouble() 171 neighs.append((vehID, dist)) 172 return tuple(neighs) 173 174 175def _readNextTLS(result): 176 result.read("!iB") # numCompounds, TYPE_INT 177 numTLS = result.read("!i")[0] 178 nextTLS = [] 179 for _ in range(numTLS): 180 result.read("!B") 181 tlsID = result.readString() 182 tlsIndex, dist, state = result.read("!BiBdBB")[1::2] 183 nextTLS.append((tlsID, tlsIndex, dist, chr(state))) 184 return tuple(nextTLS) 185 186 187def _readNextStops(result): 188 result.read("!iB") # numCompounds, TYPE_INT 189 numStops = result.read("!i")[0] 190 nextStop = [] 191 for _ in range(numStops): 192 result.read("!B") 193 lane = result.readString() 194 result.read("!B") 195 endPos = result.readDouble() 196 result.read("!B") 197 stoppingPlaceID = result.readString() 198 result.read("!B") 199 stopFlags = result.readInt() 200 result.read("!B") 201 duration = result.readDouble() 202 result.read("!B") 203 until = result.readDouble() 204 nextStop.append((lane, endPos, stoppingPlaceID, stopFlags, duration, until)) 205 return tuple(nextStop) 206 207 208def _readJunctionFoes(result): 209 result.read("!Bi") 210 nbJunctionFoes = result.readInt() 211 junctionFoes = [] 212 for _ in range(nbJunctionFoes): 213 result.read("!B") 214 foeId = result.readString() 215 result.read("!B") 216 egoDist = result.readDouble() 217 result.read("!B") 218 foeDist = result.readDouble() 219 result.read("!B") 220 egoExitDist = result.readDouble() 221 result.read("!B") 222 foeExitDist = result.readDouble() 223 result.read("!B") 224 egoLane = result.readString() 225 result.read("!B") 226 foeLane = result.readString() 227 result.read("!B") 228 egoResponse = bool(result.read("!B")[0]) 229 result.read("!B") 230 foeResponse = bool(result.read("!B")[0]) 231 junctionFoes.append((foeId, egoDist, foeDist, egoExitDist, foeExitDist, 232 egoLane, foeLane, egoResponse, foeResponse)) 233 return tuple(junctionFoes) 234 235 236_RETURN_VALUE_FUNC = {tc.VAR_ROUTE_VALID: lambda result: bool(result.read("!i")[0]), 237 tc.VAR_BEST_LANES: _readBestLanes, 238 tc.VAR_LEADER: _readLeader, 239 tc.VAR_FOLLOWER: _readFollower, 240 tc.VAR_NEIGHBORS: _readNeighbors, 241 tc.VAR_NEXT_TLS: _readNextTLS, 242 tc.VAR_NEXT_STOPS: _readNextStops, 243 tc.VAR_NEXT_LINKS: _readLinks, 244 tc.VAR_NEXT_STOPS2: _readStopData, 245 tc.VAR_FOES: _readJunctionFoes, 246 # ignore num compounds and type int 247 tc.CMD_CHANGELANE: lambda result: result.read("!iBiBi")[2::2]} 248 249 250class VehicleDomain(VTypeDomain): 251 # imported for backwards compatibility 252 STOP_DEFAULT = tc.STOP_DEFAULT 253 STOP_PARKING = tc.STOP_PARKING 254 STOP_TRIGGERED = tc.STOP_TRIGGERED 255 STOP_CONTAINER_TRIGGERED = tc.STOP_CONTAINER_TRIGGERED 256 STOP_BUS_STOP = tc.STOP_BUS_STOP 257 STOP_CONTAINER_STOP = tc.STOP_CONTAINER_STOP 258 STOP_CHARGING_STATION = tc.STOP_CHARGING_STATION 259 STOP_PARKING_AREA = tc.STOP_PARKING_AREA 260 DEPART_TRIGGERED = tc.DEPARTFLAG_TRIGGERED 261 DEPART_CONTAINER_TRIGGERED = tc.DEPARTFLAG_CONTAINER_TRIGGERED 262 DEPART_NOW = tc.DEPARTFLAG_NOW 263 DEPART_SPEED_RANDOM = tc.DEPARTFLAG_SPEED_RANDOM 264 DEPART_SPEED_MAX = tc.DEPARTFLAG_SPEED_MAX 265 DEPART_LANE_RANDOM = tc.DEPARTFLAG_LANE_RANDOM 266 DEPART_LANE_FREE = tc.DEPARTFLAG_LANE_FREE 267 DEPART_LANE_ALLOWED_FREE = tc.DEPARTFLAG_LANE_ALLOWED_FREE 268 DEPART_LANE_BEST_FREE = tc.DEPARTFLAG_LANE_BEST_FREE 269 DEPART_LANE_FIRST_ALLOWED = tc.DEPARTFLAG_LANE_FIRST_ALLOWED 270 271 def __init__(self): 272 VTypeDomain.__init__(self, "vehicle", tc.CMD_GET_VEHICLE_VARIABLE, tc.CMD_SET_VEHICLE_VARIABLE, 273 tc.CMD_SUBSCRIBE_VEHICLE_VARIABLE, tc.RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE, 274 tc.CMD_SUBSCRIBE_VEHICLE_CONTEXT, tc.RESPONSE_SUBSCRIBE_VEHICLE_CONTEXT, 275 _RETURN_VALUE_FUNC, subscriptionDefault=(tc.VAR_ROAD_ID, tc.VAR_LANEPOSITION)) 276 277 def getSpeed(self, vehID): 278 """getSpeed(string) -> double 279 280 Returns the (longitudinal) speed in m/s of the named vehicle within the last step. 281 """ 282 return self._getUniversal(tc.VAR_SPEED, vehID) 283 284 def getLateralSpeed(self, vehID): 285 """getLateralSpeed(string) -> double 286 287 Returns the lateral speed in m/s of the named vehicle within the last step. 288 """ 289 return self._getUniversal(tc.VAR_SPEED_LAT, vehID) 290 291 def getAcceleration(self, vehID): 292 """getAcceleration(string) -> double 293 294 Returns the acceleration in m/s^2 of the named vehicle within the last step. 295 """ 296 return self._getUniversal(tc.VAR_ACCELERATION, vehID) 297 298 def getSpeedWithoutTraCI(self, vehID): 299 """getSpeedWithoutTraCI(string) -> double 300 Returns the speed that the vehicle would drive if no speed-influencing 301 command such as setSpeed or slowDown was given. 302 """ 303 return self._getUniversal(tc.VAR_SPEED_WITHOUT_TRACI, vehID) 304 305 def getPosition(self, vehID): 306 """getPosition(string) -> (double, double) 307 308 Returns the position of the named vehicle within the last step [m,m]. 309 """ 310 return self._getUniversal(tc.VAR_POSITION, vehID) 311 312 def getPosition3D(self, vehID): 313 """getPosition3D(string) -> (double, double, double) 314 315 Returns the position of the named vehicle within the last step [m,m,m]. 316 """ 317 return self._getUniversal(tc.VAR_POSITION3D, vehID) 318 319 def getAngle(self, vehID): 320 """getAngle(string) -> double 321 322 Returns the angle in degrees of the named vehicle within the last step. 323 """ 324 return self._getUniversal(tc.VAR_ANGLE, vehID) 325 326 def getRoadID(self, vehID): 327 """getRoadID(string) -> string 328 329 Returns the id of the edge the named vehicle was at within the last step. 330 """ 331 return self._getUniversal(tc.VAR_ROAD_ID, vehID) 332 333 def getDeparture(self, vehID): 334 """getDeparture(string) -> double 335 336 Returns the actual departure time in seconds 337 """ 338 return self._getUniversal(tc.VAR_DEPARTURE, vehID) 339 340 def getDepartDelay(self, vehID): 341 """getDepartDelay(string) -> double 342 343 Returns the delay between intended and actual departure in seconds 344 """ 345 return self._getUniversal(tc.VAR_DEPART_DELAY, vehID) 346 347 def getLaneID(self, vehID): 348 """getLaneID(string) -> string 349 350 Returns the id of the lane the named vehicle was at within the last step. 351 """ 352 return self._getUniversal(tc.VAR_LANE_ID, vehID) 353 354 def getShadowLaneID(self, vehID): 355 """getShadowLaneID(string) -> string 356 357 Returns the id of the shadow lane if the vehicle is currently changing lanes. 358 """ 359 return self._getUniversal(tc.VAR_SHADOW_LANE_ID, vehID) 360 361 def getLaneIndex(self, vehID): 362 """getLaneIndex(string) -> integer 363 364 Returns the index of the lane the named vehicle was at within the last step. 365 """ 366 return self._getUniversal(tc.VAR_LANE_INDEX, vehID) 367 368 def getSegmentID(self, vehID): 369 """getSegmentID(string) -> string 370 371 Returns the id of the segment the named vehicle was at within the last step (mesosim). 372 """ 373 return self._getUniversal(tc.VAR_SEGMENT_ID, vehID) 374 375 def getSegmentIndex(self, vehID): 376 """getSegmentIndex(string) -> integer 377 378 Returns the index of the segment the named vehicle was at within the last step (mesosim). 379 """ 380 return self._getUniversal(tc.VAR_SEGMENT_INDEX, vehID) 381 382 def getTypeID(self, vehID): 383 """getTypeID(string) -> string 384 385 Returns the id of the type of the named vehicle. 386 """ 387 return self._getUniversal(tc.VAR_TYPE, vehID) 388 389 def getRouteID(self, vehID): 390 """getRouteID(string) -> string 391 392 Returns the id of the route of the named vehicle. 393 """ 394 return self._getUniversal(tc.VAR_ROUTE_ID, vehID) 395 396 def getRouteIndex(self, vehID): 397 """getRouteIndex(string) -> int 398 399 Returns the index of the current edge within the vehicles route or -1 if the 400 vehicle has not yet departed 401 """ 402 return self._getUniversal(tc.VAR_ROUTE_INDEX, vehID) 403 404 def getRoute(self, vehID): 405 """getRoute(string) -> tuple(string) 406 407 Returns the ids of the edges the vehicle's route is made of. 408 """ 409 return self._getUniversal(tc.VAR_EDGES, vehID) 410 411 def getLanePosition(self, vehID): 412 """getLanePosition(string) -> double 413 414 The position of the vehicle along the lane measured in m. 415 """ 416 return self._getUniversal(tc.VAR_LANEPOSITION, vehID) 417 418 def getCO2Emission(self, vehID): 419 """getCO2Emission(string) -> double 420 421 Returns the CO2 emission in mg/s for the last time step. 422 Multiply by the step length to get the value for one step. 423 """ 424 return self._getUniversal(tc.VAR_CO2EMISSION, vehID) 425 426 def getCOEmission(self, vehID): 427 """getCOEmission(string) -> double 428 429 Returns the CO emission in mg/s for the last time step. 430 Multiply by the step length to get the value for one step. 431 """ 432 return self._getUniversal(tc.VAR_COEMISSION, vehID) 433 434 def getHCEmission(self, vehID): 435 """getHCEmission(string) -> double 436 437 Returns the HC emission in mg/s for the last time step. 438 Multiply by the step length to get the value for one step. 439 """ 440 return self._getUniversal(tc.VAR_HCEMISSION, vehID) 441 442 def getPMxEmission(self, vehID): 443 """getPMxEmission(string) -> double 444 445 Returns the particular matter emission in mg/s for the last time step. 446 Multiply by the step length to get the value for one step. 447 """ 448 return self._getUniversal(tc.VAR_PMXEMISSION, vehID) 449 450 def getNOxEmission(self, vehID): 451 """getNOxEmission(string) -> double 452 453 Returns the NOx emission in mg/s for the last time step. 454 Multiply by the step length to get the value for one step. 455 """ 456 return self._getUniversal(tc.VAR_NOXEMISSION, vehID) 457 458 def getFuelConsumption(self, vehID): 459 """getFuelConsumption(string) -> double 460 461 Returns the fuel consumption in mg/s for the last time step. 462 Multiply by the step length to get the value for one step. 463 """ 464 return self._getUniversal(tc.VAR_FUELCONSUMPTION, vehID) 465 466 def getNoiseEmission(self, vehID): 467 """getNoiseEmission(string) -> double 468 469 Returns the noise emission in db for the last time step. 470 """ 471 return self._getUniversal(tc.VAR_NOISEEMISSION, vehID) 472 473 def getElectricityConsumption(self, vehID): 474 """getElectricityConsumption(string) -> double 475 476 Returns the electricity consumption in Wh/s for the last time step. 477 Multiply by the step length to get the value for one step. 478 """ 479 return self._getUniversal(tc.VAR_ELECTRICITYCONSUMPTION, vehID) 480 481 def getPersonNumber(self, vehID): 482 """getPersonNumber(string) -> integer 483 Returns the total number of persons which includes those defined 484 using attribute 'personNumber' as well as <person>-objects who are riding in 485 this vehicle. 486 """ 487 return self._getUniversal(tc.VAR_PERSON_NUMBER, vehID) 488 489 def getPersonIDList(self, vehID): 490 """getPersonIDList(string) -> tuple(string) 491 Returns the tuple of persons who are riding in this vehicle. 492 """ 493 return self._getUniversal(tc.LAST_STEP_PERSON_ID_LIST, vehID) 494 495 def getAdaptedTraveltime(self, vehID, time, edgeID): 496 """getAdaptedTraveltime(string, double, string) -> double 497 498 Returns the information about the travel time of edge "edgeID" valid 499 for the given time from the vehicle's internal edge weights 500 container (see setAdaptedTraveltime). 501 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 502 """ 503 return self._getUniversal(tc.VAR_EDGE_TRAVELTIME, vehID, "tds", 2, time, edgeID) 504 505 def getEffort(self, vehID, time, edgeID): 506 """getEffort(string, double, string) -> double 507 508 Returns the information about the effort needed for edge "edgeID" valid 509 for the given time from the vehicle's internal effort 510 container (see setEffort). 511 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 512 """ 513 return self._getUniversal(tc.VAR_EDGE_EFFORT, vehID, "tds", 2, time, edgeID) 514 515 def isRouteValid(self, vehID): 516 """isRouteValid(string) -> bool 517 Returns whether the current vehicle route is connected for the vehicle 518 class of the given vehicle. 519 """ 520 return self._getUniversal(tc.VAR_ROUTE_VALID, vehID) 521 522 def getSignals(self, vehID): 523 """getSignals(string) -> integer 524 525 Returns an integer encoding the state of a vehicle's signals. 526 """ 527 return self._getUniversal(tc.VAR_SIGNALS, vehID) 528 529 def getLateralLanePosition(self, vehID): 530 """getLateralLanePosition(string) -> double 531 532 Returns the lateral position of the vehicle on its current lane measured in m. 533 """ 534 return self._getUniversal(tc.VAR_LANEPOSITION_LAT, vehID) 535 536 def getAllowedSpeed(self, vehID): 537 """getAllowedSpeed(string) -> double 538 539 Returns the maximum allowed speed on the current lane regarding speed factor in m/s for this vehicle. 540 """ 541 return self._getUniversal(tc.VAR_ALLOWED_SPEED, vehID) 542 543 def getWaitingTime(self, vehID): 544 """getWaitingTime(string) -> double 545 The waiting time of a vehicle is defined as the time (in seconds) spent with a 546 speed below 0.1m/s since the last time it was faster than 0.1m/s. 547 (basically, the waiting time of a vehicle is reset to 0 every time it moves). 548 A vehicle that is stopping intentionally with a <stop> does not accumulate waiting time. 549 """ 550 return self._getUniversal(tc.VAR_WAITING_TIME, vehID) 551 552 def getAccumulatedWaitingTime(self, vehID): 553 """getAccumulatedWaitingTime(string) -> double 554 The accumulated waiting time of a vehicle collects the vehicle's waiting time 555 over a certain time interval (interval length is set per option '--waiting-time-memory') 556 """ 557 return self._getUniversal(tc.VAR_ACCUMULATED_WAITING_TIME, vehID) 558 559 def getLaneChangeMode(self, vehID): 560 """getLaneChangeMode(string) -> integer 561 562 Gets the vehicle's lane change mode as a bitset. 563 """ 564 return self._getUniversal(tc.VAR_LANECHANGE_MODE, vehID) 565 566 def getSpeedMode(self, vehID): 567 """getSpeedMode(string) -> int 568 The speed mode of a vehicle 569 """ 570 return self._getUniversal(tc.VAR_SPEEDSETMODE, vehID) 571 572 def getSlope(self, vehID): 573 """getSlope(string) -> double 574 The slope at the current position of the vehicle in degrees 575 """ 576 return self._getUniversal(tc.VAR_SLOPE, vehID) 577 578 def getLine(self, vehID): 579 """getLine(string) -> string 580 581 Returns the line information of this vehicle. 582 """ 583 return self._getUniversal(tc.VAR_LINE, vehID) 584 585 def getVia(self, vehID): 586 """getVia(string) -> tuple(string) 587 588 Returns the ids of via edges for this vehicle 589 """ 590 return self._getUniversal(tc.VAR_VIA, vehID) 591 592 def getLastActionTime(self, vehID): 593 """getLastActionTime(string) -> double 594 595 Returns the time in s of last action point for this vehicle. 596 """ 597 return self._getUniversal(tc.VAR_LASTACTIONTIME, vehID) 598 599 def getBestLanes(self, vehID): 600 """getBestLanes(string) -> tuple(data) 601 where data is a tuple of (laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes)) 602 603 For each lane of the current edge a data tuple is returned where the 604 entries have the following meaning: 605 - laneID: the id of that lane on the current edge 606 - the length that can be driven without lane change (measured from the start of that lane) 607 - the occupation on the future lanes (brutto vehicle lengths) 608 - the offset of that lane from the lane that would be strategically 609 preferred (this is the lane that requires the least future lane 610 changes or a lane that needs to be used for stopping) 611 - whether that lane allows continuing the route (for at least one more edge) 612 - the sequence of lanes that would be driven starting at laneID if no 613 lane change were to take place 614 """ 615 return self._getUniversal(tc.VAR_BEST_LANES, vehID) 616 617 def getLeader(self, vehID, dist=100.): 618 """getLeader(string, double) -> (string, double) 619 620 Return the leading vehicle id together with the distance. The distance 621 is measured from the front + minGap to the back of the leader, so it does not include the 622 minGap of the vehicle. 623 The dist parameter defines the minimum lookahead, 0 calculates a lookahead from the brake gap. 624 Note that the returned leader may be further away than the given dist and that the vehicle 625 will only look on its current best lanes and not look beyond the end of its final route edge. 626 627 In the case where no leader is found, the function returns 'None'. 628 This special case is deprecated. The future behavior is to return the 629 pair ("", -1) when no leader is found. 630 The function 'traci.setLegacyGetLeader(bool) can be used to switch 631 between both behaviors. 632 """ 633 return self._getUniversal(tc.VAR_LEADER, vehID, "d", dist) 634 635 def getFollower(self, vehID, dist=0.): 636 """getFollower(string, double) -> (string, double) 637 638 Return the following vehicle id together with the distance. The distance 639 is measured from the front + minGap of the follower to the back of vehID, so it does not include the 640 minGap of the follower. 641 The dist parameter defines the minimum lookback, 0 calculates the 642 lookback distance from the braking distance at 4.5m/s^2 at 2*roadSpeedLimit. 643 Due to junctions and lane merges, there may be multiple followers. 644 In this case, the "critical" follower is returned. This is the follower 645 where the value of (getSecureGap - gap) is maximal. 646 Note that the returned follower may be further away than the given dist. 647 """ 648 return self._getUniversal(tc.VAR_FOLLOWER, vehID, "d", dist) 649 650 def getRightFollowers(self, vehID, blockingOnly=False): 651 """ getRightFollowers(string, bool) -> tuple(tuple(string, double)) 652 Convenience method, see getNeighbors() 653 """ 654 if blockingOnly: 655 mode = 5 656 else: 657 mode = 1 658 return self.getNeighbors(vehID, mode) 659 660 def getRightLeaders(self, vehID, blockingOnly=False): 661 """ getRightLeaders(string, bool) -> tuple(tuple(string, double)) 662 Convenience method, see getNeighbors() 663 """ 664 if blockingOnly: 665 mode = 7 666 else: 667 mode = 3 668 return self.getNeighbors(vehID, mode) 669 670 def getLeftFollowers(self, vehID, blockingOnly=False): 671 """ getLeftFollowers(string, bool) -> tuple(tuple(string, double)) 672 Convenience method, see getNeighbors() 673 """ 674 if blockingOnly: 675 mode = 4 676 else: 677 mode = 0 678 return self.getNeighbors(vehID, mode) 679 680 def getLeftLeaders(self, vehID, blockingOnly=False): 681 """ getLeftLeaders(string, bool) -> tuple(tuple(string, double)) 682 Convenience method, see getNeighbors() 683 """ 684 if blockingOnly: 685 mode = 6 686 else: 687 mode = 2 688 return self.getNeighbors(vehID, mode) 689 690 def getNeighbors(self, vehID, mode): 691 """ getNeighbors(string, byte) -> tuple(tuple(string, double)) 692 693 The parameter mode is a bitset (UBYTE), specifying the following: 694 bit 1: query lateral direction (left:0, right:1) 695 bit 2: query longitudinal direction (followers:0, leaders:1) 696 bit 3: blocking (return all:0, return only blockers:1) 697 698 The returned tuple contains pairs (ID, dist) for all lane change relevant neighboring leaders, resp. followers, 699 along with their longitudinal distance to the ego vehicle (egoFront - egoMinGap to leaderBack, resp. 700 followerFront - followerMinGap to egoBack. The value can be negative for overlapping neighs). 701 For the non-sublane case, the lists will contain at most one entry. 702 703 Note: The exact set of blockers in case blocking==1 is not determined for the sublane model, 704 but either all neighboring vehicles are returned (in case LCA_BLOCKED) or 705 none is returned (in case !LCA_BLOCKED). 706 """ 707 return self._getUniversal(tc.VAR_NEIGHBORS, vehID, "B", mode) 708 709 def getFollowSpeed(self, vehID, speed, gap, leaderSpeed, leaderMaxDecel, leaderID=""): 710 """getFollowSpeed(string, double, double, double, double, string) -> double 711 Return the follow speed computed by the carFollowModel of vehID 712 """ 713 return self._getUniversal(tc.VAR_FOLLOW_SPEED, vehID, "tdddds", 5, 714 speed, gap, leaderSpeed, leaderMaxDecel, leaderID) 715 716 def getSecureGap(self, vehID, speed, leaderSpeed, leaderMaxDecel, leaderID=""): 717 """getSecureGap(string, double, double, double, string) -> double 718 Return the secure gap computed by the carFollowModel of vehID 719 """ 720 return self._getUniversal(tc.VAR_SECURE_GAP, vehID, "tddds", 4, 721 speed, leaderSpeed, leaderMaxDecel, leaderID) 722 723 def getStopSpeed(self, vehID, speed, gap): 724 """getStopSpeed(string, double, double) -> double 725 Return the speed for stopping at gap computed by the carFollowModel of vehID 726 """ 727 return self._getUniversal(tc.VAR_STOP_SPEED, vehID, "tdd", 2, speed, gap) 728 729 def getStopDelay(self, vehID): 730 """getStopDelay(string) -> double 731 Returns the expected depart delay at the next stop (if that stop defines the 732 until-attribute) in seconds. Returns -1 if the next stop is not applicable 733 """ 734 return self._getUniversal(tc.VAR_STOP_DELAY, vehID) 735 736 def getStopArrivalDelay(self, vehID): 737 """getStopArrivalDelay(string) -> double 738 Returns the expected arrival delay at the next stop (if that stop defines the 739 arrival-attribute) in seconds. The returned value may be negative to 740 indicate early arrival. Returns INVALID_DOUBLE if the next stop is not applicable 741 """ 742 return self._getUniversal(tc.VAR_STOP_ARRIVALDELAY, vehID) 743 744 def getTimeLoss(self, vehID): 745 """getTimeLoss(string) -> double 746 Returns the time loss since departure 747 """ 748 return self._getUniversal(tc.VAR_TIMELOSS, vehID) 749 750 def getNextTLS(self, vehID): 751 """getNextTLS(string) -> tuple(tuple(string, int, double, string)) 752 753 Return tuple of upcoming traffic lights [(tlsID, tlsIndex, distance, state), ...] 754 """ 755 return self._getUniversal(tc.VAR_NEXT_TLS, vehID) 756 757 @alias_param("dist", "distance") 758 def getJunctionFoes(self, vehID, dist=0.): 759 """getJunctionFoes(string, double) -> complex 760 761 Return tuple of junction foes [(foeId, egoDist, foeDist, egoExitDist, foeExitDist, 762 egoLane, foeLane, egoResponse, foeResponse), ...] within the given distance to the given vehicle. 763 """ 764 return self._getUniversal(tc.VAR_FOES, vehID, "d", dist) 765 766 @deprecated() 767 def getNextStops(self, vehID): 768 """getNextStops(string) -> tuple(tuple(string, double, string, int, double, double)) 769 770 Return tuple of upcoming stops ((lane, endPos, stoppingPlaceID, stopFlags, duration, until), ...) 771 where integer stopFlag is defined as: 772 1 * stopped + 773 2 * parking + 774 4 * personTriggered + 775 8 * containerTriggered + 776 16 * isBusStop + 777 32 * isContainerStop + 778 64 * chargingStation + 779 128 * parkingarea 780 with each of these flags defined as 0 or 1. 781 """ 782 return self._getUniversal(tc.VAR_NEXT_STOPS, vehID) 783 784 def getNextLinks(self, vehID): 785 """getNextLinks(string) -> tuple(tuple(string, string, bool, bool, bool, string, string, double)) 786 787 Return tuple of upcoming links along the route ((lane, via, priority, opened, foe, 788 state, direction, length), ...) 789 """ 790 return self._getUniversal(tc.VAR_NEXT_LINKS, vehID) 791 792 def getStops(self, vehID, limit=0): 793 """getStops(string, int) -> tuple(StopData) 794 795 Return a tuple of StopData object. The flags are the same as for setStop and 796 replaceStop (and different from getNextStops(!) for backward compatibility): 797 1 * parking + 798 2 * personTriggered + 799 4 * containerTriggered + 800 8 * isBusStop + 801 16 * isContainerStop + 802 32 * chargingStation + 803 64 * parkingarea 804 with each of these flags defined as 0 or 1. 805 806 The optional argument limit can be used to limit the returned stops to 807 the next INT number (i.e. limit=1 if only the next stop is required). 808 Setting a negative limit returns up to 'limit' previous stops (or fewer 809 if the vehicle stopped fewer times previously) 810 """ 811 return self._getUniversal(tc.VAR_NEXT_STOPS2, vehID, "i", limit) 812 813 def subscribeLeader(self, vehID, dist=0., begin=0, end=2**31 - 1): 814 """subscribeLeader(string, double, double, double) -> None 815 816 Subscribe for the leading vehicle id together with the distance. 817 The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap. 818 """ 819 self.subscribe(vehID, (tc.VAR_LEADER,), begin, end, {tc.VAR_LEADER: ("d", dist)}) 820 821 def getDrivingDistance(self, vehID, edgeID, pos, laneIndex=0): 822 """getDrivingDistance(string, string, double, integer) -> double 823 824 For an edge along the remaining route of vehID, return the distance from the current vehicle position 825 to the given edge and position along the vehicles route. 826 Otherwise, return INVALID_DOUBLE_VALUE 827 """ 828 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tru", 2, 829 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST) 830 831 def getDrivingDistance2D(self, vehID, x, y): 832 """getDrivingDistance2D(string, double, double) -> integer 833 834 Return the distance to the given network position along the vehicles route. 835 """ 836 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST) 837 838 def getDistance(self, vehID): 839 """getDistance(string) -> double 840 841 Returns the distance to the starting point like an odometer. 842 """ 843 return self._getUniversal(tc.VAR_DISTANCE, vehID) 844 845 def getReferenceDistance(self, vehID): 846 """getReferenceDistance(string) -> double 847 Returns the distance along the linear reference system 848 in which the current edge takes part (i.e. kilometrage/mile markers) 849 """ 850 return self._getUniversal(tc.VAR_REFERENCE_DISTANCE, vehID) 851 852 def getStopParameter(self, vehID, nextStopIndex, param, customParam=False): 853 """getStopParameter(string, int, string) -> string 854 Gets the value of the given parameter for the stop at the given index 855 Negative indices permit access to past stops. 856 Supported params correspond to all legal stop xml-attributes 857 If customParam is set to True, the user defined stop parameter with the 858 specified param name will be returned instead (or "" if undefined) 859 """ 860 return self._getUniversal(tc.VAR_STOP_PARAMETER, vehID, "tisb", 3, nextStopIndex, param, customParam) 861 862 def getStopState(self, vehID): 863 """getStopState(string) -> integer 864 865 Returns information in regard to stopping: 866 The returned integer is defined as 1 * stopped + 2 * parking 867 + 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop 868 + 32 * isContainerStop 869 with each of these flags defined as 0 or 1 870 """ 871 return self._getUniversal(tc.VAR_STOPSTATE, vehID) 872 873 def isStopped(self, vehID): 874 """isStopped(string) -> bool 875 Return whether the vehicle is stopped 876 """ 877 return (self.getStopState(vehID) & 1) == 1 878 879 def isStoppedParking(self, vehID): 880 """isStoppedParking(string) -> bool 881 Return whether the vehicle is parking (implies stopped) 882 """ 883 return (self.getStopState(vehID) & 2) == 2 884 885 def isStoppedTriggered(self, vehID): 886 """isStoppedTriggered(string) -> bool 887 Return whether the vehicle is stopped and waiting for a person or container 888 """ 889 return (self.getStopState(vehID) & 12) > 0 890 891 def isAtBusStop(self, vehID): 892 """isAtBusStop(string) -> bool 893 Return whether the vehicle is stopped at a bus stop 894 """ 895 return (self.getStopState(vehID) & 16) == 16 896 897 def isAtContainerStop(self, vehID): 898 """isAtContainerStop(string) -> bool 899 Return whether the vehicle is stopped at a container stop 900 """ 901 return (self.getStopState(vehID) & 32) == 32 902 903 def getLaneChangeState(self, vehID, direction): 904 """getLaneChangeState(string, int) -> (int, int) 905 Return the lane change state for the vehicle. The first value returns 906 the state as computed by the lane change model and the second value 907 returns the state after incorporation TraCI requests. 908 See getLaneChangeStatePretty for an interpretation of the integer/bitset 909 results 910 """ 911 return self._getUniversal(tc.CMD_CHANGELANE, vehID, "i", direction) 912 913 def getLaneChangeStatePretty(self, vehID, direction): 914 """getLaneChangeStatePretty(string, int) -> ([string, ...], [string, ...]) 915 Return the lane change state for the vehicle as two lists of string 916 constants. The first tuple returns the state as computed by the lane change 917 model and the second tuple returns the state after incorporation TraCI requests. 918 """ 919 constants = { 920 0: 'stay', 921 1: 'left', 922 2: 'right', 923 3: 'strategic', 924 4: 'cooperative', 925 5: 'speedGain', 926 6: 'keepRight', 927 7: 'TraCI', 928 8: 'urgent', 929 9: 'blocked by left leader', 930 10: 'blocked by left follower', 931 11: 'blocked by right leader', 932 12: 'blocked by right follower', 933 13: 'overlapping', 934 14: 'insufficient space', 935 15: 'sublane', 936 } 937 938 def prettifyBitstring(intval): 939 return tuple([v for k, v in constants.items() if (intval & 2**k)]) 940 941 state, stateTraCI = self.getLaneChangeState(vehID, direction) 942 return prettifyBitstring(state), prettifyBitstring(stateTraCI) 943 944 def couldChangeLane(self, vehID, direction, state=None): 945 """couldChangeLane(string, int) -> bool 946 Return whether the vehicle could change lanes in the specified direction. 947 This reflects the state after the last try to change lanes. 948 If you want to execute changeLane as a result of the evaluation of this function 949 it is not guaranteed to work because vehicle movements occur first. 950 """ 951 if state is None: 952 state, stateTraCI = self.getLaneChangeState(vehID, direction) 953 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 954 # vehicle changed in the last step. state is no longer applicable 955 return False 956 return state != tc.LCA_UNKNOWN and (state & tc.LCA_BLOCKED == 0) 957 958 def wantsAndCouldChangeLane(self, vehID, direction, state=None): 959 """wantsAndCouldChangeLane(string, int) -> bool 960 Return whether the vehicle wants to and could change lanes in the specified direction 961 This reflects the state after the last try to change lanes. 962 If you want to execute changeLane as a result of the evaluation of this function 963 it is not guaranteed to work because vehicle movements occur first. 964 """ 965 if state is None: 966 state, stateTraCI = self.getLaneChangeState(vehID, direction) 967 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 968 # vehicle changed in the last step. state is no longer applicable 969 return False 970 if state & tc.LCA_BLOCKED == 0: 971 if direction == -1: 972 return state & tc.LCA_RIGHT != 0 973 if direction == 1: 974 return state & tc.LCA_LEFT != 0 975 return False 976 977 def getRoutingMode(self, vehID): 978 """getRoutingMode(string) 979 returns the current routing mode: 980 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 981 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 982 """ 983 return self._getUniversal(tc.VAR_ROUTING_MODE, vehID) 984 985 @alias_param("taxiState", "flag") 986 def getTaxiFleet(self, taxiState=0): 987 """getTaxiFleet(int) -> tuple(string) 988 Return the tuple of all taxis with the given taxiState: 989 0 : empty 990 1 : pickup 991 2 : occupied 992 """ 993 return self._getUniversal(tc.VAR_TAXI_FLEET, "", "i", taxiState) 994 995 def getLoadedIDList(self): 996 """getLoadedIDList() -> tuple(string) 997 returns all loaded vehicles that have not yet left the simulation 998 """ 999 return self._getUniversal(tc.VAR_LOADED_LIST, "") 1000 1001 def getTeleportingIDList(self): 1002 """getTeleportingIDList() -> tuple(string) 1003 returns all teleporting or jumping vehicles 1004 """ 1005 return self._getUniversal(tc.VAR_TELEPORTING_LIST, "") 1006 1007 def rerouteParkingArea(self, vehID, parkingAreaID): 1008 """rerouteParkingArea(string, string) 1009 1010 Changes the next parking area in parkingAreaID, updates the vehicle route, 1011 and preserve consistency in case of passengers/containers on board. 1012 """ 1013 self._setCmd(tc.CMD_REROUTE_TO_PARKING, vehID, "ts", 1, parkingAreaID) 1014 1015 def setStop(self, vehID, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1016 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, until=tc.INVALID_DOUBLE_VALUE): 1017 """setStop(string, string, double, integer, double, integer, double, double) -> None 1018 1019 Adds or modifies a stop with the given parameters. The duration and the until attribute are 1020 in seconds. 1021 """ 1022 if type(duration) is int and duration >= 1000 and duration % 1000 == 0: 1023 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1024 self._setCmd(tc.CMD_STOP, vehID, "tsdbdbdd", 7, edgeID, pos, laneIndex, duration, flags, startPos, until) 1025 1026 def setBusStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1027 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1028 """setBusStop(string, string, double, double, integer) -> None 1029 1030 Adds or modifies a bus stop with the given parameters. The duration and the until attribute are 1031 in seconds. 1032 """ 1033 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_BUS_STOP) 1034 1035 def setContainerStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1036 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1037 """setContainerStop(string, string, double, double, integer) -> None 1038 1039 Adds or modifies a container stop with the given parameters. The duration and the until attribute are 1040 in seconds. 1041 """ 1042 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CONTAINER_STOP) 1043 1044 def setChargingStationStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1045 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1046 """setChargingStationStop(string, string, double, double, integer) -> None 1047 1048 Adds or modifies a stop at a chargingStation with the given parameters. The duration and the until attribute are 1049 in seconds. 1050 """ 1051 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CHARGING_STATION) 1052 1053 def setParkingAreaStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1054 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_PARKING): 1055 """setParkingAreaStop(string, string, double, double, integer) -> None 1056 1057 Adds or modifies a stop at a parkingArea with the given parameters. The duration and the until attribute are 1058 in seconds. 1059 """ 1060 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_PARKING_AREA) 1061 1062 def replaceStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1063 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1064 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1065 """replaceStop(string, int, string, double, integer, double, integer, double, double) -> None 1066 1067 Replaces stop at the given index (within the list of all stops) with a new stop. 1068 Automatically modifies the route if the replacement stop is at another location. 1069 For edgeID a stopping place id may be given if the flag marks this 1070 stop as stopping on busStop, parkingArea, containerStop etc. 1071 If edgeID is "", the stop at the given index will be removed without 1072 replacement and the route will not be modified (unless setting 1073 teleport=2 which will trigger rerouting between the prior and next stop) 1074 If teleport is set to 1, the route to the replacement stop will be 1075 disconnected (forcing a teleport). 1076 If stopIndex is 0 the gap will be between the current 1077 edge and the new stop. Otherwise the gap will be between the stop edge for 1078 nextStopIndex - 1 and the new stop. 1079 """ 1080 self._setCmd(tc.CMD_REPLACE_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1081 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport) 1082 1083 def insertStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1084 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1085 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1086 """insertStop(string, int, string, double, integer, double, integer, double, double) -> None 1087 1088 Insert stop at the given index (within the list of all existing stops). 1089 Automatically modifies the route if the new stop is not along the route between the preceeding 1090 and succeeding stops (or start / end). 1091 For edgeID a stopping place id may be given if the flag marks this 1092 stop as stopping on busStop, parkingArea, containerStop etc. 1093 If teleport is set to 1, the route to the new stop will be 1094 disconnected (forcing a teleport). 1095 If stopIndex is 0 the gap will be between the current 1096 edge and the new stop. Otherwise the gap will be between the stop edge for 1097 nextStopIndex - 1 and the new stop. 1098 """ 1099 self._setCmd(tc.CMD_INSERT_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1100 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport) 1101 1102 def setStopParameter(self, vehID, nextStopIndex, param, value, customParam=False): 1103 """setStopParameter(string, int, string, string) -> None 1104 Sets the value of the given parameter for the (upcoming) stop at the 1105 given index (within the list of all stops). 1106 Supported params correspond to (almost) all legal stop xml-attributes 1107 and their value semantics 1108 If customParam is set to True, the user defined stop parameter with the 1109 specified param name will be set instead 1110 """ 1111 self._setCmd(tc.VAR_STOP_PARAMETER, vehID, "tissb", 4, nextStopIndex, param, value, customParam) 1112 1113 def resume(self, vehID): 1114 """resume(string) -> None 1115 1116 Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped). 1117 """ 1118 self._setCmd(tc.CMD_RESUME, vehID, "t", 0) 1119 1120 def changeLane(self, vehID, laneIndex, duration): 1121 """changeLane(string, int, double) -> None 1122 Forces a lane change to the lane with the given index; The lane change 1123 will be attempted for the given duration (in s) and if it succeeds, 1124 the vehicle will stay on that lane for the remaining duration. 1125 """ 1126 if type(duration) is int and duration >= 1000: 1127 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1128 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbd", 2, laneIndex, duration) 1129 1130 def changeLaneRelative(self, vehID, indexOffset, duration): 1131 """changeLaneRelative(string, int, double) -> None 1132 1133 Forces a relative lane change; if successful, 1134 the lane will be chosen for the given amount of time (in s). 1135 The indexOffset specifies the target lane relative to the vehicles current lane 1136 """ 1137 if type(duration) is int and duration >= 1000: 1138 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1139 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbdb", 3, indexOffset, duration, 1) 1140 1141 def changeSublane(self, vehID, latDist): 1142 """changeSublane(string, double) -> None 1143 Forces a lateral change by the given amount (negative values indicate changing to the right, positive 1144 to the left). This will override any other lane change motivations but conform to 1145 safety-constraints as configured by laneChangeMode. 1146 """ 1147 self._setCmd(tc.CMD_CHANGESUBLANE, vehID, "d", latDist) 1148 1149 def slowDown(self, vehID, speed, duration): 1150 """slowDown(string, double, double) -> None 1151 1152 Changes the speed smoothly to the given value over the given amount 1153 of time in seconds (can also be used to increase speed). 1154 """ 1155 if type(duration) is int and duration >= 1000: 1156 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1157 self._setCmd(tc.CMD_SLOWDOWN, vehID, "tdd", 2, speed, duration) 1158 1159 def openGap(self, vehID, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel=-1, referenceVehID=None): 1160 """openGap(string, double, double, double, double, double, string) -> None 1161 1162 Changes the vehicle's desired time headway (cf-parameter tau) smoothly to the given new value 1163 using the given change rate. Similarly, the given space headway is applied gradually 1164 to achieve a minimal spatial gap. 1165 The vehicle is commanded to keep the increased headway for 1166 the given duration once its target value is attained. The maximal value for the 1167 deceleration can be given to prevent harsh braking due to the change of tau. If maxDecel=-1, 1168 the limit determined by the CF model is used. 1169 A vehicle ID for a reference vehicle can optionally be given, otherwise, the gap is created with 1170 respect to the current leader on the ego vehicle's current lane. 1171 Note that this does only affect the following behavior regarding the current leader and does 1172 not influence the gap acceptance during lane change, etc. 1173 """ 1174 if type(duration) is int and duration >= 1000: 1175 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1176 if referenceVehID is None: 1177 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddd", 5, 1178 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel) 1179 else: 1180 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddds", 6, 1181 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, referenceVehID) 1182 1183 def deactivateGapControl(self, vehID): 1184 """deactivateGapControl(string) -> None 1185 1186 Deactivate the vehicle's gap control 1187 """ 1188 self.openGap(vehID, -1, -1, -1, -1) 1189 1190 def requestToC(self, vehID, leadTime): 1191 """ requestToC(string, double) -> None 1192 1193 Interface for triggering a transition of control for a vehicle equipped with a ToC device. 1194 """ 1195 self.setParameter(vehID, "device.toc.requestToC", str(leadTime)) 1196 1197 def changeTarget(self, vehID, edgeID): 1198 """changeTarget(string, string) -> None 1199 1200 The vehicle's destination edge is set to the given edge id. The route is rebuilt. 1201 """ 1202 self._setCmd(tc.CMD_CHANGETARGET, vehID, "s", edgeID) 1203 1204 def setType(self, vehID, typeID): 1205 """setType(string, string) -> None 1206 1207 Sets the id of the type for the named vehicle. 1208 """ 1209 self._setCmd(tc.VAR_TYPE, vehID, "s", typeID) 1210 1211 def setRouteID(self, vehID, routeID): 1212 """setRouteID(string, string) -> None 1213 1214 Changes the vehicles route to the route with the given id. 1215 """ 1216 self._setCmd(tc.VAR_ROUTE_ID, vehID, "s", routeID) 1217 1218 def setRoute(self, vehID, edgeList): 1219 """ 1220 setRoute(string, list) -> None 1221 1222 changes the vehicle route to given edges list. 1223 The first edge in the list has to be the one that the vehicle is at the moment. 1224 1225 example usage: 1226 setRoute('1', ['1', '2', '4', '6', '7']) 1227 1228 this changes route for vehicle id 1 to edges 1-2-4-6-7 1229 """ 1230 if isinstance(edgeList, str): 1231 edgeList = [edgeList] 1232 self._setCmd(tc.VAR_ROUTE, vehID, "l", edgeList) 1233 1234 def setLateralLanePosition(self, vehID, posLat): 1235 """setLateralLanePosition(string, double) -> None 1236 1237 Sets the lateral vehicle position relative to the center line of the 1238 lane in m (negative values are to the right in right-hand networks). 1239 The vehicle may adapt this position in the same step unless this is 1240 disabled via setLaneChangeMode. 1241 """ 1242 self._setCmd(tc.VAR_LANEPOSITION_LAT, vehID, "d", posLat) 1243 1244 def updateBestLanes(self, vehID): 1245 """ updateBestLanes(string) -> None 1246 Triggers an update of the vehicle's bestLanes (structure determining the lane preferences used by LC models) 1247 It may be called after modifying the vClass for instance. 1248 """ 1249 self._setCmd(tc.VAR_UPDATE_BESTLANES, vehID) 1250 1251 def setAdaptedTraveltime(self, vehID, edgeID, time=None, begTime=None, endTime=None): 1252 """setAdaptedTraveltime(string, string, double, double, double) -> None 1253 Inserts the information about the travel time of edge "edgeID" valid 1254 from begin time to end time into the vehicle's internal edge weights 1255 container. 1256 If the time is not specified, any previously set values for that edge 1257 are removed. 1258 If begTime or endTime are not specified the value is set for the whole 1259 simulation duration. 1260 """ 1261 if not isinstance(edgeID, str) and isinstance(begTime, str): 1262 # legacy handling 1263 warnings.warn( 1264 "Parameter order has changed for setAdaptedTraveltime(). Attempting legacy ordering. " + 1265 "Please update your code.", stacklevel=2) 1266 return self.setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time) 1267 if time is None: 1268 # reset 1269 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "ts", 1, edgeID) 1270 elif begTime is None: 1271 # set value for the whole simulation 1272 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tsd", 2, edgeID, time) 1273 else: 1274 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tddsd", 4, begTime, endTime, edgeID, time) 1275 1276 def setEffort(self, vehID, edgeID, effort=None, begTime=None, endTime=None): 1277 """setEffort(string, string, double, double, double) -> None 1278 Inserts the information about the effort of edge "edgeID" valid from 1279 begin time to end time into the vehicle's internal edge weights 1280 container. 1281 If the time is not specified, any previously set values for that edge 1282 are removed. 1283 If begTime or endTime are not specified the value is set for the whole 1284 simulation duration. 1285 """ 1286 if not isinstance(edgeID, str) and isinstance(begTime, str): 1287 # legacy handling 1288 warnings.warn( 1289 "Parameter order has changed for setEffort(). Attempting legacy ordering. Please update your code.", 1290 stacklevel=2) 1291 return self.setEffort(vehID, begTime, endTime, edgeID, effort) 1292 if effort is None: 1293 # reset 1294 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "ts", 1, edgeID) 1295 elif begTime is None: 1296 # set value for the whole simulation 1297 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tsd", 2, edgeID, effort) 1298 else: 1299 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tddsd", 4, begTime, endTime, edgeID, effort) 1300 1301 LAST_TRAVEL_TIME_UPDATE = -1 1302 1303 def setRoutingMode(self, vehID, routingMode): 1304 """setRoutingMode(string, int) -> None 1305 Sets the current routing mode: 1306 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 1307 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 1308 tc.ROUTING_MODE_AGGREGATED_CUSTOM : use weight storages and fall-back to smoothed travel times 1309 """ 1310 self._setCmd(tc.VAR_ROUTING_MODE, vehID, "i", routingMode) 1311 1312 def rerouteTraveltime(self, vehID, currentTravelTimes=True): 1313 """rerouteTraveltime(string, bool) -> None 1314 Reroutes a vehicle. 1315 If currentTravelTimes is True (default) and the routing mode is still ROUTING_MODE_DEFAULT 1316 then the ROUTING_MODE_AGGREGATED_CUSTOM gets activated temporarily 1317 and used for rerouting. The various functions and options for 1318 customizing travel times are described at https://sumo.dlr.de/wiki/Simulation/Routing 1319 1320 When rerouteTraveltime has been called once with an aggregated routing mode, 1321 edge weight storage and update gets activated which might slow down the simulation. 1322 """ 1323 if currentTravelTimes: 1324 routingMode = self.getRoutingMode(vehID) 1325 if routingMode == tc.ROUTING_MODE_DEFAULT: 1326 self.setRoutingMode(vehID, tc.ROUTING_MODE_AGGREGATED_CUSTOM) 1327 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, vehID, "t", 0) 1328 if currentTravelTimes and routingMode == tc.ROUTING_MODE_DEFAULT: 1329 self.setRoutingMode(vehID, routingMode) 1330 1331 def rerouteEffort(self, vehID): 1332 """rerouteEffort(string) -> None 1333 Reroutes a vehicle according to the effort values. 1334 """ 1335 self._setCmd(tc.CMD_REROUTE_EFFORT, vehID, "t", 0) 1336 1337 def setSignals(self, vehID, signals): 1338 """setSignals(string, integer) -> None 1339 1340 Sets an integer encoding the state of the vehicle's signals. 1341 """ 1342 self._setCmd(tc.VAR_SIGNALS, vehID, "i", signals) 1343 1344 def moveTo(self, vehID, laneID, pos, reason=tc.MOVE_AUTOMATIC): 1345 """moveTo(string, string, double, integer) -> None 1346 1347 Move a vehicle to a new position along its current route. 1348 """ 1349 self._setCmd(tc.VAR_MOVE_TO, vehID, "tsdi", 3, laneID, pos, reason) 1350 1351 def setSpeed(self, vehID, speed): 1352 """setSpeed(string, double) -> None 1353 1354 Sets the speed in m/s for the named vehicle within the last step. 1355 Calling with speed=-1 hands the vehicle control back to SUMO. 1356 """ 1357 self._setCmd(tc.VAR_SPEED, vehID, "d", speed) 1358 1359 def setAcceleration(self, vehID, acceleration, duration): 1360 """setAcceleration(string, double, double) -> None 1361 1362 Sets the acceleration in m/s^2 for the named vehicle and the given duration. 1363 """ 1364 self._setCmd(tc.VAR_ACCELERATION, vehID, "tdd", 2, acceleration, duration) 1365 1366 def setPreviousSpeed(self, vehID, speed, acceleration=tc.INVALID_DOUBLE_VALUE): 1367 """setPreviousSpeed(string, double, double) -> None 1368 1369 Sets the previous speed in m/s for the named vehicle wich will be used for 1370 calculations in the current step. Optionally, the acceleration for the 1371 previous step (in m/s^2) can be set as well. 1372 """ 1373 self._setCmd(tc.VAR_PREV_SPEED, vehID, "tdd", 2, speed, acceleration) 1374 1375 def setLine(self, vehID, line): 1376 """setLine(string, string) -> None 1377 1378 Sets the line information for this vehicle. 1379 """ 1380 self._setCmd(tc.VAR_LINE, vehID, "s", line) 1381 1382 def setVia(self, vehID, edgeList): 1383 """ 1384 setVia(string, list) -> None 1385 1386 changes the via edges to the given edges list (to be used during 1387 subsequent rerouting calls). 1388 1389 Note: a single edgeId as argument is allowed as shorthand for a list of length 1 1390 """ 1391 if isinstance(edgeList, str): 1392 edgeList = [edgeList] 1393 self._setCmd(tc.VAR_VIA, vehID, "l", edgeList) 1394 1395 def highlight(self, vehID, color=(255, 0, 0, 255), size=-1, alphaMax=-1, duration=-1, type=0): 1396 """ highlight(string, color, float, ubyte, float, ubyte) -> None 1397 Adds a circle of the given color tracking the vehicle. 1398 If a positive size [in m] is given the size of the highlight is chosen accordingly, 1399 otherwise the length of the vehicle is used as reference. 1400 If alphaMax and duration are positive, the circle fades in and out within the given duration, 1401 otherwise it permanently follows the vehicle. 1402 """ 1403 if type > 255: 1404 raise TraCIException("vehicle.highlight(): maximal value for type is 255") 1405 if alphaMax > 255: 1406 raise TraCIException("vehicle.highlight(): maximal value for alphaMax is 255") 1407 if alphaMax <= 0 and duration > 0: 1408 raise TraCIException("vehicle.highlight(): duration>0 requires alphaMax>0") 1409 if alphaMax > 0 and duration <= 0: 1410 raise TraCIException("vehicle.highlight(): alphaMax>0 requires duration>0") 1411 1412 if alphaMax > 0: 1413 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcdBdB", 5, color, size, alphaMax, duration, type) 1414 else: 1415 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcd", 2, color, size) 1416 1417 @alias_param("laneChangeMode", "lcm") 1418 def setLaneChangeMode(self, vehID, laneChangeMode): 1419 """setLaneChangeMode(string, integer) -> None 1420 1421 Sets the vehicle's lane change mode as a bitset. 1422 """ 1423 self._setCmd(tc.VAR_LANECHANGE_MODE, vehID, "i", laneChangeMode) 1424 1425 @alias_param("speedMode", "sm") 1426 def setSpeedMode(self, vehID, speedMode): 1427 """setSpeedMode(string, integer) -> None 1428 1429 Sets the vehicle's speed mode as a bitset. 1430 """ 1431 self._setCmd(tc.VAR_SPEEDSETMODE, vehID, "i", speedMode) 1432 1433 def addLegacy(self, vehID, routeID, depart=tc.DEPARTFLAG_NOW, pos=0, speed=0, 1434 lane=tc.DEPARTFLAG_LANE_FIRST_ALLOWED, typeID="DEFAULT_VEHTYPE"): 1435 """ 1436 Add a new vehicle (old style) 1437 """ 1438 if depart == tc.DEPARTFLAG_NOW: 1439 depart = "now" 1440 elif depart == tc.DEPARTFLAG_TRIGGERED: 1441 depart = "triggered" 1442 else: 1443 depart = str(depart) 1444 if pos < 0: 1445 print("Invalid departure position.") 1446 return 1447 if lane == tc.DEPARTFLAG_LANE_FIRST_ALLOWED: 1448 lane = "first" 1449 elif lane == tc.DEPARTFLAG_LANE_FREE: 1450 lane = "free" 1451 else: 1452 lane = str(lane) 1453 self.addFull(vehID, routeID, typeID, depart, lane, str(pos), str(speed)) 1454 1455 def add(self, vehID, routeID, typeID="DEFAULT_VEHTYPE", depart="now", 1456 departLane="first", departPos="base", departSpeed="0", 1457 arrivalLane="current", arrivalPos="max", arrivalSpeed="current", 1458 fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0): 1459 """ 1460 Add a new vehicle (new style with all possible parameters) 1461 If routeID is "", the vehicle will be inserted on a random network edge 1462 if route consists of two disconnected edges, the vehicle will be treated 1463 like a <trip> and use the fastest route between the two edges. 1464 """ 1465 if depart is None: 1466 # legacy compatibility 1467 depart = str(self._connection.simulation.getTime()) 1468 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii", 14, 1469 routeID, typeID, depart, departLane, departPos, departSpeed, 1470 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, personCapacity, personNumber) 1471 1472 addFull = add 1473 1474 def dispatchTaxi(self, vehID, reservations): 1475 """dispatchTaxi(string, list(string)) -> None 1476 dispatches the taxi with the given id to service the given reservations. 1477 If only a single reservation is given, this implies pickup and drop-off 1478 If multiple reservations are given, each reservation id must occur twice 1479 (once for pickup and once for drop-off) and the list encodes ride 1480 sharing of passengers (in pickup and drop-off order) 1481 """ 1482 if isinstance(reservations, str): 1483 reservations = [reservations] 1484 self._setCmd(tc.CMD_TAXI_DISPATCH, vehID, "l", reservations) 1485 1486 def remove(self, vehID, reason=tc.REMOVE_VAPORIZED): 1487 '''Remove vehicle with the given ID for the give reason. 1488 Reasons are defined in module constants and start with REMOVE_''' 1489 self._setCmd(tc.REMOVE, vehID, "b", reason) 1490 1491 @alias_param("laneIndex", "lane") 1492 def moveToXY(self, vehID, edgeID, laneIndex, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 1493 '''Place vehicle at the given x,y coordinates and force its angle to 1494 the given value (for drawing). 1495 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 1496 natural angle of the edge on which it is driving. 1497 If keepRoute is set to 1, the closest position 1498 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 1499 any edge in the network but its route then only consists of that edge. 1500 If keepRoute is set to 2 the vehicle has all the freedom of keepRoute=0 1501 but in addition to that may even move outside the road network. 1502 edgeID and lane are optional placement hints to resolve ambiguities. 1503 The command fails if no suitable target position is found within the 1504 distance given by matchThreshold. 1505 ''' 1506 self._setCmd(tc.MOVE_TO_XY, vehID, "tsidddbd", 7, edgeID, laneIndex, x, y, angle, keepRoute, matchThreshold) 1507 1508 def addSubscriptionFilterLanes(self, lanes, noOpposite=False, downstreamDist=None, upstreamDist=None): 1509 """addSubscriptionFilterLanes(list(integer), bool, double, double) -> None 1510 1511 Adds a lane-filter to the last modified vehicle context subscription (call it just after subscribing). 1512 lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.) 1513 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1514 downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net. 1515 """ 1516 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1517 if noOpposite: 1518 self.addSubscriptionFilterNoOpposite() 1519 if downstreamDist is not None: 1520 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1521 if upstreamDist is not None: 1522 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1523 1524 def addSubscriptionFilterNoOpposite(self): 1525 """addSubscriptionFilterNoOpposite() -> None 1526 1527 Omits vehicles on other edges than the ego's for the last modified vehicle context subscription 1528 (call it just after subscribing). 1529 """ 1530 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_NOOPPOSITE) 1531 1532 def addSubscriptionFilterDownstreamDistance(self, dist): 1533 """addSubscriptionFilterDownstreamDist(float) -> None 1534 1535 Sets the downstream distance along the network for vehicles to be returned by the last modified 1536 vehicle context subscription (call it just after subscribing). 1537 """ 1538 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_DOWNSTREAM_DIST, dist) 1539 1540 def addSubscriptionFilterUpstreamDistance(self, dist): 1541 """addSubscriptionFilterUpstreamDist(float) -> None 1542 1543 Sets the upstream distance along the network for vehicles to be returned by the last modified 1544 vehicle context subscription (call it just after subscribing). 1545 """ 1546 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_UPSTREAM_DIST, dist) 1547 1548 def addSubscriptionFilterCFManeuver(self, downstreamDist=None, upstreamDist=None): 1549 """addSubscriptionFilterCFManeuver() -> None 1550 1551 Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego. 1552 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1553 """ 1554 self.addSubscriptionFilterLeadFollow([0]) 1555 if downstreamDist is not None: 1556 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1557 if upstreamDist is not None: 1558 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1559 1560 def addSubscriptionFilterLCManeuver(self, direction=None, noOpposite=False, downstreamDist=None, upstreamDist=None): 1561 """addSubscriptionFilterLCManeuver(int) -> None 1562 1563 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1564 and follower of the ego. 1565 direction - lane change direction (in {-1=right, 1=left}) 1566 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1567 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1568 Combine with: distance filters; vClass/vType filter. 1569 """ 1570 if direction is None: 1571 # Using default: both directions 1572 lanes = [-1, 0, 1] 1573 elif not (direction == -1 or direction == 1): 1574 warnings.warn("Ignoring lane change subscription filter " + 1575 "with non-neighboring lane offset direction=%s." % direction) 1576 return 1577 else: 1578 lanes = [0, direction] 1579 self.addSubscriptionFilterLeadFollow(lanes) 1580 if noOpposite: 1581 self.addSubscriptionFilterNoOpposite() 1582 if downstreamDist is not None: 1583 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1584 if upstreamDist is not None: 1585 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1586 1587 def addSubscriptionFilterLeadFollow(self, lanes): 1588 """addSubscriptionFilterLCManeuver(lanes) -> None 1589 1590 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1591 and follower of the ego. 1592 Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter. 1593 """ 1594 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LEAD_FOLLOW) 1595 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1596 1597 def addSubscriptionFilterTurn(self, downstreamDist=None, foeDistToJunction=None): 1598 """addSubscriptionFilterTurn(double, double) -> None 1599 1600 Restricts vehicles returned by the last modified vehicle context subscription to foes on upcoming junctions 1601 """ 1602 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_TURN, foeDistToJunction) 1603 if downstreamDist is not None: 1604 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1605 1606 def addSubscriptionFilterVClass(self, vClasses): 1607 """addSubscriptionFilterVClass(list(String)) -> None 1608 1609 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given classes 1610 """ 1611 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VCLASS, vClasses) 1612 1613 def addSubscriptionFilterVType(self, vTypes): 1614 """addSubscriptionFilterVType(list(String)) -> None 1615 1616 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given types 1617 """ 1618 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VTYPE, vTypes) 1619 1620 def addSubscriptionFilterFieldOfVision(self, openingAngle): 1621 """addSubscriptionFilterFieldOfVision(float) -> None 1622 1623 Restricts vehicles returned by the last modified vehicle context subscription 1624 to vehicles within field of vision with given opening angle 1625 """ 1626 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_FIELD_OF_VISION, openingAngle) 1627 1628 def addSubscriptionFilterLateralDistance(self, lateralDist, downstreamDist=None, upstreamDist=None): 1629 """addSubscriptionFilterLateralDist(double, double, double) -> None 1630 1631 Adds a lateral distance filter to the last modified vehicle context subscription 1632 (call it just after subscribing). 1633 downstreamDist and upstreamDist specify the longitudinal range of the search 1634 for surrounding vehicles along the ego vehicle's route. 1635 """ 1636 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LATERAL_DIST, lateralDist) 1637 if downstreamDist is not None: 1638 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1639 if upstreamDist is not None: 1640 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
38class StopData(object): 39 40 def __init__(self, 41 lane="", 42 startPos=-1, 43 endPos=-1, 44 stoppingPlaceID="", 45 stopFlags=0, 46 duration=-1, 47 until=-1, 48 intendedArrival=-1, 49 arrival=-1, 50 depart=-1, 51 split="", 52 join="", 53 actType="", 54 tripId="", 55 line="", 56 speed=0): 57 self.lane = lane 58 self.startPos = startPos 59 self.endPos = endPos 60 self.stoppingPlaceID = stoppingPlaceID 61 self.stopFlags = stopFlags 62 self.duration = duration 63 self.until = until 64 self.intendedArrival = intendedArrival 65 self.arrival = arrival 66 self.depart = depart 67 self.split = split 68 self.join = join 69 self.actType = actType 70 self.tripId = tripId 71 self.line = line 72 self.speed = speed 73 74 def __attr_repr__(self, attrname, default=""): 75 if getattr(self, attrname) == default: 76 return "" 77 else: 78 val = getattr(self, attrname) 79 if val == tc.INVALID_DOUBLE_VALUE: 80 val = "INVALID" 81 return "%s=%s" % (attrname, val) 82 83 def __repr__(self): 84 return "StopData(%s)" % ', '.join([v for v in [ 85 self.__attr_repr__("lane"), 86 self.__attr_repr__("startPos"), 87 self.__attr_repr__("endPos"), 88 self.__attr_repr__("stoppingPlaceID"), 89 self.__attr_repr__("stopFlags"), 90 self.__attr_repr__("duration", tc.INVALID_DOUBLE_VALUE), 91 self.__attr_repr__("until", tc.INVALID_DOUBLE_VALUE), 92 self.__attr_repr__("intendedArrival", tc.INVALID_DOUBLE_VALUE), 93 self.__attr_repr__("arrival", tc.INVALID_DOUBLE_VALUE), 94 self.__attr_repr__("depart", tc.INVALID_DOUBLE_VALUE), 95 self.__attr_repr__("split"), 96 self.__attr_repr__("join"), 97 self.__attr_repr__("actType"), 98 self.__attr_repr__("tripId"), 99 self.__attr_repr__("line"), 100 self.__attr_repr__("speed", 0), 101 ] if v != ""])
40 def __init__(self, 41 lane="", 42 startPos=-1, 43 endPos=-1, 44 stoppingPlaceID="", 45 stopFlags=0, 46 duration=-1, 47 until=-1, 48 intendedArrival=-1, 49 arrival=-1, 50 depart=-1, 51 split="", 52 join="", 53 actType="", 54 tripId="", 55 line="", 56 speed=0): 57 self.lane = lane 58 self.startPos = startPos 59 self.endPos = endPos 60 self.stoppingPlaceID = stoppingPlaceID 61 self.stopFlags = stopFlags 62 self.duration = duration 63 self.until = until 64 self.intendedArrival = intendedArrival 65 self.arrival = arrival 66 self.depart = depart 67 self.split = split 68 self.join = join 69 self.actType = actType 70 self.tripId = tripId 71 self.line = line 72 self.speed = speed
251class VehicleDomain(VTypeDomain): 252 # imported for backwards compatibility 253 STOP_DEFAULT = tc.STOP_DEFAULT 254 STOP_PARKING = tc.STOP_PARKING 255 STOP_TRIGGERED = tc.STOP_TRIGGERED 256 STOP_CONTAINER_TRIGGERED = tc.STOP_CONTAINER_TRIGGERED 257 STOP_BUS_STOP = tc.STOP_BUS_STOP 258 STOP_CONTAINER_STOP = tc.STOP_CONTAINER_STOP 259 STOP_CHARGING_STATION = tc.STOP_CHARGING_STATION 260 STOP_PARKING_AREA = tc.STOP_PARKING_AREA 261 DEPART_TRIGGERED = tc.DEPARTFLAG_TRIGGERED 262 DEPART_CONTAINER_TRIGGERED = tc.DEPARTFLAG_CONTAINER_TRIGGERED 263 DEPART_NOW = tc.DEPARTFLAG_NOW 264 DEPART_SPEED_RANDOM = tc.DEPARTFLAG_SPEED_RANDOM 265 DEPART_SPEED_MAX = tc.DEPARTFLAG_SPEED_MAX 266 DEPART_LANE_RANDOM = tc.DEPARTFLAG_LANE_RANDOM 267 DEPART_LANE_FREE = tc.DEPARTFLAG_LANE_FREE 268 DEPART_LANE_ALLOWED_FREE = tc.DEPARTFLAG_LANE_ALLOWED_FREE 269 DEPART_LANE_BEST_FREE = tc.DEPARTFLAG_LANE_BEST_FREE 270 DEPART_LANE_FIRST_ALLOWED = tc.DEPARTFLAG_LANE_FIRST_ALLOWED 271 272 def __init__(self): 273 VTypeDomain.__init__(self, "vehicle", tc.CMD_GET_VEHICLE_VARIABLE, tc.CMD_SET_VEHICLE_VARIABLE, 274 tc.CMD_SUBSCRIBE_VEHICLE_VARIABLE, tc.RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE, 275 tc.CMD_SUBSCRIBE_VEHICLE_CONTEXT, tc.RESPONSE_SUBSCRIBE_VEHICLE_CONTEXT, 276 _RETURN_VALUE_FUNC, subscriptionDefault=(tc.VAR_ROAD_ID, tc.VAR_LANEPOSITION)) 277 278 def getSpeed(self, vehID): 279 """getSpeed(string) -> double 280 281 Returns the (longitudinal) speed in m/s of the named vehicle within the last step. 282 """ 283 return self._getUniversal(tc.VAR_SPEED, vehID) 284 285 def getLateralSpeed(self, vehID): 286 """getLateralSpeed(string) -> double 287 288 Returns the lateral speed in m/s of the named vehicle within the last step. 289 """ 290 return self._getUniversal(tc.VAR_SPEED_LAT, vehID) 291 292 def getAcceleration(self, vehID): 293 """getAcceleration(string) -> double 294 295 Returns the acceleration in m/s^2 of the named vehicle within the last step. 296 """ 297 return self._getUniversal(tc.VAR_ACCELERATION, vehID) 298 299 def getSpeedWithoutTraCI(self, vehID): 300 """getSpeedWithoutTraCI(string) -> double 301 Returns the speed that the vehicle would drive if no speed-influencing 302 command such as setSpeed or slowDown was given. 303 """ 304 return self._getUniversal(tc.VAR_SPEED_WITHOUT_TRACI, vehID) 305 306 def getPosition(self, vehID): 307 """getPosition(string) -> (double, double) 308 309 Returns the position of the named vehicle within the last step [m,m]. 310 """ 311 return self._getUniversal(tc.VAR_POSITION, vehID) 312 313 def getPosition3D(self, vehID): 314 """getPosition3D(string) -> (double, double, double) 315 316 Returns the position of the named vehicle within the last step [m,m,m]. 317 """ 318 return self._getUniversal(tc.VAR_POSITION3D, vehID) 319 320 def getAngle(self, vehID): 321 """getAngle(string) -> double 322 323 Returns the angle in degrees of the named vehicle within the last step. 324 """ 325 return self._getUniversal(tc.VAR_ANGLE, vehID) 326 327 def getRoadID(self, vehID): 328 """getRoadID(string) -> string 329 330 Returns the id of the edge the named vehicle was at within the last step. 331 """ 332 return self._getUniversal(tc.VAR_ROAD_ID, vehID) 333 334 def getDeparture(self, vehID): 335 """getDeparture(string) -> double 336 337 Returns the actual departure time in seconds 338 """ 339 return self._getUniversal(tc.VAR_DEPARTURE, vehID) 340 341 def getDepartDelay(self, vehID): 342 """getDepartDelay(string) -> double 343 344 Returns the delay between intended and actual departure in seconds 345 """ 346 return self._getUniversal(tc.VAR_DEPART_DELAY, vehID) 347 348 def getLaneID(self, vehID): 349 """getLaneID(string) -> string 350 351 Returns the id of the lane the named vehicle was at within the last step. 352 """ 353 return self._getUniversal(tc.VAR_LANE_ID, vehID) 354 355 def getShadowLaneID(self, vehID): 356 """getShadowLaneID(string) -> string 357 358 Returns the id of the shadow lane if the vehicle is currently changing lanes. 359 """ 360 return self._getUniversal(tc.VAR_SHADOW_LANE_ID, vehID) 361 362 def getLaneIndex(self, vehID): 363 """getLaneIndex(string) -> integer 364 365 Returns the index of the lane the named vehicle was at within the last step. 366 """ 367 return self._getUniversal(tc.VAR_LANE_INDEX, vehID) 368 369 def getSegmentID(self, vehID): 370 """getSegmentID(string) -> string 371 372 Returns the id of the segment the named vehicle was at within the last step (mesosim). 373 """ 374 return self._getUniversal(tc.VAR_SEGMENT_ID, vehID) 375 376 def getSegmentIndex(self, vehID): 377 """getSegmentIndex(string) -> integer 378 379 Returns the index of the segment the named vehicle was at within the last step (mesosim). 380 """ 381 return self._getUniversal(tc.VAR_SEGMENT_INDEX, vehID) 382 383 def getTypeID(self, vehID): 384 """getTypeID(string) -> string 385 386 Returns the id of the type of the named vehicle. 387 """ 388 return self._getUniversal(tc.VAR_TYPE, vehID) 389 390 def getRouteID(self, vehID): 391 """getRouteID(string) -> string 392 393 Returns the id of the route of the named vehicle. 394 """ 395 return self._getUniversal(tc.VAR_ROUTE_ID, vehID) 396 397 def getRouteIndex(self, vehID): 398 """getRouteIndex(string) -> int 399 400 Returns the index of the current edge within the vehicles route or -1 if the 401 vehicle has not yet departed 402 """ 403 return self._getUniversal(tc.VAR_ROUTE_INDEX, vehID) 404 405 def getRoute(self, vehID): 406 """getRoute(string) -> tuple(string) 407 408 Returns the ids of the edges the vehicle's route is made of. 409 """ 410 return self._getUniversal(tc.VAR_EDGES, vehID) 411 412 def getLanePosition(self, vehID): 413 """getLanePosition(string) -> double 414 415 The position of the vehicle along the lane measured in m. 416 """ 417 return self._getUniversal(tc.VAR_LANEPOSITION, vehID) 418 419 def getCO2Emission(self, vehID): 420 """getCO2Emission(string) -> double 421 422 Returns the CO2 emission in mg/s for the last time step. 423 Multiply by the step length to get the value for one step. 424 """ 425 return self._getUniversal(tc.VAR_CO2EMISSION, vehID) 426 427 def getCOEmission(self, vehID): 428 """getCOEmission(string) -> double 429 430 Returns the CO emission in mg/s for the last time step. 431 Multiply by the step length to get the value for one step. 432 """ 433 return self._getUniversal(tc.VAR_COEMISSION, vehID) 434 435 def getHCEmission(self, vehID): 436 """getHCEmission(string) -> double 437 438 Returns the HC emission in mg/s for the last time step. 439 Multiply by the step length to get the value for one step. 440 """ 441 return self._getUniversal(tc.VAR_HCEMISSION, vehID) 442 443 def getPMxEmission(self, vehID): 444 """getPMxEmission(string) -> double 445 446 Returns the particular matter emission in mg/s for the last time step. 447 Multiply by the step length to get the value for one step. 448 """ 449 return self._getUniversal(tc.VAR_PMXEMISSION, vehID) 450 451 def getNOxEmission(self, vehID): 452 """getNOxEmission(string) -> double 453 454 Returns the NOx emission in mg/s for the last time step. 455 Multiply by the step length to get the value for one step. 456 """ 457 return self._getUniversal(tc.VAR_NOXEMISSION, vehID) 458 459 def getFuelConsumption(self, vehID): 460 """getFuelConsumption(string) -> double 461 462 Returns the fuel consumption in mg/s for the last time step. 463 Multiply by the step length to get the value for one step. 464 """ 465 return self._getUniversal(tc.VAR_FUELCONSUMPTION, vehID) 466 467 def getNoiseEmission(self, vehID): 468 """getNoiseEmission(string) -> double 469 470 Returns the noise emission in db for the last time step. 471 """ 472 return self._getUniversal(tc.VAR_NOISEEMISSION, vehID) 473 474 def getElectricityConsumption(self, vehID): 475 """getElectricityConsumption(string) -> double 476 477 Returns the electricity consumption in Wh/s for the last time step. 478 Multiply by the step length to get the value for one step. 479 """ 480 return self._getUniversal(tc.VAR_ELECTRICITYCONSUMPTION, vehID) 481 482 def getPersonNumber(self, vehID): 483 """getPersonNumber(string) -> integer 484 Returns the total number of persons which includes those defined 485 using attribute 'personNumber' as well as <person>-objects who are riding in 486 this vehicle. 487 """ 488 return self._getUniversal(tc.VAR_PERSON_NUMBER, vehID) 489 490 def getPersonIDList(self, vehID): 491 """getPersonIDList(string) -> tuple(string) 492 Returns the tuple of persons who are riding in this vehicle. 493 """ 494 return self._getUniversal(tc.LAST_STEP_PERSON_ID_LIST, vehID) 495 496 def getAdaptedTraveltime(self, vehID, time, edgeID): 497 """getAdaptedTraveltime(string, double, string) -> double 498 499 Returns the information about the travel time of edge "edgeID" valid 500 for the given time from the vehicle's internal edge weights 501 container (see setAdaptedTraveltime). 502 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 503 """ 504 return self._getUniversal(tc.VAR_EDGE_TRAVELTIME, vehID, "tds", 2, time, edgeID) 505 506 def getEffort(self, vehID, time, edgeID): 507 """getEffort(string, double, string) -> double 508 509 Returns the information about the effort needed for edge "edgeID" valid 510 for the given time from the vehicle's internal effort 511 container (see setEffort). 512 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 513 """ 514 return self._getUniversal(tc.VAR_EDGE_EFFORT, vehID, "tds", 2, time, edgeID) 515 516 def isRouteValid(self, vehID): 517 """isRouteValid(string) -> bool 518 Returns whether the current vehicle route is connected for the vehicle 519 class of the given vehicle. 520 """ 521 return self._getUniversal(tc.VAR_ROUTE_VALID, vehID) 522 523 def getSignals(self, vehID): 524 """getSignals(string) -> integer 525 526 Returns an integer encoding the state of a vehicle's signals. 527 """ 528 return self._getUniversal(tc.VAR_SIGNALS, vehID) 529 530 def getLateralLanePosition(self, vehID): 531 """getLateralLanePosition(string) -> double 532 533 Returns the lateral position of the vehicle on its current lane measured in m. 534 """ 535 return self._getUniversal(tc.VAR_LANEPOSITION_LAT, vehID) 536 537 def getAllowedSpeed(self, vehID): 538 """getAllowedSpeed(string) -> double 539 540 Returns the maximum allowed speed on the current lane regarding speed factor in m/s for this vehicle. 541 """ 542 return self._getUniversal(tc.VAR_ALLOWED_SPEED, vehID) 543 544 def getWaitingTime(self, vehID): 545 """getWaitingTime(string) -> double 546 The waiting time of a vehicle is defined as the time (in seconds) spent with a 547 speed below 0.1m/s since the last time it was faster than 0.1m/s. 548 (basically, the waiting time of a vehicle is reset to 0 every time it moves). 549 A vehicle that is stopping intentionally with a <stop> does not accumulate waiting time. 550 """ 551 return self._getUniversal(tc.VAR_WAITING_TIME, vehID) 552 553 def getAccumulatedWaitingTime(self, vehID): 554 """getAccumulatedWaitingTime(string) -> double 555 The accumulated waiting time of a vehicle collects the vehicle's waiting time 556 over a certain time interval (interval length is set per option '--waiting-time-memory') 557 """ 558 return self._getUniversal(tc.VAR_ACCUMULATED_WAITING_TIME, vehID) 559 560 def getLaneChangeMode(self, vehID): 561 """getLaneChangeMode(string) -> integer 562 563 Gets the vehicle's lane change mode as a bitset. 564 """ 565 return self._getUniversal(tc.VAR_LANECHANGE_MODE, vehID) 566 567 def getSpeedMode(self, vehID): 568 """getSpeedMode(string) -> int 569 The speed mode of a vehicle 570 """ 571 return self._getUniversal(tc.VAR_SPEEDSETMODE, vehID) 572 573 def getSlope(self, vehID): 574 """getSlope(string) -> double 575 The slope at the current position of the vehicle in degrees 576 """ 577 return self._getUniversal(tc.VAR_SLOPE, vehID) 578 579 def getLine(self, vehID): 580 """getLine(string) -> string 581 582 Returns the line information of this vehicle. 583 """ 584 return self._getUniversal(tc.VAR_LINE, vehID) 585 586 def getVia(self, vehID): 587 """getVia(string) -> tuple(string) 588 589 Returns the ids of via edges for this vehicle 590 """ 591 return self._getUniversal(tc.VAR_VIA, vehID) 592 593 def getLastActionTime(self, vehID): 594 """getLastActionTime(string) -> double 595 596 Returns the time in s of last action point for this vehicle. 597 """ 598 return self._getUniversal(tc.VAR_LASTACTIONTIME, vehID) 599 600 def getBestLanes(self, vehID): 601 """getBestLanes(string) -> tuple(data) 602 where data is a tuple of (laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes)) 603 604 For each lane of the current edge a data tuple is returned where the 605 entries have the following meaning: 606 - laneID: the id of that lane on the current edge 607 - the length that can be driven without lane change (measured from the start of that lane) 608 - the occupation on the future lanes (brutto vehicle lengths) 609 - the offset of that lane from the lane that would be strategically 610 preferred (this is the lane that requires the least future lane 611 changes or a lane that needs to be used for stopping) 612 - whether that lane allows continuing the route (for at least one more edge) 613 - the sequence of lanes that would be driven starting at laneID if no 614 lane change were to take place 615 """ 616 return self._getUniversal(tc.VAR_BEST_LANES, vehID) 617 618 def getLeader(self, vehID, dist=100.): 619 """getLeader(string, double) -> (string, double) 620 621 Return the leading vehicle id together with the distance. The distance 622 is measured from the front + minGap to the back of the leader, so it does not include the 623 minGap of the vehicle. 624 The dist parameter defines the minimum lookahead, 0 calculates a lookahead from the brake gap. 625 Note that the returned leader may be further away than the given dist and that the vehicle 626 will only look on its current best lanes and not look beyond the end of its final route edge. 627 628 In the case where no leader is found, the function returns 'None'. 629 This special case is deprecated. The future behavior is to return the 630 pair ("", -1) when no leader is found. 631 The function 'traci.setLegacyGetLeader(bool) can be used to switch 632 between both behaviors. 633 """ 634 return self._getUniversal(tc.VAR_LEADER, vehID, "d", dist) 635 636 def getFollower(self, vehID, dist=0.): 637 """getFollower(string, double) -> (string, double) 638 639 Return the following vehicle id together with the distance. The distance 640 is measured from the front + minGap of the follower to the back of vehID, so it does not include the 641 minGap of the follower. 642 The dist parameter defines the minimum lookback, 0 calculates the 643 lookback distance from the braking distance at 4.5m/s^2 at 2*roadSpeedLimit. 644 Due to junctions and lane merges, there may be multiple followers. 645 In this case, the "critical" follower is returned. This is the follower 646 where the value of (getSecureGap - gap) is maximal. 647 Note that the returned follower may be further away than the given dist. 648 """ 649 return self._getUniversal(tc.VAR_FOLLOWER, vehID, "d", dist) 650 651 def getRightFollowers(self, vehID, blockingOnly=False): 652 """ getRightFollowers(string, bool) -> tuple(tuple(string, double)) 653 Convenience method, see getNeighbors() 654 """ 655 if blockingOnly: 656 mode = 5 657 else: 658 mode = 1 659 return self.getNeighbors(vehID, mode) 660 661 def getRightLeaders(self, vehID, blockingOnly=False): 662 """ getRightLeaders(string, bool) -> tuple(tuple(string, double)) 663 Convenience method, see getNeighbors() 664 """ 665 if blockingOnly: 666 mode = 7 667 else: 668 mode = 3 669 return self.getNeighbors(vehID, mode) 670 671 def getLeftFollowers(self, vehID, blockingOnly=False): 672 """ getLeftFollowers(string, bool) -> tuple(tuple(string, double)) 673 Convenience method, see getNeighbors() 674 """ 675 if blockingOnly: 676 mode = 4 677 else: 678 mode = 0 679 return self.getNeighbors(vehID, mode) 680 681 def getLeftLeaders(self, vehID, blockingOnly=False): 682 """ getLeftLeaders(string, bool) -> tuple(tuple(string, double)) 683 Convenience method, see getNeighbors() 684 """ 685 if blockingOnly: 686 mode = 6 687 else: 688 mode = 2 689 return self.getNeighbors(vehID, mode) 690 691 def getNeighbors(self, vehID, mode): 692 """ getNeighbors(string, byte) -> tuple(tuple(string, double)) 693 694 The parameter mode is a bitset (UBYTE), specifying the following: 695 bit 1: query lateral direction (left:0, right:1) 696 bit 2: query longitudinal direction (followers:0, leaders:1) 697 bit 3: blocking (return all:0, return only blockers:1) 698 699 The returned tuple contains pairs (ID, dist) for all lane change relevant neighboring leaders, resp. followers, 700 along with their longitudinal distance to the ego vehicle (egoFront - egoMinGap to leaderBack, resp. 701 followerFront - followerMinGap to egoBack. The value can be negative for overlapping neighs). 702 For the non-sublane case, the lists will contain at most one entry. 703 704 Note: The exact set of blockers in case blocking==1 is not determined for the sublane model, 705 but either all neighboring vehicles are returned (in case LCA_BLOCKED) or 706 none is returned (in case !LCA_BLOCKED). 707 """ 708 return self._getUniversal(tc.VAR_NEIGHBORS, vehID, "B", mode) 709 710 def getFollowSpeed(self, vehID, speed, gap, leaderSpeed, leaderMaxDecel, leaderID=""): 711 """getFollowSpeed(string, double, double, double, double, string) -> double 712 Return the follow speed computed by the carFollowModel of vehID 713 """ 714 return self._getUniversal(tc.VAR_FOLLOW_SPEED, vehID, "tdddds", 5, 715 speed, gap, leaderSpeed, leaderMaxDecel, leaderID) 716 717 def getSecureGap(self, vehID, speed, leaderSpeed, leaderMaxDecel, leaderID=""): 718 """getSecureGap(string, double, double, double, string) -> double 719 Return the secure gap computed by the carFollowModel of vehID 720 """ 721 return self._getUniversal(tc.VAR_SECURE_GAP, vehID, "tddds", 4, 722 speed, leaderSpeed, leaderMaxDecel, leaderID) 723 724 def getStopSpeed(self, vehID, speed, gap): 725 """getStopSpeed(string, double, double) -> double 726 Return the speed for stopping at gap computed by the carFollowModel of vehID 727 """ 728 return self._getUniversal(tc.VAR_STOP_SPEED, vehID, "tdd", 2, speed, gap) 729 730 def getStopDelay(self, vehID): 731 """getStopDelay(string) -> double 732 Returns the expected depart delay at the next stop (if that stop defines the 733 until-attribute) in seconds. Returns -1 if the next stop is not applicable 734 """ 735 return self._getUniversal(tc.VAR_STOP_DELAY, vehID) 736 737 def getStopArrivalDelay(self, vehID): 738 """getStopArrivalDelay(string) -> double 739 Returns the expected arrival delay at the next stop (if that stop defines the 740 arrival-attribute) in seconds. The returned value may be negative to 741 indicate early arrival. Returns INVALID_DOUBLE if the next stop is not applicable 742 """ 743 return self._getUniversal(tc.VAR_STOP_ARRIVALDELAY, vehID) 744 745 def getTimeLoss(self, vehID): 746 """getTimeLoss(string) -> double 747 Returns the time loss since departure 748 """ 749 return self._getUniversal(tc.VAR_TIMELOSS, vehID) 750 751 def getNextTLS(self, vehID): 752 """getNextTLS(string) -> tuple(tuple(string, int, double, string)) 753 754 Return tuple of upcoming traffic lights [(tlsID, tlsIndex, distance, state), ...] 755 """ 756 return self._getUniversal(tc.VAR_NEXT_TLS, vehID) 757 758 @alias_param("dist", "distance") 759 def getJunctionFoes(self, vehID, dist=0.): 760 """getJunctionFoes(string, double) -> complex 761 762 Return tuple of junction foes [(foeId, egoDist, foeDist, egoExitDist, foeExitDist, 763 egoLane, foeLane, egoResponse, foeResponse), ...] within the given distance to the given vehicle. 764 """ 765 return self._getUniversal(tc.VAR_FOES, vehID, "d", dist) 766 767 @deprecated() 768 def getNextStops(self, vehID): 769 """getNextStops(string) -> tuple(tuple(string, double, string, int, double, double)) 770 771 Return tuple of upcoming stops ((lane, endPos, stoppingPlaceID, stopFlags, duration, until), ...) 772 where integer stopFlag is defined as: 773 1 * stopped + 774 2 * parking + 775 4 * personTriggered + 776 8 * containerTriggered + 777 16 * isBusStop + 778 32 * isContainerStop + 779 64 * chargingStation + 780 128 * parkingarea 781 with each of these flags defined as 0 or 1. 782 """ 783 return self._getUniversal(tc.VAR_NEXT_STOPS, vehID) 784 785 def getNextLinks(self, vehID): 786 """getNextLinks(string) -> tuple(tuple(string, string, bool, bool, bool, string, string, double)) 787 788 Return tuple of upcoming links along the route ((lane, via, priority, opened, foe, 789 state, direction, length), ...) 790 """ 791 return self._getUniversal(tc.VAR_NEXT_LINKS, vehID) 792 793 def getStops(self, vehID, limit=0): 794 """getStops(string, int) -> tuple(StopData) 795 796 Return a tuple of StopData object. The flags are the same as for setStop and 797 replaceStop (and different from getNextStops(!) for backward compatibility): 798 1 * parking + 799 2 * personTriggered + 800 4 * containerTriggered + 801 8 * isBusStop + 802 16 * isContainerStop + 803 32 * chargingStation + 804 64 * parkingarea 805 with each of these flags defined as 0 or 1. 806 807 The optional argument limit can be used to limit the returned stops to 808 the next INT number (i.e. limit=1 if only the next stop is required). 809 Setting a negative limit returns up to 'limit' previous stops (or fewer 810 if the vehicle stopped fewer times previously) 811 """ 812 return self._getUniversal(tc.VAR_NEXT_STOPS2, vehID, "i", limit) 813 814 def subscribeLeader(self, vehID, dist=0., begin=0, end=2**31 - 1): 815 """subscribeLeader(string, double, double, double) -> None 816 817 Subscribe for the leading vehicle id together with the distance. 818 The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap. 819 """ 820 self.subscribe(vehID, (tc.VAR_LEADER,), begin, end, {tc.VAR_LEADER: ("d", dist)}) 821 822 def getDrivingDistance(self, vehID, edgeID, pos, laneIndex=0): 823 """getDrivingDistance(string, string, double, integer) -> double 824 825 For an edge along the remaining route of vehID, return the distance from the current vehicle position 826 to the given edge and position along the vehicles route. 827 Otherwise, return INVALID_DOUBLE_VALUE 828 """ 829 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tru", 2, 830 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST) 831 832 def getDrivingDistance2D(self, vehID, x, y): 833 """getDrivingDistance2D(string, double, double) -> integer 834 835 Return the distance to the given network position along the vehicles route. 836 """ 837 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST) 838 839 def getDistance(self, vehID): 840 """getDistance(string) -> double 841 842 Returns the distance to the starting point like an odometer. 843 """ 844 return self._getUniversal(tc.VAR_DISTANCE, vehID) 845 846 def getReferenceDistance(self, vehID): 847 """getReferenceDistance(string) -> double 848 Returns the distance along the linear reference system 849 in which the current edge takes part (i.e. kilometrage/mile markers) 850 """ 851 return self._getUniversal(tc.VAR_REFERENCE_DISTANCE, vehID) 852 853 def getStopParameter(self, vehID, nextStopIndex, param, customParam=False): 854 """getStopParameter(string, int, string) -> string 855 Gets the value of the given parameter for the stop at the given index 856 Negative indices permit access to past stops. 857 Supported params correspond to all legal stop xml-attributes 858 If customParam is set to True, the user defined stop parameter with the 859 specified param name will be returned instead (or "" if undefined) 860 """ 861 return self._getUniversal(tc.VAR_STOP_PARAMETER, vehID, "tisb", 3, nextStopIndex, param, customParam) 862 863 def getStopState(self, vehID): 864 """getStopState(string) -> integer 865 866 Returns information in regard to stopping: 867 The returned integer is defined as 1 * stopped + 2 * parking 868 + 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop 869 + 32 * isContainerStop 870 with each of these flags defined as 0 or 1 871 """ 872 return self._getUniversal(tc.VAR_STOPSTATE, vehID) 873 874 def isStopped(self, vehID): 875 """isStopped(string) -> bool 876 Return whether the vehicle is stopped 877 """ 878 return (self.getStopState(vehID) & 1) == 1 879 880 def isStoppedParking(self, vehID): 881 """isStoppedParking(string) -> bool 882 Return whether the vehicle is parking (implies stopped) 883 """ 884 return (self.getStopState(vehID) & 2) == 2 885 886 def isStoppedTriggered(self, vehID): 887 """isStoppedTriggered(string) -> bool 888 Return whether the vehicle is stopped and waiting for a person or container 889 """ 890 return (self.getStopState(vehID) & 12) > 0 891 892 def isAtBusStop(self, vehID): 893 """isAtBusStop(string) -> bool 894 Return whether the vehicle is stopped at a bus stop 895 """ 896 return (self.getStopState(vehID) & 16) == 16 897 898 def isAtContainerStop(self, vehID): 899 """isAtContainerStop(string) -> bool 900 Return whether the vehicle is stopped at a container stop 901 """ 902 return (self.getStopState(vehID) & 32) == 32 903 904 def getLaneChangeState(self, vehID, direction): 905 """getLaneChangeState(string, int) -> (int, int) 906 Return the lane change state for the vehicle. The first value returns 907 the state as computed by the lane change model and the second value 908 returns the state after incorporation TraCI requests. 909 See getLaneChangeStatePretty for an interpretation of the integer/bitset 910 results 911 """ 912 return self._getUniversal(tc.CMD_CHANGELANE, vehID, "i", direction) 913 914 def getLaneChangeStatePretty(self, vehID, direction): 915 """getLaneChangeStatePretty(string, int) -> ([string, ...], [string, ...]) 916 Return the lane change state for the vehicle as two lists of string 917 constants. The first tuple returns the state as computed by the lane change 918 model and the second tuple returns the state after incorporation TraCI requests. 919 """ 920 constants = { 921 0: 'stay', 922 1: 'left', 923 2: 'right', 924 3: 'strategic', 925 4: 'cooperative', 926 5: 'speedGain', 927 6: 'keepRight', 928 7: 'TraCI', 929 8: 'urgent', 930 9: 'blocked by left leader', 931 10: 'blocked by left follower', 932 11: 'blocked by right leader', 933 12: 'blocked by right follower', 934 13: 'overlapping', 935 14: 'insufficient space', 936 15: 'sublane', 937 } 938 939 def prettifyBitstring(intval): 940 return tuple([v for k, v in constants.items() if (intval & 2**k)]) 941 942 state, stateTraCI = self.getLaneChangeState(vehID, direction) 943 return prettifyBitstring(state), prettifyBitstring(stateTraCI) 944 945 def couldChangeLane(self, vehID, direction, state=None): 946 """couldChangeLane(string, int) -> bool 947 Return whether the vehicle could change lanes in the specified direction. 948 This reflects the state after the last try to change lanes. 949 If you want to execute changeLane as a result of the evaluation of this function 950 it is not guaranteed to work because vehicle movements occur first. 951 """ 952 if state is None: 953 state, stateTraCI = self.getLaneChangeState(vehID, direction) 954 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 955 # vehicle changed in the last step. state is no longer applicable 956 return False 957 return state != tc.LCA_UNKNOWN and (state & tc.LCA_BLOCKED == 0) 958 959 def wantsAndCouldChangeLane(self, vehID, direction, state=None): 960 """wantsAndCouldChangeLane(string, int) -> bool 961 Return whether the vehicle wants to and could change lanes in the specified direction 962 This reflects the state after the last try to change lanes. 963 If you want to execute changeLane as a result of the evaluation of this function 964 it is not guaranteed to work because vehicle movements occur first. 965 """ 966 if state is None: 967 state, stateTraCI = self.getLaneChangeState(vehID, direction) 968 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 969 # vehicle changed in the last step. state is no longer applicable 970 return False 971 if state & tc.LCA_BLOCKED == 0: 972 if direction == -1: 973 return state & tc.LCA_RIGHT != 0 974 if direction == 1: 975 return state & tc.LCA_LEFT != 0 976 return False 977 978 def getRoutingMode(self, vehID): 979 """getRoutingMode(string) 980 returns the current routing mode: 981 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 982 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 983 """ 984 return self._getUniversal(tc.VAR_ROUTING_MODE, vehID) 985 986 @alias_param("taxiState", "flag") 987 def getTaxiFleet(self, taxiState=0): 988 """getTaxiFleet(int) -> tuple(string) 989 Return the tuple of all taxis with the given taxiState: 990 0 : empty 991 1 : pickup 992 2 : occupied 993 """ 994 return self._getUniversal(tc.VAR_TAXI_FLEET, "", "i", taxiState) 995 996 def getLoadedIDList(self): 997 """getLoadedIDList() -> tuple(string) 998 returns all loaded vehicles that have not yet left the simulation 999 """ 1000 return self._getUniversal(tc.VAR_LOADED_LIST, "") 1001 1002 def getTeleportingIDList(self): 1003 """getTeleportingIDList() -> tuple(string) 1004 returns all teleporting or jumping vehicles 1005 """ 1006 return self._getUniversal(tc.VAR_TELEPORTING_LIST, "") 1007 1008 def rerouteParkingArea(self, vehID, parkingAreaID): 1009 """rerouteParkingArea(string, string) 1010 1011 Changes the next parking area in parkingAreaID, updates the vehicle route, 1012 and preserve consistency in case of passengers/containers on board. 1013 """ 1014 self._setCmd(tc.CMD_REROUTE_TO_PARKING, vehID, "ts", 1, parkingAreaID) 1015 1016 def setStop(self, vehID, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1017 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, until=tc.INVALID_DOUBLE_VALUE): 1018 """setStop(string, string, double, integer, double, integer, double, double) -> None 1019 1020 Adds or modifies a stop with the given parameters. The duration and the until attribute are 1021 in seconds. 1022 """ 1023 if type(duration) is int and duration >= 1000 and duration % 1000 == 0: 1024 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1025 self._setCmd(tc.CMD_STOP, vehID, "tsdbdbdd", 7, edgeID, pos, laneIndex, duration, flags, startPos, until) 1026 1027 def setBusStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1028 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1029 """setBusStop(string, string, double, double, integer) -> None 1030 1031 Adds or modifies a bus stop with the given parameters. The duration and the until attribute are 1032 in seconds. 1033 """ 1034 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_BUS_STOP) 1035 1036 def setContainerStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1037 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1038 """setContainerStop(string, string, double, double, integer) -> None 1039 1040 Adds or modifies a container stop with the given parameters. The duration and the until attribute are 1041 in seconds. 1042 """ 1043 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CONTAINER_STOP) 1044 1045 def setChargingStationStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1046 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1047 """setChargingStationStop(string, string, double, double, integer) -> None 1048 1049 Adds or modifies a stop at a chargingStation with the given parameters. The duration and the until attribute are 1050 in seconds. 1051 """ 1052 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CHARGING_STATION) 1053 1054 def setParkingAreaStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1055 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_PARKING): 1056 """setParkingAreaStop(string, string, double, double, integer) -> None 1057 1058 Adds or modifies a stop at a parkingArea with the given parameters. The duration and the until attribute are 1059 in seconds. 1060 """ 1061 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_PARKING_AREA) 1062 1063 def replaceStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1064 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1065 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1066 """replaceStop(string, int, string, double, integer, double, integer, double, double) -> None 1067 1068 Replaces stop at the given index (within the list of all stops) with a new stop. 1069 Automatically modifies the route if the replacement stop is at another location. 1070 For edgeID a stopping place id may be given if the flag marks this 1071 stop as stopping on busStop, parkingArea, containerStop etc. 1072 If edgeID is "", the stop at the given index will be removed without 1073 replacement and the route will not be modified (unless setting 1074 teleport=2 which will trigger rerouting between the prior and next stop) 1075 If teleport is set to 1, the route to the replacement stop will be 1076 disconnected (forcing a teleport). 1077 If stopIndex is 0 the gap will be between the current 1078 edge and the new stop. Otherwise the gap will be between the stop edge for 1079 nextStopIndex - 1 and the new stop. 1080 """ 1081 self._setCmd(tc.CMD_REPLACE_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1082 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport) 1083 1084 def insertStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1085 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1086 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1087 """insertStop(string, int, string, double, integer, double, integer, double, double) -> None 1088 1089 Insert stop at the given index (within the list of all existing stops). 1090 Automatically modifies the route if the new stop is not along the route between the preceeding 1091 and succeeding stops (or start / end). 1092 For edgeID a stopping place id may be given if the flag marks this 1093 stop as stopping on busStop, parkingArea, containerStop etc. 1094 If teleport is set to 1, the route to the new stop will be 1095 disconnected (forcing a teleport). 1096 If stopIndex is 0 the gap will be between the current 1097 edge and the new stop. Otherwise the gap will be between the stop edge for 1098 nextStopIndex - 1 and the new stop. 1099 """ 1100 self._setCmd(tc.CMD_INSERT_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1101 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport) 1102 1103 def setStopParameter(self, vehID, nextStopIndex, param, value, customParam=False): 1104 """setStopParameter(string, int, string, string) -> None 1105 Sets the value of the given parameter for the (upcoming) stop at the 1106 given index (within the list of all stops). 1107 Supported params correspond to (almost) all legal stop xml-attributes 1108 and their value semantics 1109 If customParam is set to True, the user defined stop parameter with the 1110 specified param name will be set instead 1111 """ 1112 self._setCmd(tc.VAR_STOP_PARAMETER, vehID, "tissb", 4, nextStopIndex, param, value, customParam) 1113 1114 def resume(self, vehID): 1115 """resume(string) -> None 1116 1117 Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped). 1118 """ 1119 self._setCmd(tc.CMD_RESUME, vehID, "t", 0) 1120 1121 def changeLane(self, vehID, laneIndex, duration): 1122 """changeLane(string, int, double) -> None 1123 Forces a lane change to the lane with the given index; The lane change 1124 will be attempted for the given duration (in s) and if it succeeds, 1125 the vehicle will stay on that lane for the remaining duration. 1126 """ 1127 if type(duration) is int and duration >= 1000: 1128 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1129 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbd", 2, laneIndex, duration) 1130 1131 def changeLaneRelative(self, vehID, indexOffset, duration): 1132 """changeLaneRelative(string, int, double) -> None 1133 1134 Forces a relative lane change; if successful, 1135 the lane will be chosen for the given amount of time (in s). 1136 The indexOffset specifies the target lane relative to the vehicles current lane 1137 """ 1138 if type(duration) is int and duration >= 1000: 1139 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1140 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbdb", 3, indexOffset, duration, 1) 1141 1142 def changeSublane(self, vehID, latDist): 1143 """changeSublane(string, double) -> None 1144 Forces a lateral change by the given amount (negative values indicate changing to the right, positive 1145 to the left). This will override any other lane change motivations but conform to 1146 safety-constraints as configured by laneChangeMode. 1147 """ 1148 self._setCmd(tc.CMD_CHANGESUBLANE, vehID, "d", latDist) 1149 1150 def slowDown(self, vehID, speed, duration): 1151 """slowDown(string, double, double) -> None 1152 1153 Changes the speed smoothly to the given value over the given amount 1154 of time in seconds (can also be used to increase speed). 1155 """ 1156 if type(duration) is int and duration >= 1000: 1157 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1158 self._setCmd(tc.CMD_SLOWDOWN, vehID, "tdd", 2, speed, duration) 1159 1160 def openGap(self, vehID, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel=-1, referenceVehID=None): 1161 """openGap(string, double, double, double, double, double, string) -> None 1162 1163 Changes the vehicle's desired time headway (cf-parameter tau) smoothly to the given new value 1164 using the given change rate. Similarly, the given space headway is applied gradually 1165 to achieve a minimal spatial gap. 1166 The vehicle is commanded to keep the increased headway for 1167 the given duration once its target value is attained. The maximal value for the 1168 deceleration can be given to prevent harsh braking due to the change of tau. If maxDecel=-1, 1169 the limit determined by the CF model is used. 1170 A vehicle ID for a reference vehicle can optionally be given, otherwise, the gap is created with 1171 respect to the current leader on the ego vehicle's current lane. 1172 Note that this does only affect the following behavior regarding the current leader and does 1173 not influence the gap acceptance during lane change, etc. 1174 """ 1175 if type(duration) is int and duration >= 1000: 1176 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1177 if referenceVehID is None: 1178 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddd", 5, 1179 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel) 1180 else: 1181 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddds", 6, 1182 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, referenceVehID) 1183 1184 def deactivateGapControl(self, vehID): 1185 """deactivateGapControl(string) -> None 1186 1187 Deactivate the vehicle's gap control 1188 """ 1189 self.openGap(vehID, -1, -1, -1, -1) 1190 1191 def requestToC(self, vehID, leadTime): 1192 """ requestToC(string, double) -> None 1193 1194 Interface for triggering a transition of control for a vehicle equipped with a ToC device. 1195 """ 1196 self.setParameter(vehID, "device.toc.requestToC", str(leadTime)) 1197 1198 def changeTarget(self, vehID, edgeID): 1199 """changeTarget(string, string) -> None 1200 1201 The vehicle's destination edge is set to the given edge id. The route is rebuilt. 1202 """ 1203 self._setCmd(tc.CMD_CHANGETARGET, vehID, "s", edgeID) 1204 1205 def setType(self, vehID, typeID): 1206 """setType(string, string) -> None 1207 1208 Sets the id of the type for the named vehicle. 1209 """ 1210 self._setCmd(tc.VAR_TYPE, vehID, "s", typeID) 1211 1212 def setRouteID(self, vehID, routeID): 1213 """setRouteID(string, string) -> None 1214 1215 Changes the vehicles route to the route with the given id. 1216 """ 1217 self._setCmd(tc.VAR_ROUTE_ID, vehID, "s", routeID) 1218 1219 def setRoute(self, vehID, edgeList): 1220 """ 1221 setRoute(string, list) -> None 1222 1223 changes the vehicle route to given edges list. 1224 The first edge in the list has to be the one that the vehicle is at the moment. 1225 1226 example usage: 1227 setRoute('1', ['1', '2', '4', '6', '7']) 1228 1229 this changes route for vehicle id 1 to edges 1-2-4-6-7 1230 """ 1231 if isinstance(edgeList, str): 1232 edgeList = [edgeList] 1233 self._setCmd(tc.VAR_ROUTE, vehID, "l", edgeList) 1234 1235 def setLateralLanePosition(self, vehID, posLat): 1236 """setLateralLanePosition(string, double) -> None 1237 1238 Sets the lateral vehicle position relative to the center line of the 1239 lane in m (negative values are to the right in right-hand networks). 1240 The vehicle may adapt this position in the same step unless this is 1241 disabled via setLaneChangeMode. 1242 """ 1243 self._setCmd(tc.VAR_LANEPOSITION_LAT, vehID, "d", posLat) 1244 1245 def updateBestLanes(self, vehID): 1246 """ updateBestLanes(string) -> None 1247 Triggers an update of the vehicle's bestLanes (structure determining the lane preferences used by LC models) 1248 It may be called after modifying the vClass for instance. 1249 """ 1250 self._setCmd(tc.VAR_UPDATE_BESTLANES, vehID) 1251 1252 def setAdaptedTraveltime(self, vehID, edgeID, time=None, begTime=None, endTime=None): 1253 """setAdaptedTraveltime(string, string, double, double, double) -> None 1254 Inserts the information about the travel time of edge "edgeID" valid 1255 from begin time to end time into the vehicle's internal edge weights 1256 container. 1257 If the time is not specified, any previously set values for that edge 1258 are removed. 1259 If begTime or endTime are not specified the value is set for the whole 1260 simulation duration. 1261 """ 1262 if not isinstance(edgeID, str) and isinstance(begTime, str): 1263 # legacy handling 1264 warnings.warn( 1265 "Parameter order has changed for setAdaptedTraveltime(). Attempting legacy ordering. " + 1266 "Please update your code.", stacklevel=2) 1267 return self.setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time) 1268 if time is None: 1269 # reset 1270 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "ts", 1, edgeID) 1271 elif begTime is None: 1272 # set value for the whole simulation 1273 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tsd", 2, edgeID, time) 1274 else: 1275 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tddsd", 4, begTime, endTime, edgeID, time) 1276 1277 def setEffort(self, vehID, edgeID, effort=None, begTime=None, endTime=None): 1278 """setEffort(string, string, double, double, double) -> None 1279 Inserts the information about the effort of edge "edgeID" valid from 1280 begin time to end time into the vehicle's internal edge weights 1281 container. 1282 If the time is not specified, any previously set values for that edge 1283 are removed. 1284 If begTime or endTime are not specified the value is set for the whole 1285 simulation duration. 1286 """ 1287 if not isinstance(edgeID, str) and isinstance(begTime, str): 1288 # legacy handling 1289 warnings.warn( 1290 "Parameter order has changed for setEffort(). Attempting legacy ordering. Please update your code.", 1291 stacklevel=2) 1292 return self.setEffort(vehID, begTime, endTime, edgeID, effort) 1293 if effort is None: 1294 # reset 1295 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "ts", 1, edgeID) 1296 elif begTime is None: 1297 # set value for the whole simulation 1298 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tsd", 2, edgeID, effort) 1299 else: 1300 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tddsd", 4, begTime, endTime, edgeID, effort) 1301 1302 LAST_TRAVEL_TIME_UPDATE = -1 1303 1304 def setRoutingMode(self, vehID, routingMode): 1305 """setRoutingMode(string, int) -> None 1306 Sets the current routing mode: 1307 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 1308 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 1309 tc.ROUTING_MODE_AGGREGATED_CUSTOM : use weight storages and fall-back to smoothed travel times 1310 """ 1311 self._setCmd(tc.VAR_ROUTING_MODE, vehID, "i", routingMode) 1312 1313 def rerouteTraveltime(self, vehID, currentTravelTimes=True): 1314 """rerouteTraveltime(string, bool) -> None 1315 Reroutes a vehicle. 1316 If currentTravelTimes is True (default) and the routing mode is still ROUTING_MODE_DEFAULT 1317 then the ROUTING_MODE_AGGREGATED_CUSTOM gets activated temporarily 1318 and used for rerouting. The various functions and options for 1319 customizing travel times are described at https://sumo.dlr.de/wiki/Simulation/Routing 1320 1321 When rerouteTraveltime has been called once with an aggregated routing mode, 1322 edge weight storage and update gets activated which might slow down the simulation. 1323 """ 1324 if currentTravelTimes: 1325 routingMode = self.getRoutingMode(vehID) 1326 if routingMode == tc.ROUTING_MODE_DEFAULT: 1327 self.setRoutingMode(vehID, tc.ROUTING_MODE_AGGREGATED_CUSTOM) 1328 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, vehID, "t", 0) 1329 if currentTravelTimes and routingMode == tc.ROUTING_MODE_DEFAULT: 1330 self.setRoutingMode(vehID, routingMode) 1331 1332 def rerouteEffort(self, vehID): 1333 """rerouteEffort(string) -> None 1334 Reroutes a vehicle according to the effort values. 1335 """ 1336 self._setCmd(tc.CMD_REROUTE_EFFORT, vehID, "t", 0) 1337 1338 def setSignals(self, vehID, signals): 1339 """setSignals(string, integer) -> None 1340 1341 Sets an integer encoding the state of the vehicle's signals. 1342 """ 1343 self._setCmd(tc.VAR_SIGNALS, vehID, "i", signals) 1344 1345 def moveTo(self, vehID, laneID, pos, reason=tc.MOVE_AUTOMATIC): 1346 """moveTo(string, string, double, integer) -> None 1347 1348 Move a vehicle to a new position along its current route. 1349 """ 1350 self._setCmd(tc.VAR_MOVE_TO, vehID, "tsdi", 3, laneID, pos, reason) 1351 1352 def setSpeed(self, vehID, speed): 1353 """setSpeed(string, double) -> None 1354 1355 Sets the speed in m/s for the named vehicle within the last step. 1356 Calling with speed=-1 hands the vehicle control back to SUMO. 1357 """ 1358 self._setCmd(tc.VAR_SPEED, vehID, "d", speed) 1359 1360 def setAcceleration(self, vehID, acceleration, duration): 1361 """setAcceleration(string, double, double) -> None 1362 1363 Sets the acceleration in m/s^2 for the named vehicle and the given duration. 1364 """ 1365 self._setCmd(tc.VAR_ACCELERATION, vehID, "tdd", 2, acceleration, duration) 1366 1367 def setPreviousSpeed(self, vehID, speed, acceleration=tc.INVALID_DOUBLE_VALUE): 1368 """setPreviousSpeed(string, double, double) -> None 1369 1370 Sets the previous speed in m/s for the named vehicle wich will be used for 1371 calculations in the current step. Optionally, the acceleration for the 1372 previous step (in m/s^2) can be set as well. 1373 """ 1374 self._setCmd(tc.VAR_PREV_SPEED, vehID, "tdd", 2, speed, acceleration) 1375 1376 def setLine(self, vehID, line): 1377 """setLine(string, string) -> None 1378 1379 Sets the line information for this vehicle. 1380 """ 1381 self._setCmd(tc.VAR_LINE, vehID, "s", line) 1382 1383 def setVia(self, vehID, edgeList): 1384 """ 1385 setVia(string, list) -> None 1386 1387 changes the via edges to the given edges list (to be used during 1388 subsequent rerouting calls). 1389 1390 Note: a single edgeId as argument is allowed as shorthand for a list of length 1 1391 """ 1392 if isinstance(edgeList, str): 1393 edgeList = [edgeList] 1394 self._setCmd(tc.VAR_VIA, vehID, "l", edgeList) 1395 1396 def highlight(self, vehID, color=(255, 0, 0, 255), size=-1, alphaMax=-1, duration=-1, type=0): 1397 """ highlight(string, color, float, ubyte, float, ubyte) -> None 1398 Adds a circle of the given color tracking the vehicle. 1399 If a positive size [in m] is given the size of the highlight is chosen accordingly, 1400 otherwise the length of the vehicle is used as reference. 1401 If alphaMax and duration are positive, the circle fades in and out within the given duration, 1402 otherwise it permanently follows the vehicle. 1403 """ 1404 if type > 255: 1405 raise TraCIException("vehicle.highlight(): maximal value for type is 255") 1406 if alphaMax > 255: 1407 raise TraCIException("vehicle.highlight(): maximal value for alphaMax is 255") 1408 if alphaMax <= 0 and duration > 0: 1409 raise TraCIException("vehicle.highlight(): duration>0 requires alphaMax>0") 1410 if alphaMax > 0 and duration <= 0: 1411 raise TraCIException("vehicle.highlight(): alphaMax>0 requires duration>0") 1412 1413 if alphaMax > 0: 1414 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcdBdB", 5, color, size, alphaMax, duration, type) 1415 else: 1416 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcd", 2, color, size) 1417 1418 @alias_param("laneChangeMode", "lcm") 1419 def setLaneChangeMode(self, vehID, laneChangeMode): 1420 """setLaneChangeMode(string, integer) -> None 1421 1422 Sets the vehicle's lane change mode as a bitset. 1423 """ 1424 self._setCmd(tc.VAR_LANECHANGE_MODE, vehID, "i", laneChangeMode) 1425 1426 @alias_param("speedMode", "sm") 1427 def setSpeedMode(self, vehID, speedMode): 1428 """setSpeedMode(string, integer) -> None 1429 1430 Sets the vehicle's speed mode as a bitset. 1431 """ 1432 self._setCmd(tc.VAR_SPEEDSETMODE, vehID, "i", speedMode) 1433 1434 def addLegacy(self, vehID, routeID, depart=tc.DEPARTFLAG_NOW, pos=0, speed=0, 1435 lane=tc.DEPARTFLAG_LANE_FIRST_ALLOWED, typeID="DEFAULT_VEHTYPE"): 1436 """ 1437 Add a new vehicle (old style) 1438 """ 1439 if depart == tc.DEPARTFLAG_NOW: 1440 depart = "now" 1441 elif depart == tc.DEPARTFLAG_TRIGGERED: 1442 depart = "triggered" 1443 else: 1444 depart = str(depart) 1445 if pos < 0: 1446 print("Invalid departure position.") 1447 return 1448 if lane == tc.DEPARTFLAG_LANE_FIRST_ALLOWED: 1449 lane = "first" 1450 elif lane == tc.DEPARTFLAG_LANE_FREE: 1451 lane = "free" 1452 else: 1453 lane = str(lane) 1454 self.addFull(vehID, routeID, typeID, depart, lane, str(pos), str(speed)) 1455 1456 def add(self, vehID, routeID, typeID="DEFAULT_VEHTYPE", depart="now", 1457 departLane="first", departPos="base", departSpeed="0", 1458 arrivalLane="current", arrivalPos="max", arrivalSpeed="current", 1459 fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0): 1460 """ 1461 Add a new vehicle (new style with all possible parameters) 1462 If routeID is "", the vehicle will be inserted on a random network edge 1463 if route consists of two disconnected edges, the vehicle will be treated 1464 like a <trip> and use the fastest route between the two edges. 1465 """ 1466 if depart is None: 1467 # legacy compatibility 1468 depart = str(self._connection.simulation.getTime()) 1469 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii", 14, 1470 routeID, typeID, depart, departLane, departPos, departSpeed, 1471 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, personCapacity, personNumber) 1472 1473 addFull = add 1474 1475 def dispatchTaxi(self, vehID, reservations): 1476 """dispatchTaxi(string, list(string)) -> None 1477 dispatches the taxi with the given id to service the given reservations. 1478 If only a single reservation is given, this implies pickup and drop-off 1479 If multiple reservations are given, each reservation id must occur twice 1480 (once for pickup and once for drop-off) and the list encodes ride 1481 sharing of passengers (in pickup and drop-off order) 1482 """ 1483 if isinstance(reservations, str): 1484 reservations = [reservations] 1485 self._setCmd(tc.CMD_TAXI_DISPATCH, vehID, "l", reservations) 1486 1487 def remove(self, vehID, reason=tc.REMOVE_VAPORIZED): 1488 '''Remove vehicle with the given ID for the give reason. 1489 Reasons are defined in module constants and start with REMOVE_''' 1490 self._setCmd(tc.REMOVE, vehID, "b", reason) 1491 1492 @alias_param("laneIndex", "lane") 1493 def moveToXY(self, vehID, edgeID, laneIndex, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 1494 '''Place vehicle at the given x,y coordinates and force its angle to 1495 the given value (for drawing). 1496 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 1497 natural angle of the edge on which it is driving. 1498 If keepRoute is set to 1, the closest position 1499 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 1500 any edge in the network but its route then only consists of that edge. 1501 If keepRoute is set to 2 the vehicle has all the freedom of keepRoute=0 1502 but in addition to that may even move outside the road network. 1503 edgeID and lane are optional placement hints to resolve ambiguities. 1504 The command fails if no suitable target position is found within the 1505 distance given by matchThreshold. 1506 ''' 1507 self._setCmd(tc.MOVE_TO_XY, vehID, "tsidddbd", 7, edgeID, laneIndex, x, y, angle, keepRoute, matchThreshold) 1508 1509 def addSubscriptionFilterLanes(self, lanes, noOpposite=False, downstreamDist=None, upstreamDist=None): 1510 """addSubscriptionFilterLanes(list(integer), bool, double, double) -> None 1511 1512 Adds a lane-filter to the last modified vehicle context subscription (call it just after subscribing). 1513 lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.) 1514 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1515 downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net. 1516 """ 1517 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1518 if noOpposite: 1519 self.addSubscriptionFilterNoOpposite() 1520 if downstreamDist is not None: 1521 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1522 if upstreamDist is not None: 1523 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1524 1525 def addSubscriptionFilterNoOpposite(self): 1526 """addSubscriptionFilterNoOpposite() -> None 1527 1528 Omits vehicles on other edges than the ego's for the last modified vehicle context subscription 1529 (call it just after subscribing). 1530 """ 1531 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_NOOPPOSITE) 1532 1533 def addSubscriptionFilterDownstreamDistance(self, dist): 1534 """addSubscriptionFilterDownstreamDist(float) -> None 1535 1536 Sets the downstream distance along the network for vehicles to be returned by the last modified 1537 vehicle context subscription (call it just after subscribing). 1538 """ 1539 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_DOWNSTREAM_DIST, dist) 1540 1541 def addSubscriptionFilterUpstreamDistance(self, dist): 1542 """addSubscriptionFilterUpstreamDist(float) -> None 1543 1544 Sets the upstream distance along the network for vehicles to be returned by the last modified 1545 vehicle context subscription (call it just after subscribing). 1546 """ 1547 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_UPSTREAM_DIST, dist) 1548 1549 def addSubscriptionFilterCFManeuver(self, downstreamDist=None, upstreamDist=None): 1550 """addSubscriptionFilterCFManeuver() -> None 1551 1552 Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego. 1553 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1554 """ 1555 self.addSubscriptionFilterLeadFollow([0]) 1556 if downstreamDist is not None: 1557 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1558 if upstreamDist is not None: 1559 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1560 1561 def addSubscriptionFilterLCManeuver(self, direction=None, noOpposite=False, downstreamDist=None, upstreamDist=None): 1562 """addSubscriptionFilterLCManeuver(int) -> None 1563 1564 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1565 and follower of the ego. 1566 direction - lane change direction (in {-1=right, 1=left}) 1567 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1568 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1569 Combine with: distance filters; vClass/vType filter. 1570 """ 1571 if direction is None: 1572 # Using default: both directions 1573 lanes = [-1, 0, 1] 1574 elif not (direction == -1 or direction == 1): 1575 warnings.warn("Ignoring lane change subscription filter " + 1576 "with non-neighboring lane offset direction=%s." % direction) 1577 return 1578 else: 1579 lanes = [0, direction] 1580 self.addSubscriptionFilterLeadFollow(lanes) 1581 if noOpposite: 1582 self.addSubscriptionFilterNoOpposite() 1583 if downstreamDist is not None: 1584 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1585 if upstreamDist is not None: 1586 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1587 1588 def addSubscriptionFilterLeadFollow(self, lanes): 1589 """addSubscriptionFilterLCManeuver(lanes) -> None 1590 1591 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1592 and follower of the ego. 1593 Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter. 1594 """ 1595 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LEAD_FOLLOW) 1596 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1597 1598 def addSubscriptionFilterTurn(self, downstreamDist=None, foeDistToJunction=None): 1599 """addSubscriptionFilterTurn(double, double) -> None 1600 1601 Restricts vehicles returned by the last modified vehicle context subscription to foes on upcoming junctions 1602 """ 1603 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_TURN, foeDistToJunction) 1604 if downstreamDist is not None: 1605 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1606 1607 def addSubscriptionFilterVClass(self, vClasses): 1608 """addSubscriptionFilterVClass(list(String)) -> None 1609 1610 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given classes 1611 """ 1612 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VCLASS, vClasses) 1613 1614 def addSubscriptionFilterVType(self, vTypes): 1615 """addSubscriptionFilterVType(list(String)) -> None 1616 1617 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given types 1618 """ 1619 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VTYPE, vTypes) 1620 1621 def addSubscriptionFilterFieldOfVision(self, openingAngle): 1622 """addSubscriptionFilterFieldOfVision(float) -> None 1623 1624 Restricts vehicles returned by the last modified vehicle context subscription 1625 to vehicles within field of vision with given opening angle 1626 """ 1627 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_FIELD_OF_VISION, openingAngle) 1628 1629 def addSubscriptionFilterLateralDistance(self, lateralDist, downstreamDist=None, upstreamDist=None): 1630 """addSubscriptionFilterLateralDist(double, double, double) -> None 1631 1632 Adds a lateral distance filter to the last modified vehicle context subscription 1633 (call it just after subscribing). 1634 downstreamDist and upstreamDist specify the longitudinal range of the search 1635 for surrounding vehicles along the ego vehicle's route. 1636 """ 1637 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LATERAL_DIST, lateralDist) 1638 if downstreamDist is not None: 1639 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1640 if upstreamDist is not None: 1641 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
This class contains all functions which are common to the vehicletype, vehicle and person domain
278 def getSpeed(self, vehID): 279 """getSpeed(string) -> double 280 281 Returns the (longitudinal) speed in m/s of the named vehicle within the last step. 282 """ 283 return self._getUniversal(tc.VAR_SPEED, vehID)
getSpeed(string) -> double
Returns the (longitudinal) speed in m/s of the named vehicle within the last step.
285 def getLateralSpeed(self, vehID): 286 """getLateralSpeed(string) -> double 287 288 Returns the lateral speed in m/s of the named vehicle within the last step. 289 """ 290 return self._getUniversal(tc.VAR_SPEED_LAT, vehID)
getLateralSpeed(string) -> double
Returns the lateral speed in m/s of the named vehicle within the last step.
292 def getAcceleration(self, vehID): 293 """getAcceleration(string) -> double 294 295 Returns the acceleration in m/s^2 of the named vehicle within the last step. 296 """ 297 return self._getUniversal(tc.VAR_ACCELERATION, vehID)
getAcceleration(string) -> double
Returns the acceleration in m/s^2 of the named vehicle within the last step.
299 def getSpeedWithoutTraCI(self, vehID): 300 """getSpeedWithoutTraCI(string) -> double 301 Returns the speed that the vehicle would drive if no speed-influencing 302 command such as setSpeed or slowDown was given. 303 """ 304 return self._getUniversal(tc.VAR_SPEED_WITHOUT_TRACI, vehID)
getSpeedWithoutTraCI(string) -> double Returns the speed that the vehicle would drive if no speed-influencing command such as setSpeed or slowDown was given.
306 def getPosition(self, vehID): 307 """getPosition(string) -> (double, double) 308 309 Returns the position of the named vehicle within the last step [m,m]. 310 """ 311 return self._getUniversal(tc.VAR_POSITION, vehID)
getPosition(string) -> (double, double)
Returns the position of the named vehicle within the last step [m,m].
313 def getPosition3D(self, vehID): 314 """getPosition3D(string) -> (double, double, double) 315 316 Returns the position of the named vehicle within the last step [m,m,m]. 317 """ 318 return self._getUniversal(tc.VAR_POSITION3D, vehID)
getPosition3D(string) -> (double, double, double)
Returns the position of the named vehicle within the last step [m,m,m].
320 def getAngle(self, vehID): 321 """getAngle(string) -> double 322 323 Returns the angle in degrees of the named vehicle within the last step. 324 """ 325 return self._getUniversal(tc.VAR_ANGLE, vehID)
getAngle(string) -> double
Returns the angle in degrees of the named vehicle within the last step.
327 def getRoadID(self, vehID): 328 """getRoadID(string) -> string 329 330 Returns the id of the edge the named vehicle was at within the last step. 331 """ 332 return self._getUniversal(tc.VAR_ROAD_ID, vehID)
getRoadID(string) -> string
Returns the id of the edge the named vehicle was at within the last step.
334 def getDeparture(self, vehID): 335 """getDeparture(string) -> double 336 337 Returns the actual departure time in seconds 338 """ 339 return self._getUniversal(tc.VAR_DEPARTURE, vehID)
getDeparture(string) -> double
Returns the actual departure time in seconds
341 def getDepartDelay(self, vehID): 342 """getDepartDelay(string) -> double 343 344 Returns the delay between intended and actual departure in seconds 345 """ 346 return self._getUniversal(tc.VAR_DEPART_DELAY, vehID)
getDepartDelay(string) -> double
Returns the delay between intended and actual departure in seconds
348 def getLaneID(self, vehID): 349 """getLaneID(string) -> string 350 351 Returns the id of the lane the named vehicle was at within the last step. 352 """ 353 return self._getUniversal(tc.VAR_LANE_ID, vehID)
getLaneID(string) -> string
Returns the id of the lane the named vehicle was at within the last step.
355 def getShadowLaneID(self, vehID): 356 """getShadowLaneID(string) -> string 357 358 Returns the id of the shadow lane if the vehicle is currently changing lanes. 359 """ 360 return self._getUniversal(tc.VAR_SHADOW_LANE_ID, vehID)
getShadowLaneID(string) -> string
Returns the id of the shadow lane if the vehicle is currently changing lanes.
362 def getLaneIndex(self, vehID): 363 """getLaneIndex(string) -> integer 364 365 Returns the index of the lane the named vehicle was at within the last step. 366 """ 367 return self._getUniversal(tc.VAR_LANE_INDEX, vehID)
getLaneIndex(string) -> integer
Returns the index of the lane the named vehicle was at within the last step.
369 def getSegmentID(self, vehID): 370 """getSegmentID(string) -> string 371 372 Returns the id of the segment the named vehicle was at within the last step (mesosim). 373 """ 374 return self._getUniversal(tc.VAR_SEGMENT_ID, vehID)
getSegmentID(string) -> string
Returns the id of the segment the named vehicle was at within the last step (mesosim).
376 def getSegmentIndex(self, vehID): 377 """getSegmentIndex(string) -> integer 378 379 Returns the index of the segment the named vehicle was at within the last step (mesosim). 380 """ 381 return self._getUniversal(tc.VAR_SEGMENT_INDEX, vehID)
getSegmentIndex(string) -> integer
Returns the index of the segment the named vehicle was at within the last step (mesosim).
383 def getTypeID(self, vehID): 384 """getTypeID(string) -> string 385 386 Returns the id of the type of the named vehicle. 387 """ 388 return self._getUniversal(tc.VAR_TYPE, vehID)
getTypeID(string) -> string
Returns the id of the type of the named vehicle.
390 def getRouteID(self, vehID): 391 """getRouteID(string) -> string 392 393 Returns the id of the route of the named vehicle. 394 """ 395 return self._getUniversal(tc.VAR_ROUTE_ID, vehID)
getRouteID(string) -> string
Returns the id of the route of the named vehicle.
397 def getRouteIndex(self, vehID): 398 """getRouteIndex(string) -> int 399 400 Returns the index of the current edge within the vehicles route or -1 if the 401 vehicle has not yet departed 402 """ 403 return self._getUniversal(tc.VAR_ROUTE_INDEX, vehID)
getRouteIndex(string) -> int
Returns the index of the current edge within the vehicles route or -1 if the vehicle has not yet departed
405 def getRoute(self, vehID): 406 """getRoute(string) -> tuple(string) 407 408 Returns the ids of the edges the vehicle's route is made of. 409 """ 410 return self._getUniversal(tc.VAR_EDGES, vehID)
getRoute(string) -> tuple(string)
Returns the ids of the edges the vehicle's route is made of.
412 def getLanePosition(self, vehID): 413 """getLanePosition(string) -> double 414 415 The position of the vehicle along the lane measured in m. 416 """ 417 return self._getUniversal(tc.VAR_LANEPOSITION, vehID)
getLanePosition(string) -> double
The position of the vehicle along the lane measured in m.
419 def getCO2Emission(self, vehID): 420 """getCO2Emission(string) -> double 421 422 Returns the CO2 emission in mg/s for the last time step. 423 Multiply by the step length to get the value for one step. 424 """ 425 return self._getUniversal(tc.VAR_CO2EMISSION, vehID)
getCO2Emission(string) -> double
Returns the CO2 emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
427 def getCOEmission(self, vehID): 428 """getCOEmission(string) -> double 429 430 Returns the CO emission in mg/s for the last time step. 431 Multiply by the step length to get the value for one step. 432 """ 433 return self._getUniversal(tc.VAR_COEMISSION, vehID)
getCOEmission(string) -> double
Returns the CO emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
435 def getHCEmission(self, vehID): 436 """getHCEmission(string) -> double 437 438 Returns the HC emission in mg/s for the last time step. 439 Multiply by the step length to get the value for one step. 440 """ 441 return self._getUniversal(tc.VAR_HCEMISSION, vehID)
getHCEmission(string) -> double
Returns the HC emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
443 def getPMxEmission(self, vehID): 444 """getPMxEmission(string) -> double 445 446 Returns the particular matter emission in mg/s for the last time step. 447 Multiply by the step length to get the value for one step. 448 """ 449 return self._getUniversal(tc.VAR_PMXEMISSION, vehID)
getPMxEmission(string) -> double
Returns the particular matter emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
451 def getNOxEmission(self, vehID): 452 """getNOxEmission(string) -> double 453 454 Returns the NOx emission in mg/s for the last time step. 455 Multiply by the step length to get the value for one step. 456 """ 457 return self._getUniversal(tc.VAR_NOXEMISSION, vehID)
getNOxEmission(string) -> double
Returns the NOx emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
459 def getFuelConsumption(self, vehID): 460 """getFuelConsumption(string) -> double 461 462 Returns the fuel consumption in mg/s for the last time step. 463 Multiply by the step length to get the value for one step. 464 """ 465 return self._getUniversal(tc.VAR_FUELCONSUMPTION, vehID)
getFuelConsumption(string) -> double
Returns the fuel consumption in mg/s for the last time step. Multiply by the step length to get the value for one step.
467 def getNoiseEmission(self, vehID): 468 """getNoiseEmission(string) -> double 469 470 Returns the noise emission in db for the last time step. 471 """ 472 return self._getUniversal(tc.VAR_NOISEEMISSION, vehID)
getNoiseEmission(string) -> double
Returns the noise emission in db for the last time step.
474 def getElectricityConsumption(self, vehID): 475 """getElectricityConsumption(string) -> double 476 477 Returns the electricity consumption in Wh/s for the last time step. 478 Multiply by the step length to get the value for one step. 479 """ 480 return self._getUniversal(tc.VAR_ELECTRICITYCONSUMPTION, vehID)
getElectricityConsumption(string) -> double
Returns the electricity consumption in Wh/s for the last time step. Multiply by the step length to get the value for one step.
482 def getPersonNumber(self, vehID): 483 """getPersonNumber(string) -> integer 484 Returns the total number of persons which includes those defined 485 using attribute 'personNumber' as well as <person>-objects who are riding in 486 this vehicle. 487 """ 488 return self._getUniversal(tc.VAR_PERSON_NUMBER, vehID)
getPersonNumber(string) -> integer
Returns the total number of persons which includes those defined
using attribute 'personNumber' as well as
490 def getPersonIDList(self, vehID): 491 """getPersonIDList(string) -> tuple(string) 492 Returns the tuple of persons who are riding in this vehicle. 493 """ 494 return self._getUniversal(tc.LAST_STEP_PERSON_ID_LIST, vehID)
getPersonIDList(string) -> tuple(string) Returns the tuple of persons who are riding in this vehicle.
496 def getAdaptedTraveltime(self, vehID, time, edgeID): 497 """getAdaptedTraveltime(string, double, string) -> double 498 499 Returns the information about the travel time of edge "edgeID" valid 500 for the given time from the vehicle's internal edge weights 501 container (see setAdaptedTraveltime). 502 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 503 """ 504 return self._getUniversal(tc.VAR_EDGE_TRAVELTIME, vehID, "tds", 2, time, edgeID)
getAdaptedTraveltime(string, double, string) -> double
Returns the information about the travel time of edge "edgeID" valid for the given time from the vehicle's internal edge weights container (see setAdaptedTraveltime). If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned.
506 def getEffort(self, vehID, time, edgeID): 507 """getEffort(string, double, string) -> double 508 509 Returns the information about the effort needed for edge "edgeID" valid 510 for the given time from the vehicle's internal effort 511 container (see setEffort). 512 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 513 """ 514 return self._getUniversal(tc.VAR_EDGE_EFFORT, vehID, "tds", 2, time, edgeID)
getEffort(string, double, string) -> double
Returns the information about the effort needed for edge "edgeID" valid for the given time from the vehicle's internal effort container (see setEffort). If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned.
516 def isRouteValid(self, vehID): 517 """isRouteValid(string) -> bool 518 Returns whether the current vehicle route is connected for the vehicle 519 class of the given vehicle. 520 """ 521 return self._getUniversal(tc.VAR_ROUTE_VALID, vehID)
isRouteValid(string) -> bool Returns whether the current vehicle route is connected for the vehicle class of the given vehicle.
523 def getSignals(self, vehID): 524 """getSignals(string) -> integer 525 526 Returns an integer encoding the state of a vehicle's signals. 527 """ 528 return self._getUniversal(tc.VAR_SIGNALS, vehID)
getSignals(string) -> integer
Returns an integer encoding the state of a vehicle's signals.
530 def getLateralLanePosition(self, vehID): 531 """getLateralLanePosition(string) -> double 532 533 Returns the lateral position of the vehicle on its current lane measured in m. 534 """ 535 return self._getUniversal(tc.VAR_LANEPOSITION_LAT, vehID)
getLateralLanePosition(string) -> double
Returns the lateral position of the vehicle on its current lane measured in m.
537 def getAllowedSpeed(self, vehID): 538 """getAllowedSpeed(string) -> double 539 540 Returns the maximum allowed speed on the current lane regarding speed factor in m/s for this vehicle. 541 """ 542 return self._getUniversal(tc.VAR_ALLOWED_SPEED, vehID)
getAllowedSpeed(string) -> double
Returns the maximum allowed speed on the current lane regarding speed factor in m/s for this vehicle.
544 def getWaitingTime(self, vehID): 545 """getWaitingTime(string) -> double 546 The waiting time of a vehicle is defined as the time (in seconds) spent with a 547 speed below 0.1m/s since the last time it was faster than 0.1m/s. 548 (basically, the waiting time of a vehicle is reset to 0 every time it moves). 549 A vehicle that is stopping intentionally with a <stop> does not accumulate waiting time. 550 """ 551 return self._getUniversal(tc.VAR_WAITING_TIME, vehID)
getWaitingTime(string) -> double
The waiting time of a vehicle is defined as the time (in seconds) spent with a
speed below 0.1m/s since the last time it was faster than 0.1m/s.
(basically, the waiting time of a vehicle is reset to 0 every time it moves).
A vehicle that is stopping intentionally with a
553 def getAccumulatedWaitingTime(self, vehID): 554 """getAccumulatedWaitingTime(string) -> double 555 The accumulated waiting time of a vehicle collects the vehicle's waiting time 556 over a certain time interval (interval length is set per option '--waiting-time-memory') 557 """ 558 return self._getUniversal(tc.VAR_ACCUMULATED_WAITING_TIME, vehID)
getAccumulatedWaitingTime(string) -> double The accumulated waiting time of a vehicle collects the vehicle's waiting time over a certain time interval (interval length is set per option '--waiting-time-memory')
560 def getLaneChangeMode(self, vehID): 561 """getLaneChangeMode(string) -> integer 562 563 Gets the vehicle's lane change mode as a bitset. 564 """ 565 return self._getUniversal(tc.VAR_LANECHANGE_MODE, vehID)
getLaneChangeMode(string) -> integer
Gets the vehicle's lane change mode as a bitset.
567 def getSpeedMode(self, vehID): 568 """getSpeedMode(string) -> int 569 The speed mode of a vehicle 570 """ 571 return self._getUniversal(tc.VAR_SPEEDSETMODE, vehID)
getSpeedMode(string) -> int The speed mode of a vehicle
573 def getSlope(self, vehID): 574 """getSlope(string) -> double 575 The slope at the current position of the vehicle in degrees 576 """ 577 return self._getUniversal(tc.VAR_SLOPE, vehID)
getSlope(string) -> double The slope at the current position of the vehicle in degrees
579 def getLine(self, vehID): 580 """getLine(string) -> string 581 582 Returns the line information of this vehicle. 583 """ 584 return self._getUniversal(tc.VAR_LINE, vehID)
getLine(string) -> string
Returns the line information of this vehicle.
586 def getVia(self, vehID): 587 """getVia(string) -> tuple(string) 588 589 Returns the ids of via edges for this vehicle 590 """ 591 return self._getUniversal(tc.VAR_VIA, vehID)
getVia(string) -> tuple(string)
Returns the ids of via edges for this vehicle
593 def getLastActionTime(self, vehID): 594 """getLastActionTime(string) -> double 595 596 Returns the time in s of last action point for this vehicle. 597 """ 598 return self._getUniversal(tc.VAR_LASTACTIONTIME, vehID)
getLastActionTime(string) -> double
Returns the time in s of last action point for this vehicle.
600 def getBestLanes(self, vehID): 601 """getBestLanes(string) -> tuple(data) 602 where data is a tuple of (laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes)) 603 604 For each lane of the current edge a data tuple is returned where the 605 entries have the following meaning: 606 - laneID: the id of that lane on the current edge 607 - the length that can be driven without lane change (measured from the start of that lane) 608 - the occupation on the future lanes (brutto vehicle lengths) 609 - the offset of that lane from the lane that would be strategically 610 preferred (this is the lane that requires the least future lane 611 changes or a lane that needs to be used for stopping) 612 - whether that lane allows continuing the route (for at least one more edge) 613 - the sequence of lanes that would be driven starting at laneID if no 614 lane change were to take place 615 """ 616 return self._getUniversal(tc.VAR_BEST_LANES, vehID)
getBestLanes(string) -> tuple(data) where data is a tuple of (laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes))
For each lane of the current edge a data tuple is returned where the entries have the following meaning:
- laneID: the id of that lane on the current edge
- the length that can be driven without lane change (measured from the start of that lane)
- the occupation on the future lanes (brutto vehicle lengths)
- the offset of that lane from the lane that would be strategically preferred (this is the lane that requires the least future lane changes or a lane that needs to be used for stopping)
- whether that lane allows continuing the route (for at least one more edge)
- the sequence of lanes that would be driven starting at laneID if no lane change were to take place
618 def getLeader(self, vehID, dist=100.): 619 """getLeader(string, double) -> (string, double) 620 621 Return the leading vehicle id together with the distance. The distance 622 is measured from the front + minGap to the back of the leader, so it does not include the 623 minGap of the vehicle. 624 The dist parameter defines the minimum lookahead, 0 calculates a lookahead from the brake gap. 625 Note that the returned leader may be further away than the given dist and that the vehicle 626 will only look on its current best lanes and not look beyond the end of its final route edge. 627 628 In the case where no leader is found, the function returns 'None'. 629 This special case is deprecated. The future behavior is to return the 630 pair ("", -1) when no leader is found. 631 The function 'traci.setLegacyGetLeader(bool) can be used to switch 632 between both behaviors. 633 """ 634 return self._getUniversal(tc.VAR_LEADER, vehID, "d", dist)
getLeader(string, double) -> (string, double)
Return the leading vehicle id together with the distance. The distance is measured from the front + minGap to the back of the leader, so it does not include the minGap of the vehicle. The dist parameter defines the minimum lookahead, 0 calculates a lookahead from the brake gap. Note that the returned leader may be further away than the given dist and that the vehicle will only look on its current best lanes and not look beyond the end of its final route edge.
In the case where no leader is found, the function returns 'None'. This special case is deprecated. The future behavior is to return the pair ("", -1) when no leader is found. The function 'traci.setLegacyGetLeader(bool) can be used to switch between both behaviors.
636 def getFollower(self, vehID, dist=0.): 637 """getFollower(string, double) -> (string, double) 638 639 Return the following vehicle id together with the distance. The distance 640 is measured from the front + minGap of the follower to the back of vehID, so it does not include the 641 minGap of the follower. 642 The dist parameter defines the minimum lookback, 0 calculates the 643 lookback distance from the braking distance at 4.5m/s^2 at 2*roadSpeedLimit. 644 Due to junctions and lane merges, there may be multiple followers. 645 In this case, the "critical" follower is returned. This is the follower 646 where the value of (getSecureGap - gap) is maximal. 647 Note that the returned follower may be further away than the given dist. 648 """ 649 return self._getUniversal(tc.VAR_FOLLOWER, vehID, "d", dist)
getFollower(string, double) -> (string, double)
Return the following vehicle id together with the distance. The distance is measured from the front + minGap of the follower to the back of vehID, so it does not include the minGap of the follower. The dist parameter defines the minimum lookback, 0 calculates the lookback distance from the braking distance at 4.5m/s^2 at 2*roadSpeedLimit. Due to junctions and lane merges, there may be multiple followers. In this case, the "critical" follower is returned. This is the follower where the value of (getSecureGap - gap) is maximal. Note that the returned follower may be further away than the given dist.
651 def getRightFollowers(self, vehID, blockingOnly=False): 652 """ getRightFollowers(string, bool) -> tuple(tuple(string, double)) 653 Convenience method, see getNeighbors() 654 """ 655 if blockingOnly: 656 mode = 5 657 else: 658 mode = 1 659 return self.getNeighbors(vehID, mode)
getRightFollowers(string, bool) -> tuple(tuple(string, double)) Convenience method, see getNeighbors()
661 def getRightLeaders(self, vehID, blockingOnly=False): 662 """ getRightLeaders(string, bool) -> tuple(tuple(string, double)) 663 Convenience method, see getNeighbors() 664 """ 665 if blockingOnly: 666 mode = 7 667 else: 668 mode = 3 669 return self.getNeighbors(vehID, mode)
getRightLeaders(string, bool) -> tuple(tuple(string, double)) Convenience method, see getNeighbors()
671 def getLeftFollowers(self, vehID, blockingOnly=False): 672 """ getLeftFollowers(string, bool) -> tuple(tuple(string, double)) 673 Convenience method, see getNeighbors() 674 """ 675 if blockingOnly: 676 mode = 4 677 else: 678 mode = 0 679 return self.getNeighbors(vehID, mode)
getLeftFollowers(string, bool) -> tuple(tuple(string, double)) Convenience method, see getNeighbors()
681 def getLeftLeaders(self, vehID, blockingOnly=False): 682 """ getLeftLeaders(string, bool) -> tuple(tuple(string, double)) 683 Convenience method, see getNeighbors() 684 """ 685 if blockingOnly: 686 mode = 6 687 else: 688 mode = 2 689 return self.getNeighbors(vehID, mode)
getLeftLeaders(string, bool) -> tuple(tuple(string, double)) Convenience method, see getNeighbors()
691 def getNeighbors(self, vehID, mode): 692 """ getNeighbors(string, byte) -> tuple(tuple(string, double)) 693 694 The parameter mode is a bitset (UBYTE), specifying the following: 695 bit 1: query lateral direction (left:0, right:1) 696 bit 2: query longitudinal direction (followers:0, leaders:1) 697 bit 3: blocking (return all:0, return only blockers:1) 698 699 The returned tuple contains pairs (ID, dist) for all lane change relevant neighboring leaders, resp. followers, 700 along with their longitudinal distance to the ego vehicle (egoFront - egoMinGap to leaderBack, resp. 701 followerFront - followerMinGap to egoBack. The value can be negative for overlapping neighs). 702 For the non-sublane case, the lists will contain at most one entry. 703 704 Note: The exact set of blockers in case blocking==1 is not determined for the sublane model, 705 but either all neighboring vehicles are returned (in case LCA_BLOCKED) or 706 none is returned (in case !LCA_BLOCKED). 707 """ 708 return self._getUniversal(tc.VAR_NEIGHBORS, vehID, "B", mode)
getNeighbors(string, byte) -> tuple(tuple(string, double))
The parameter mode is a bitset (UBYTE), specifying the following: bit 1: query lateral direction (left:0, right:1) bit 2: query longitudinal direction (followers:0, leaders:1) bit 3: blocking (return all:0, return only blockers:1)
The returned tuple contains pairs (ID, dist) for all lane change relevant neighboring leaders, resp. followers, along with their longitudinal distance to the ego vehicle (egoFront - egoMinGap to leaderBack, resp. followerFront - followerMinGap to egoBack. The value can be negative for overlapping neighs). For the non-sublane case, the lists will contain at most one entry.
Note: The exact set of blockers in case blocking==1 is not determined for the sublane model, but either all neighboring vehicles are returned (in case LCA_BLOCKED) or none is returned (in case !LCA_BLOCKED).
710 def getFollowSpeed(self, vehID, speed, gap, leaderSpeed, leaderMaxDecel, leaderID=""): 711 """getFollowSpeed(string, double, double, double, double, string) -> double 712 Return the follow speed computed by the carFollowModel of vehID 713 """ 714 return self._getUniversal(tc.VAR_FOLLOW_SPEED, vehID, "tdddds", 5, 715 speed, gap, leaderSpeed, leaderMaxDecel, leaderID)
getFollowSpeed(string, double, double, double, double, string) -> double Return the follow speed computed by the carFollowModel of vehID
717 def getSecureGap(self, vehID, speed, leaderSpeed, leaderMaxDecel, leaderID=""): 718 """getSecureGap(string, double, double, double, string) -> double 719 Return the secure gap computed by the carFollowModel of vehID 720 """ 721 return self._getUniversal(tc.VAR_SECURE_GAP, vehID, "tddds", 4, 722 speed, leaderSpeed, leaderMaxDecel, leaderID)
getSecureGap(string, double, double, double, string) -> double Return the secure gap computed by the carFollowModel of vehID
724 def getStopSpeed(self, vehID, speed, gap): 725 """getStopSpeed(string, double, double) -> double 726 Return the speed for stopping at gap computed by the carFollowModel of vehID 727 """ 728 return self._getUniversal(tc.VAR_STOP_SPEED, vehID, "tdd", 2, speed, gap)
getStopSpeed(string, double, double) -> double Return the speed for stopping at gap computed by the carFollowModel of vehID
730 def getStopDelay(self, vehID): 731 """getStopDelay(string) -> double 732 Returns the expected depart delay at the next stop (if that stop defines the 733 until-attribute) in seconds. Returns -1 if the next stop is not applicable 734 """ 735 return self._getUniversal(tc.VAR_STOP_DELAY, vehID)
getStopDelay(string) -> double Returns the expected depart delay at the next stop (if that stop defines the until-attribute) in seconds. Returns -1 if the next stop is not applicable
737 def getStopArrivalDelay(self, vehID): 738 """getStopArrivalDelay(string) -> double 739 Returns the expected arrival delay at the next stop (if that stop defines the 740 arrival-attribute) in seconds. The returned value may be negative to 741 indicate early arrival. Returns INVALID_DOUBLE if the next stop is not applicable 742 """ 743 return self._getUniversal(tc.VAR_STOP_ARRIVALDELAY, vehID)
getStopArrivalDelay(string) -> double Returns the expected arrival delay at the next stop (if that stop defines the arrival-attribute) in seconds. The returned value may be negative to indicate early arrival. Returns INVALID_DOUBLE if the next stop is not applicable
745 def getTimeLoss(self, vehID): 746 """getTimeLoss(string) -> double 747 Returns the time loss since departure 748 """ 749 return self._getUniversal(tc.VAR_TIMELOSS, vehID)
getTimeLoss(string) -> double Returns the time loss since departure
751 def getNextTLS(self, vehID): 752 """getNextTLS(string) -> tuple(tuple(string, int, double, string)) 753 754 Return tuple of upcoming traffic lights [(tlsID, tlsIndex, distance, state), ...] 755 """ 756 return self._getUniversal(tc.VAR_NEXT_TLS, vehID)
getNextTLS(string) -> tuple(tuple(string, int, double, string))
Return tuple of upcoming traffic lights [(tlsID, tlsIndex, distance, state), ...]
758 @alias_param("dist", "distance") 759 def getJunctionFoes(self, vehID, dist=0.): 760 """getJunctionFoes(string, double) -> complex 761 762 Return tuple of junction foes [(foeId, egoDist, foeDist, egoExitDist, foeExitDist, 763 egoLane, foeLane, egoResponse, foeResponse), ...] within the given distance to the given vehicle. 764 """ 765 return self._getUniversal(tc.VAR_FOES, vehID, "d", dist)
getJunctionFoes(string, double) -> complex
Return tuple of junction foes [(foeId, egoDist, foeDist, egoExitDist, foeExitDist, egoLane, foeLane, egoResponse, foeResponse), ...] within the given distance to the given vehicle.
767 @deprecated() 768 def getNextStops(self, vehID): 769 """getNextStops(string) -> tuple(tuple(string, double, string, int, double, double)) 770 771 Return tuple of upcoming stops ((lane, endPos, stoppingPlaceID, stopFlags, duration, until), ...) 772 where integer stopFlag is defined as: 773 1 * stopped + 774 2 * parking + 775 4 * personTriggered + 776 8 * containerTriggered + 777 16 * isBusStop + 778 32 * isContainerStop + 779 64 * chargingStation + 780 128 * parkingarea 781 with each of these flags defined as 0 or 1. 782 """ 783 return self._getUniversal(tc.VAR_NEXT_STOPS, vehID)
getNextStops(string) -> tuple(tuple(string, double, string, int, double, double))
Return tuple of upcoming stops ((lane, endPos, stoppingPlaceID, stopFlags, duration, until), ...) where integer stopFlag is defined as: 1 * stopped + 2 * parking + 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop + 32 * isContainerStop + 64 * chargingStation + 128 * parkingarea with each of these flags defined as 0 or 1.
785 def getNextLinks(self, vehID): 786 """getNextLinks(string) -> tuple(tuple(string, string, bool, bool, bool, string, string, double)) 787 788 Return tuple of upcoming links along the route ((lane, via, priority, opened, foe, 789 state, direction, length), ...) 790 """ 791 return self._getUniversal(tc.VAR_NEXT_LINKS, vehID)
getNextLinks(string) -> tuple(tuple(string, string, bool, bool, bool, string, string, double))
Return tuple of upcoming links along the route ((lane, via, priority, opened, foe, state, direction, length), ...)
793 def getStops(self, vehID, limit=0): 794 """getStops(string, int) -> tuple(StopData) 795 796 Return a tuple of StopData object. The flags are the same as for setStop and 797 replaceStop (and different from getNextStops(!) for backward compatibility): 798 1 * parking + 799 2 * personTriggered + 800 4 * containerTriggered + 801 8 * isBusStop + 802 16 * isContainerStop + 803 32 * chargingStation + 804 64 * parkingarea 805 with each of these flags defined as 0 or 1. 806 807 The optional argument limit can be used to limit the returned stops to 808 the next INT number (i.e. limit=1 if only the next stop is required). 809 Setting a negative limit returns up to 'limit' previous stops (or fewer 810 if the vehicle stopped fewer times previously) 811 """ 812 return self._getUniversal(tc.VAR_NEXT_STOPS2, vehID, "i", limit)
getStops(string, int) -> tuple(StopData)
Return a tuple of StopData object. The flags are the same as for setStop and replaceStop (and different from getNextStops(!) for backward compatibility): 1 * parking + 2 * personTriggered + 4 * containerTriggered + 8 * isBusStop + 16 * isContainerStop + 32 * chargingStation + 64 * parkingarea with each of these flags defined as 0 or 1.
The optional argument limit can be used to limit the returned stops to the next INT number (i.e. limit=1 if only the next stop is required). Setting a negative limit returns up to 'limit' previous stops (or fewer if the vehicle stopped fewer times previously)
814 def subscribeLeader(self, vehID, dist=0., begin=0, end=2**31 - 1): 815 """subscribeLeader(string, double, double, double) -> None 816 817 Subscribe for the leading vehicle id together with the distance. 818 The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap. 819 """ 820 self.subscribe(vehID, (tc.VAR_LEADER,), begin, end, {tc.VAR_LEADER: ("d", dist)})
subscribeLeader(string, double, double, double) -> None
Subscribe for the leading vehicle id together with the distance. The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap.
822 def getDrivingDistance(self, vehID, edgeID, pos, laneIndex=0): 823 """getDrivingDistance(string, string, double, integer) -> double 824 825 For an edge along the remaining route of vehID, return the distance from the current vehicle position 826 to the given edge and position along the vehicles route. 827 Otherwise, return INVALID_DOUBLE_VALUE 828 """ 829 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tru", 2, 830 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST)
getDrivingDistance(string, string, double, integer) -> double
For an edge along the remaining route of vehID, return the distance from the current vehicle position to the given edge and position along the vehicles route. Otherwise, return INVALID_DOUBLE_VALUE
832 def getDrivingDistance2D(self, vehID, x, y): 833 """getDrivingDistance2D(string, double, double) -> integer 834 835 Return the distance to the given network position along the vehicles route. 836 """ 837 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST)
getDrivingDistance2D(string, double, double) -> integer
Return the distance to the given network position along the vehicles route.
839 def getDistance(self, vehID): 840 """getDistance(string) -> double 841 842 Returns the distance to the starting point like an odometer. 843 """ 844 return self._getUniversal(tc.VAR_DISTANCE, vehID)
getDistance(string) -> double
Returns the distance to the starting point like an odometer.
846 def getReferenceDistance(self, vehID): 847 """getReferenceDistance(string) -> double 848 Returns the distance along the linear reference system 849 in which the current edge takes part (i.e. kilometrage/mile markers) 850 """ 851 return self._getUniversal(tc.VAR_REFERENCE_DISTANCE, vehID)
getReferenceDistance(string) -> double Returns the distance along the linear reference system in which the current edge takes part (i.e. kilometrage/mile markers)
853 def getStopParameter(self, vehID, nextStopIndex, param, customParam=False): 854 """getStopParameter(string, int, string) -> string 855 Gets the value of the given parameter for the stop at the given index 856 Negative indices permit access to past stops. 857 Supported params correspond to all legal stop xml-attributes 858 If customParam is set to True, the user defined stop parameter with the 859 specified param name will be returned instead (or "" if undefined) 860 """ 861 return self._getUniversal(tc.VAR_STOP_PARAMETER, vehID, "tisb", 3, nextStopIndex, param, customParam)
getStopParameter(string, int, string) -> string Gets the value of the given parameter for the stop at the given index Negative indices permit access to past stops. Supported params correspond to all legal stop xml-attributes If customParam is set to True, the user defined stop parameter with the specified param name will be returned instead (or "" if undefined)
863 def getStopState(self, vehID): 864 """getStopState(string) -> integer 865 866 Returns information in regard to stopping: 867 The returned integer is defined as 1 * stopped + 2 * parking 868 + 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop 869 + 32 * isContainerStop 870 with each of these flags defined as 0 or 1 871 """ 872 return self._getUniversal(tc.VAR_STOPSTATE, vehID)
getStopState(string) -> integer
Returns information in regard to stopping: The returned integer is defined as 1 * stopped + 2 * parking
- 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop
- 32 * isContainerStop with each of these flags defined as 0 or 1
874 def isStopped(self, vehID): 875 """isStopped(string) -> bool 876 Return whether the vehicle is stopped 877 """ 878 return (self.getStopState(vehID) & 1) == 1
isStopped(string) -> bool Return whether the vehicle is stopped
880 def isStoppedParking(self, vehID): 881 """isStoppedParking(string) -> bool 882 Return whether the vehicle is parking (implies stopped) 883 """ 884 return (self.getStopState(vehID) & 2) == 2
isStoppedParking(string) -> bool Return whether the vehicle is parking (implies stopped)
886 def isStoppedTriggered(self, vehID): 887 """isStoppedTriggered(string) -> bool 888 Return whether the vehicle is stopped and waiting for a person or container 889 """ 890 return (self.getStopState(vehID) & 12) > 0
isStoppedTriggered(string) -> bool Return whether the vehicle is stopped and waiting for a person or container
892 def isAtBusStop(self, vehID): 893 """isAtBusStop(string) -> bool 894 Return whether the vehicle is stopped at a bus stop 895 """ 896 return (self.getStopState(vehID) & 16) == 16
isAtBusStop(string) -> bool Return whether the vehicle is stopped at a bus stop
898 def isAtContainerStop(self, vehID): 899 """isAtContainerStop(string) -> bool 900 Return whether the vehicle is stopped at a container stop 901 """ 902 return (self.getStopState(vehID) & 32) == 32
isAtContainerStop(string) -> bool Return whether the vehicle is stopped at a container stop
904 def getLaneChangeState(self, vehID, direction): 905 """getLaneChangeState(string, int) -> (int, int) 906 Return the lane change state for the vehicle. The first value returns 907 the state as computed by the lane change model and the second value 908 returns the state after incorporation TraCI requests. 909 See getLaneChangeStatePretty for an interpretation of the integer/bitset 910 results 911 """ 912 return self._getUniversal(tc.CMD_CHANGELANE, vehID, "i", direction)
getLaneChangeState(string, int) -> (int, int) Return the lane change state for the vehicle. The first value returns the state as computed by the lane change model and the second value returns the state after incorporation TraCI requests. See getLaneChangeStatePretty for an interpretation of the integer/bitset results
914 def getLaneChangeStatePretty(self, vehID, direction): 915 """getLaneChangeStatePretty(string, int) -> ([string, ...], [string, ...]) 916 Return the lane change state for the vehicle as two lists of string 917 constants. The first tuple returns the state as computed by the lane change 918 model and the second tuple returns the state after incorporation TraCI requests. 919 """ 920 constants = { 921 0: 'stay', 922 1: 'left', 923 2: 'right', 924 3: 'strategic', 925 4: 'cooperative', 926 5: 'speedGain', 927 6: 'keepRight', 928 7: 'TraCI', 929 8: 'urgent', 930 9: 'blocked by left leader', 931 10: 'blocked by left follower', 932 11: 'blocked by right leader', 933 12: 'blocked by right follower', 934 13: 'overlapping', 935 14: 'insufficient space', 936 15: 'sublane', 937 } 938 939 def prettifyBitstring(intval): 940 return tuple([v for k, v in constants.items() if (intval & 2**k)]) 941 942 state, stateTraCI = self.getLaneChangeState(vehID, direction) 943 return prettifyBitstring(state), prettifyBitstring(stateTraCI)
getLaneChangeStatePretty(string, int) -> ([string, ...], [string, ...]) Return the lane change state for the vehicle as two lists of string constants. The first tuple returns the state as computed by the lane change model and the second tuple returns the state after incorporation TraCI requests.
945 def couldChangeLane(self, vehID, direction, state=None): 946 """couldChangeLane(string, int) -> bool 947 Return whether the vehicle could change lanes in the specified direction. 948 This reflects the state after the last try to change lanes. 949 If you want to execute changeLane as a result of the evaluation of this function 950 it is not guaranteed to work because vehicle movements occur first. 951 """ 952 if state is None: 953 state, stateTraCI = self.getLaneChangeState(vehID, direction) 954 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 955 # vehicle changed in the last step. state is no longer applicable 956 return False 957 return state != tc.LCA_UNKNOWN and (state & tc.LCA_BLOCKED == 0)
couldChangeLane(string, int) -> bool Return whether the vehicle could change lanes in the specified direction. This reflects the state after the last try to change lanes. If you want to execute changeLane as a result of the evaluation of this function it is not guaranteed to work because vehicle movements occur first.
959 def wantsAndCouldChangeLane(self, vehID, direction, state=None): 960 """wantsAndCouldChangeLane(string, int) -> bool 961 Return whether the vehicle wants to and could change lanes in the specified direction 962 This reflects the state after the last try to change lanes. 963 If you want to execute changeLane as a result of the evaluation of this function 964 it is not guaranteed to work because vehicle movements occur first. 965 """ 966 if state is None: 967 state, stateTraCI = self.getLaneChangeState(vehID, direction) 968 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 969 # vehicle changed in the last step. state is no longer applicable 970 return False 971 if state & tc.LCA_BLOCKED == 0: 972 if direction == -1: 973 return state & tc.LCA_RIGHT != 0 974 if direction == 1: 975 return state & tc.LCA_LEFT != 0 976 return False
wantsAndCouldChangeLane(string, int) -> bool Return whether the vehicle wants to and could change lanes in the specified direction This reflects the state after the last try to change lanes. If you want to execute changeLane as a result of the evaluation of this function it is not guaranteed to work because vehicle movements occur first.
978 def getRoutingMode(self, vehID): 979 """getRoutingMode(string) 980 returns the current routing mode: 981 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 982 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 983 """ 984 return self._getUniversal(tc.VAR_ROUTING_MODE, vehID)
getRoutingMode(string) returns the current routing mode: tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting
986 @alias_param("taxiState", "flag") 987 def getTaxiFleet(self, taxiState=0): 988 """getTaxiFleet(int) -> tuple(string) 989 Return the tuple of all taxis with the given taxiState: 990 0 : empty 991 1 : pickup 992 2 : occupied 993 """ 994 return self._getUniversal(tc.VAR_TAXI_FLEET, "", "i", taxiState)
getTaxiFleet(int) -> tuple(string) Return the tuple of all taxis with the given taxiState: 0 : empty 1 : pickup 2 : occupied
996 def getLoadedIDList(self): 997 """getLoadedIDList() -> tuple(string) 998 returns all loaded vehicles that have not yet left the simulation 999 """ 1000 return self._getUniversal(tc.VAR_LOADED_LIST, "")
getLoadedIDList() -> tuple(string) returns all loaded vehicles that have not yet left the simulation
1002 def getTeleportingIDList(self): 1003 """getTeleportingIDList() -> tuple(string) 1004 returns all teleporting or jumping vehicles 1005 """ 1006 return self._getUniversal(tc.VAR_TELEPORTING_LIST, "")
getTeleportingIDList() -> tuple(string) returns all teleporting or jumping vehicles
1008 def rerouteParkingArea(self, vehID, parkingAreaID): 1009 """rerouteParkingArea(string, string) 1010 1011 Changes the next parking area in parkingAreaID, updates the vehicle route, 1012 and preserve consistency in case of passengers/containers on board. 1013 """ 1014 self._setCmd(tc.CMD_REROUTE_TO_PARKING, vehID, "ts", 1, parkingAreaID)
rerouteParkingArea(string, string)
Changes the next parking area in parkingAreaID, updates the vehicle route, and preserve consistency in case of passengers/containers on board.
1016 def setStop(self, vehID, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1017 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, until=tc.INVALID_DOUBLE_VALUE): 1018 """setStop(string, string, double, integer, double, integer, double, double) -> None 1019 1020 Adds or modifies a stop with the given parameters. The duration and the until attribute are 1021 in seconds. 1022 """ 1023 if type(duration) is int and duration >= 1000 and duration % 1000 == 0: 1024 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1025 self._setCmd(tc.CMD_STOP, vehID, "tsdbdbdd", 7, edgeID, pos, laneIndex, duration, flags, startPos, until)
setStop(string, string, double, integer, double, integer, double, double) -> None
Adds or modifies a stop with the given parameters. The duration and the until attribute are in seconds.
1027 def setBusStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1028 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1029 """setBusStop(string, string, double, double, integer) -> None 1030 1031 Adds or modifies a bus stop with the given parameters. The duration and the until attribute are 1032 in seconds. 1033 """ 1034 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_BUS_STOP)
setBusStop(string, string, double, double, integer) -> None
Adds or modifies a bus stop with the given parameters. The duration and the until attribute are in seconds.
1036 def setContainerStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1037 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1038 """setContainerStop(string, string, double, double, integer) -> None 1039 1040 Adds or modifies a container stop with the given parameters. The duration and the until attribute are 1041 in seconds. 1042 """ 1043 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CONTAINER_STOP)
setContainerStop(string, string, double, double, integer) -> None
Adds or modifies a container stop with the given parameters. The duration and the until attribute are in seconds.
1045 def setChargingStationStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1046 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1047 """setChargingStationStop(string, string, double, double, integer) -> None 1048 1049 Adds or modifies a stop at a chargingStation with the given parameters. The duration and the until attribute are 1050 in seconds. 1051 """ 1052 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CHARGING_STATION)
setChargingStationStop(string, string, double, double, integer) -> None
Adds or modifies a stop at a chargingStation with the given parameters. The duration and the until attribute are in seconds.
1054 def setParkingAreaStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1055 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_PARKING): 1056 """setParkingAreaStop(string, string, double, double, integer) -> None 1057 1058 Adds or modifies a stop at a parkingArea with the given parameters. The duration and the until attribute are 1059 in seconds. 1060 """ 1061 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_PARKING_AREA)
setParkingAreaStop(string, string, double, double, integer) -> None
Adds or modifies a stop at a parkingArea with the given parameters. The duration and the until attribute are in seconds.
1063 def replaceStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1064 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1065 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1066 """replaceStop(string, int, string, double, integer, double, integer, double, double) -> None 1067 1068 Replaces stop at the given index (within the list of all stops) with a new stop. 1069 Automatically modifies the route if the replacement stop is at another location. 1070 For edgeID a stopping place id may be given if the flag marks this 1071 stop as stopping on busStop, parkingArea, containerStop etc. 1072 If edgeID is "", the stop at the given index will be removed without 1073 replacement and the route will not be modified (unless setting 1074 teleport=2 which will trigger rerouting between the prior and next stop) 1075 If teleport is set to 1, the route to the replacement stop will be 1076 disconnected (forcing a teleport). 1077 If stopIndex is 0 the gap will be between the current 1078 edge and the new stop. Otherwise the gap will be between the stop edge for 1079 nextStopIndex - 1 and the new stop. 1080 """ 1081 self._setCmd(tc.CMD_REPLACE_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1082 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport)
replaceStop(string, int, string, double, integer, double, integer, double, double) -> None
Replaces stop at the given index (within the list of all stops) with a new stop. Automatically modifies the route if the replacement stop is at another location. For edgeID a stopping place id may be given if the flag marks this stop as stopping on busStop, parkingArea, containerStop etc. If edgeID is "", the stop at the given index will be removed without replacement and the route will not be modified (unless setting teleport=2 which will trigger rerouting between the prior and next stop) If teleport is set to 1, the route to the replacement stop will be disconnected (forcing a teleport). If stopIndex is 0 the gap will be between the current edge and the new stop. Otherwise the gap will be between the stop edge for nextStopIndex - 1 and the new stop.
1084 def insertStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1085 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1086 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1087 """insertStop(string, int, string, double, integer, double, integer, double, double) -> None 1088 1089 Insert stop at the given index (within the list of all existing stops). 1090 Automatically modifies the route if the new stop is not along the route between the preceeding 1091 and succeeding stops (or start / end). 1092 For edgeID a stopping place id may be given if the flag marks this 1093 stop as stopping on busStop, parkingArea, containerStop etc. 1094 If teleport is set to 1, the route to the new stop will be 1095 disconnected (forcing a teleport). 1096 If stopIndex is 0 the gap will be between the current 1097 edge and the new stop. Otherwise the gap will be between the stop edge for 1098 nextStopIndex - 1 and the new stop. 1099 """ 1100 self._setCmd(tc.CMD_INSERT_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1101 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport)
insertStop(string, int, string, double, integer, double, integer, double, double) -> None
Insert stop at the given index (within the list of all existing stops). Automatically modifies the route if the new stop is not along the route between the preceeding and succeeding stops (or start / end). For edgeID a stopping place id may be given if the flag marks this stop as stopping on busStop, parkingArea, containerStop etc. If teleport is set to 1, the route to the new stop will be disconnected (forcing a teleport). If stopIndex is 0 the gap will be between the current edge and the new stop. Otherwise the gap will be between the stop edge for nextStopIndex - 1 and the new stop.
1103 def setStopParameter(self, vehID, nextStopIndex, param, value, customParam=False): 1104 """setStopParameter(string, int, string, string) -> None 1105 Sets the value of the given parameter for the (upcoming) stop at the 1106 given index (within the list of all stops). 1107 Supported params correspond to (almost) all legal stop xml-attributes 1108 and their value semantics 1109 If customParam is set to True, the user defined stop parameter with the 1110 specified param name will be set instead 1111 """ 1112 self._setCmd(tc.VAR_STOP_PARAMETER, vehID, "tissb", 4, nextStopIndex, param, value, customParam)
setStopParameter(string, int, string, string) -> None Sets the value of the given parameter for the (upcoming) stop at the given index (within the list of all stops). Supported params correspond to (almost) all legal stop xml-attributes and their value semantics If customParam is set to True, the user defined stop parameter with the specified param name will be set instead
1114 def resume(self, vehID): 1115 """resume(string) -> None 1116 1117 Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped). 1118 """ 1119 self._setCmd(tc.CMD_RESUME, vehID, "t", 0)
resume(string) -> None
Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped).
1121 def changeLane(self, vehID, laneIndex, duration): 1122 """changeLane(string, int, double) -> None 1123 Forces a lane change to the lane with the given index; The lane change 1124 will be attempted for the given duration (in s) and if it succeeds, 1125 the vehicle will stay on that lane for the remaining duration. 1126 """ 1127 if type(duration) is int and duration >= 1000: 1128 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1129 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbd", 2, laneIndex, duration)
changeLane(string, int, double) -> None Forces a lane change to the lane with the given index; The lane change will be attempted for the given duration (in s) and if it succeeds, the vehicle will stay on that lane for the remaining duration.
1131 def changeLaneRelative(self, vehID, indexOffset, duration): 1132 """changeLaneRelative(string, int, double) -> None 1133 1134 Forces a relative lane change; if successful, 1135 the lane will be chosen for the given amount of time (in s). 1136 The indexOffset specifies the target lane relative to the vehicles current lane 1137 """ 1138 if type(duration) is int and duration >= 1000: 1139 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1140 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbdb", 3, indexOffset, duration, 1)
changeLaneRelative(string, int, double) -> None
Forces a relative lane change; if successful, the lane will be chosen for the given amount of time (in s). The indexOffset specifies the target lane relative to the vehicles current lane
1142 def changeSublane(self, vehID, latDist): 1143 """changeSublane(string, double) -> None 1144 Forces a lateral change by the given amount (negative values indicate changing to the right, positive 1145 to the left). This will override any other lane change motivations but conform to 1146 safety-constraints as configured by laneChangeMode. 1147 """ 1148 self._setCmd(tc.CMD_CHANGESUBLANE, vehID, "d", latDist)
changeSublane(string, double) -> None Forces a lateral change by the given amount (negative values indicate changing to the right, positive to the left). This will override any other lane change motivations but conform to safety-constraints as configured by laneChangeMode.
1150 def slowDown(self, vehID, speed, duration): 1151 """slowDown(string, double, double) -> None 1152 1153 Changes the speed smoothly to the given value over the given amount 1154 of time in seconds (can also be used to increase speed). 1155 """ 1156 if type(duration) is int and duration >= 1000: 1157 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1158 self._setCmd(tc.CMD_SLOWDOWN, vehID, "tdd", 2, speed, duration)
slowDown(string, double, double) -> None
Changes the speed smoothly to the given value over the given amount of time in seconds (can also be used to increase speed).
1160 def openGap(self, vehID, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel=-1, referenceVehID=None): 1161 """openGap(string, double, double, double, double, double, string) -> None 1162 1163 Changes the vehicle's desired time headway (cf-parameter tau) smoothly to the given new value 1164 using the given change rate. Similarly, the given space headway is applied gradually 1165 to achieve a minimal spatial gap. 1166 The vehicle is commanded to keep the increased headway for 1167 the given duration once its target value is attained. The maximal value for the 1168 deceleration can be given to prevent harsh braking due to the change of tau. If maxDecel=-1, 1169 the limit determined by the CF model is used. 1170 A vehicle ID for a reference vehicle can optionally be given, otherwise, the gap is created with 1171 respect to the current leader on the ego vehicle's current lane. 1172 Note that this does only affect the following behavior regarding the current leader and does 1173 not influence the gap acceptance during lane change, etc. 1174 """ 1175 if type(duration) is int and duration >= 1000: 1176 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1177 if referenceVehID is None: 1178 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddd", 5, 1179 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel) 1180 else: 1181 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddds", 6, 1182 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, referenceVehID)
openGap(string, double, double, double, double, double, string) -> None
Changes the vehicle's desired time headway (cf-parameter tau) smoothly to the given new value using the given change rate. Similarly, the given space headway is applied gradually to achieve a minimal spatial gap. The vehicle is commanded to keep the increased headway for the given duration once its target value is attained. The maximal value for the deceleration can be given to prevent harsh braking due to the change of tau. If maxDecel=-1, the limit determined by the CF model is used. A vehicle ID for a reference vehicle can optionally be given, otherwise, the gap is created with respect to the current leader on the ego vehicle's current lane. Note that this does only affect the following behavior regarding the current leader and does not influence the gap acceptance during lane change, etc.
1184 def deactivateGapControl(self, vehID): 1185 """deactivateGapControl(string) -> None 1186 1187 Deactivate the vehicle's gap control 1188 """ 1189 self.openGap(vehID, -1, -1, -1, -1)
deactivateGapControl(string) -> None
Deactivate the vehicle's gap control
1191 def requestToC(self, vehID, leadTime): 1192 """ requestToC(string, double) -> None 1193 1194 Interface for triggering a transition of control for a vehicle equipped with a ToC device. 1195 """ 1196 self.setParameter(vehID, "device.toc.requestToC", str(leadTime))
requestToC(string, double) -> None
Interface for triggering a transition of control for a vehicle equipped with a ToC device.
1198 def changeTarget(self, vehID, edgeID): 1199 """changeTarget(string, string) -> None 1200 1201 The vehicle's destination edge is set to the given edge id. The route is rebuilt. 1202 """ 1203 self._setCmd(tc.CMD_CHANGETARGET, vehID, "s", edgeID)
changeTarget(string, string) -> None
The vehicle's destination edge is set to the given edge id. The route is rebuilt.
1205 def setType(self, vehID, typeID): 1206 """setType(string, string) -> None 1207 1208 Sets the id of the type for the named vehicle. 1209 """ 1210 self._setCmd(tc.VAR_TYPE, vehID, "s", typeID)
setType(string, string) -> None
Sets the id of the type for the named vehicle.
1212 def setRouteID(self, vehID, routeID): 1213 """setRouteID(string, string) -> None 1214 1215 Changes the vehicles route to the route with the given id. 1216 """ 1217 self._setCmd(tc.VAR_ROUTE_ID, vehID, "s", routeID)
setRouteID(string, string) -> None
Changes the vehicles route to the route with the given id.
1219 def setRoute(self, vehID, edgeList): 1220 """ 1221 setRoute(string, list) -> None 1222 1223 changes the vehicle route to given edges list. 1224 The first edge in the list has to be the one that the vehicle is at the moment. 1225 1226 example usage: 1227 setRoute('1', ['1', '2', '4', '6', '7']) 1228 1229 this changes route for vehicle id 1 to edges 1-2-4-6-7 1230 """ 1231 if isinstance(edgeList, str): 1232 edgeList = [edgeList] 1233 self._setCmd(tc.VAR_ROUTE, vehID, "l", edgeList)
setRoute(string, list) -> None
changes the vehicle route to given edges list. The first edge in the list has to be the one that the vehicle is at the moment.
example usage: setRoute('1', ['1', '2', '4', '6', '7'])
this changes route for vehicle id 1 to edges 1-2-4-6-7
1235 def setLateralLanePosition(self, vehID, posLat): 1236 """setLateralLanePosition(string, double) -> None 1237 1238 Sets the lateral vehicle position relative to the center line of the 1239 lane in m (negative values are to the right in right-hand networks). 1240 The vehicle may adapt this position in the same step unless this is 1241 disabled via setLaneChangeMode. 1242 """ 1243 self._setCmd(tc.VAR_LANEPOSITION_LAT, vehID, "d", posLat)
setLateralLanePosition(string, double) -> None
Sets the lateral vehicle position relative to the center line of the lane in m (negative values are to the right in right-hand networks). The vehicle may adapt this position in the same step unless this is disabled via setLaneChangeMode.
1245 def updateBestLanes(self, vehID): 1246 """ updateBestLanes(string) -> None 1247 Triggers an update of the vehicle's bestLanes (structure determining the lane preferences used by LC models) 1248 It may be called after modifying the vClass for instance. 1249 """ 1250 self._setCmd(tc.VAR_UPDATE_BESTLANES, vehID)
updateBestLanes(string) -> None Triggers an update of the vehicle's bestLanes (structure determining the lane preferences used by LC models) It may be called after modifying the vClass for instance.
1252 def setAdaptedTraveltime(self, vehID, edgeID, time=None, begTime=None, endTime=None): 1253 """setAdaptedTraveltime(string, string, double, double, double) -> None 1254 Inserts the information about the travel time of edge "edgeID" valid 1255 from begin time to end time into the vehicle's internal edge weights 1256 container. 1257 If the time is not specified, any previously set values for that edge 1258 are removed. 1259 If begTime or endTime are not specified the value is set for the whole 1260 simulation duration. 1261 """ 1262 if not isinstance(edgeID, str) and isinstance(begTime, str): 1263 # legacy handling 1264 warnings.warn( 1265 "Parameter order has changed for setAdaptedTraveltime(). Attempting legacy ordering. " + 1266 "Please update your code.", stacklevel=2) 1267 return self.setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time) 1268 if time is None: 1269 # reset 1270 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "ts", 1, edgeID) 1271 elif begTime is None: 1272 # set value for the whole simulation 1273 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tsd", 2, edgeID, time) 1274 else: 1275 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tddsd", 4, begTime, endTime, edgeID, time)
setAdaptedTraveltime(string, string, double, double, double) -> None Inserts the information about the travel time of edge "edgeID" valid from begin time to end time into the vehicle's internal edge weights container. If the time is not specified, any previously set values for that edge are removed. If begTime or endTime are not specified the value is set for the whole simulation duration.
1277 def setEffort(self, vehID, edgeID, effort=None, begTime=None, endTime=None): 1278 """setEffort(string, string, double, double, double) -> None 1279 Inserts the information about the effort of edge "edgeID" valid from 1280 begin time to end time into the vehicle's internal edge weights 1281 container. 1282 If the time is not specified, any previously set values for that edge 1283 are removed. 1284 If begTime or endTime are not specified the value is set for the whole 1285 simulation duration. 1286 """ 1287 if not isinstance(edgeID, str) and isinstance(begTime, str): 1288 # legacy handling 1289 warnings.warn( 1290 "Parameter order has changed for setEffort(). Attempting legacy ordering. Please update your code.", 1291 stacklevel=2) 1292 return self.setEffort(vehID, begTime, endTime, edgeID, effort) 1293 if effort is None: 1294 # reset 1295 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "ts", 1, edgeID) 1296 elif begTime is None: 1297 # set value for the whole simulation 1298 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tsd", 2, edgeID, effort) 1299 else: 1300 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tddsd", 4, begTime, endTime, edgeID, effort)
setEffort(string, string, double, double, double) -> None Inserts the information about the effort of edge "edgeID" valid from begin time to end time into the vehicle's internal edge weights container. If the time is not specified, any previously set values for that edge are removed. If begTime or endTime are not specified the value is set for the whole simulation duration.
1304 def setRoutingMode(self, vehID, routingMode): 1305 """setRoutingMode(string, int) -> None 1306 Sets the current routing mode: 1307 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 1308 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 1309 tc.ROUTING_MODE_AGGREGATED_CUSTOM : use weight storages and fall-back to smoothed travel times 1310 """ 1311 self._setCmd(tc.VAR_ROUTING_MODE, vehID, "i", routingMode)
setRoutingMode(string, int) -> None Sets the current routing mode: tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting tc.ROUTING_MODE_AGGREGATED_CUSTOM : use weight storages and fall-back to smoothed travel times
1313 def rerouteTraveltime(self, vehID, currentTravelTimes=True): 1314 """rerouteTraveltime(string, bool) -> None 1315 Reroutes a vehicle. 1316 If currentTravelTimes is True (default) and the routing mode is still ROUTING_MODE_DEFAULT 1317 then the ROUTING_MODE_AGGREGATED_CUSTOM gets activated temporarily 1318 and used for rerouting. The various functions and options for 1319 customizing travel times are described at https://sumo.dlr.de/wiki/Simulation/Routing 1320 1321 When rerouteTraveltime has been called once with an aggregated routing mode, 1322 edge weight storage and update gets activated which might slow down the simulation. 1323 """ 1324 if currentTravelTimes: 1325 routingMode = self.getRoutingMode(vehID) 1326 if routingMode == tc.ROUTING_MODE_DEFAULT: 1327 self.setRoutingMode(vehID, tc.ROUTING_MODE_AGGREGATED_CUSTOM) 1328 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, vehID, "t", 0) 1329 if currentTravelTimes and routingMode == tc.ROUTING_MODE_DEFAULT: 1330 self.setRoutingMode(vehID, routingMode)
rerouteTraveltime(string, bool) -> None Reroutes a vehicle. If currentTravelTimes is True (default) and the routing mode is still ROUTING_MODE_DEFAULT then the ROUTING_MODE_AGGREGATED_CUSTOM gets activated temporarily and used for rerouting. The various functions and options for customizing travel times are described at https://sumo.dlr.de/wiki/Simulation/Routing
When rerouteTraveltime has been called once with an aggregated routing mode, edge weight storage and update gets activated which might slow down the simulation.
1332 def rerouteEffort(self, vehID): 1333 """rerouteEffort(string) -> None 1334 Reroutes a vehicle according to the effort values. 1335 """ 1336 self._setCmd(tc.CMD_REROUTE_EFFORT, vehID, "t", 0)
rerouteEffort(string) -> None Reroutes a vehicle according to the effort values.
1338 def setSignals(self, vehID, signals): 1339 """setSignals(string, integer) -> None 1340 1341 Sets an integer encoding the state of the vehicle's signals. 1342 """ 1343 self._setCmd(tc.VAR_SIGNALS, vehID, "i", signals)
setSignals(string, integer) -> None
Sets an integer encoding the state of the vehicle's signals.
1345 def moveTo(self, vehID, laneID, pos, reason=tc.MOVE_AUTOMATIC): 1346 """moveTo(string, string, double, integer) -> None 1347 1348 Move a vehicle to a new position along its current route. 1349 """ 1350 self._setCmd(tc.VAR_MOVE_TO, vehID, "tsdi", 3, laneID, pos, reason)
moveTo(string, string, double, integer) -> None
Move a vehicle to a new position along its current route.
1352 def setSpeed(self, vehID, speed): 1353 """setSpeed(string, double) -> None 1354 1355 Sets the speed in m/s for the named vehicle within the last step. 1356 Calling with speed=-1 hands the vehicle control back to SUMO. 1357 """ 1358 self._setCmd(tc.VAR_SPEED, vehID, "d", speed)
setSpeed(string, double) -> None
Sets the speed in m/s for the named vehicle within the last step. Calling with speed=-1 hands the vehicle control back to SUMO.
1360 def setAcceleration(self, vehID, acceleration, duration): 1361 """setAcceleration(string, double, double) -> None 1362 1363 Sets the acceleration in m/s^2 for the named vehicle and the given duration. 1364 """ 1365 self._setCmd(tc.VAR_ACCELERATION, vehID, "tdd", 2, acceleration, duration)
setAcceleration(string, double, double) -> None
Sets the acceleration in m/s^2 for the named vehicle and the given duration.
1367 def setPreviousSpeed(self, vehID, speed, acceleration=tc.INVALID_DOUBLE_VALUE): 1368 """setPreviousSpeed(string, double, double) -> None 1369 1370 Sets the previous speed in m/s for the named vehicle wich will be used for 1371 calculations in the current step. Optionally, the acceleration for the 1372 previous step (in m/s^2) can be set as well. 1373 """ 1374 self._setCmd(tc.VAR_PREV_SPEED, vehID, "tdd", 2, speed, acceleration)
setPreviousSpeed(string, double, double) -> None
Sets the previous speed in m/s for the named vehicle wich will be used for calculations in the current step. Optionally, the acceleration for the previous step (in m/s^2) can be set as well.
1376 def setLine(self, vehID, line): 1377 """setLine(string, string) -> None 1378 1379 Sets the line information for this vehicle. 1380 """ 1381 self._setCmd(tc.VAR_LINE, vehID, "s", line)
setLine(string, string) -> None
Sets the line information for this vehicle.
1383 def setVia(self, vehID, edgeList): 1384 """ 1385 setVia(string, list) -> None 1386 1387 changes the via edges to the given edges list (to be used during 1388 subsequent rerouting calls). 1389 1390 Note: a single edgeId as argument is allowed as shorthand for a list of length 1 1391 """ 1392 if isinstance(edgeList, str): 1393 edgeList = [edgeList] 1394 self._setCmd(tc.VAR_VIA, vehID, "l", edgeList)
setVia(string, list) -> None
changes the via edges to the given edges list (to be used during subsequent rerouting calls).
Note: a single edgeId as argument is allowed as shorthand for a list of length 1
1396 def highlight(self, vehID, color=(255, 0, 0, 255), size=-1, alphaMax=-1, duration=-1, type=0): 1397 """ highlight(string, color, float, ubyte, float, ubyte) -> None 1398 Adds a circle of the given color tracking the vehicle. 1399 If a positive size [in m] is given the size of the highlight is chosen accordingly, 1400 otherwise the length of the vehicle is used as reference. 1401 If alphaMax and duration are positive, the circle fades in and out within the given duration, 1402 otherwise it permanently follows the vehicle. 1403 """ 1404 if type > 255: 1405 raise TraCIException("vehicle.highlight(): maximal value for type is 255") 1406 if alphaMax > 255: 1407 raise TraCIException("vehicle.highlight(): maximal value for alphaMax is 255") 1408 if alphaMax <= 0 and duration > 0: 1409 raise TraCIException("vehicle.highlight(): duration>0 requires alphaMax>0") 1410 if alphaMax > 0 and duration <= 0: 1411 raise TraCIException("vehicle.highlight(): alphaMax>0 requires duration>0") 1412 1413 if alphaMax > 0: 1414 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcdBdB", 5, color, size, alphaMax, duration, type) 1415 else: 1416 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcd", 2, color, size)
highlight(string, color, float, ubyte, float, ubyte) -> None Adds a circle of the given color tracking the vehicle. If a positive size [in m] is given the size of the highlight is chosen accordingly, otherwise the length of the vehicle is used as reference. If alphaMax and duration are positive, the circle fades in and out within the given duration, otherwise it permanently follows the vehicle.
1418 @alias_param("laneChangeMode", "lcm") 1419 def setLaneChangeMode(self, vehID, laneChangeMode): 1420 """setLaneChangeMode(string, integer) -> None 1421 1422 Sets the vehicle's lane change mode as a bitset. 1423 """ 1424 self._setCmd(tc.VAR_LANECHANGE_MODE, vehID, "i", laneChangeMode)
setLaneChangeMode(string, integer) -> None
Sets the vehicle's lane change mode as a bitset.
1426 @alias_param("speedMode", "sm") 1427 def setSpeedMode(self, vehID, speedMode): 1428 """setSpeedMode(string, integer) -> None 1429 1430 Sets the vehicle's speed mode as a bitset. 1431 """ 1432 self._setCmd(tc.VAR_SPEEDSETMODE, vehID, "i", speedMode)
setSpeedMode(string, integer) -> None
Sets the vehicle's speed mode as a bitset.
1434 def addLegacy(self, vehID, routeID, depart=tc.DEPARTFLAG_NOW, pos=0, speed=0, 1435 lane=tc.DEPARTFLAG_LANE_FIRST_ALLOWED, typeID="DEFAULT_VEHTYPE"): 1436 """ 1437 Add a new vehicle (old style) 1438 """ 1439 if depart == tc.DEPARTFLAG_NOW: 1440 depart = "now" 1441 elif depart == tc.DEPARTFLAG_TRIGGERED: 1442 depart = "triggered" 1443 else: 1444 depart = str(depart) 1445 if pos < 0: 1446 print("Invalid departure position.") 1447 return 1448 if lane == tc.DEPARTFLAG_LANE_FIRST_ALLOWED: 1449 lane = "first" 1450 elif lane == tc.DEPARTFLAG_LANE_FREE: 1451 lane = "free" 1452 else: 1453 lane = str(lane) 1454 self.addFull(vehID, routeID, typeID, depart, lane, str(pos), str(speed))
Add a new vehicle (old style)
1456 def add(self, vehID, routeID, typeID="DEFAULT_VEHTYPE", depart="now", 1457 departLane="first", departPos="base", departSpeed="0", 1458 arrivalLane="current", arrivalPos="max", arrivalSpeed="current", 1459 fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0): 1460 """ 1461 Add a new vehicle (new style with all possible parameters) 1462 If routeID is "", the vehicle will be inserted on a random network edge 1463 if route consists of two disconnected edges, the vehicle will be treated 1464 like a <trip> and use the fastest route between the two edges. 1465 """ 1466 if depart is None: 1467 # legacy compatibility 1468 depart = str(self._connection.simulation.getTime()) 1469 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii", 14, 1470 routeID, typeID, depart, departLane, departPos, departSpeed, 1471 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, personCapacity, personNumber)
Add a new vehicle (new style with all possible parameters)
If routeID is "", the vehicle will be inserted on a random network edge
if route consists of two disconnected edges, the vehicle will be treated
like a
1456 def add(self, vehID, routeID, typeID="DEFAULT_VEHTYPE", depart="now", 1457 departLane="first", departPos="base", departSpeed="0", 1458 arrivalLane="current", arrivalPos="max", arrivalSpeed="current", 1459 fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0): 1460 """ 1461 Add a new vehicle (new style with all possible parameters) 1462 If routeID is "", the vehicle will be inserted on a random network edge 1463 if route consists of two disconnected edges, the vehicle will be treated 1464 like a <trip> and use the fastest route between the two edges. 1465 """ 1466 if depart is None: 1467 # legacy compatibility 1468 depart = str(self._connection.simulation.getTime()) 1469 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii", 14, 1470 routeID, typeID, depart, departLane, departPos, departSpeed, 1471 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, personCapacity, personNumber)
Add a new vehicle (new style with all possible parameters)
If routeID is "", the vehicle will be inserted on a random network edge
if route consists of two disconnected edges, the vehicle will be treated
like a
1475 def dispatchTaxi(self, vehID, reservations): 1476 """dispatchTaxi(string, list(string)) -> None 1477 dispatches the taxi with the given id to service the given reservations. 1478 If only a single reservation is given, this implies pickup and drop-off 1479 If multiple reservations are given, each reservation id must occur twice 1480 (once for pickup and once for drop-off) and the list encodes ride 1481 sharing of passengers (in pickup and drop-off order) 1482 """ 1483 if isinstance(reservations, str): 1484 reservations = [reservations] 1485 self._setCmd(tc.CMD_TAXI_DISPATCH, vehID, "l", reservations)
dispatchTaxi(string, list(string)) -> None dispatches the taxi with the given id to service the given reservations. If only a single reservation is given, this implies pickup and drop-off If multiple reservations are given, each reservation id must occur twice (once for pickup and once for drop-off) and the list encodes ride sharing of passengers (in pickup and drop-off order)
1487 def remove(self, vehID, reason=tc.REMOVE_VAPORIZED): 1488 '''Remove vehicle with the given ID for the give reason. 1489 Reasons are defined in module constants and start with REMOVE_''' 1490 self._setCmd(tc.REMOVE, vehID, "b", reason)
Remove vehicle with the given ID for the give reason. Reasons are defined in module constants and start with REMOVE_
1492 @alias_param("laneIndex", "lane") 1493 def moveToXY(self, vehID, edgeID, laneIndex, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 1494 '''Place vehicle at the given x,y coordinates and force its angle to 1495 the given value (for drawing). 1496 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 1497 natural angle of the edge on which it is driving. 1498 If keepRoute is set to 1, the closest position 1499 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 1500 any edge in the network but its route then only consists of that edge. 1501 If keepRoute is set to 2 the vehicle has all the freedom of keepRoute=0 1502 but in addition to that may even move outside the road network. 1503 edgeID and lane are optional placement hints to resolve ambiguities. 1504 The command fails if no suitable target position is found within the 1505 distance given by matchThreshold. 1506 ''' 1507 self._setCmd(tc.MOVE_TO_XY, vehID, "tsidddbd", 7, edgeID, laneIndex, x, y, angle, keepRoute, matchThreshold)
Place vehicle at the given x,y coordinates and force its angle to the given value (for drawing). If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the natural angle of the edge on which it is driving. If keepRoute is set to 1, the closest position within the existing route is taken. If keepRoute is set to 0, the vehicle may move to any edge in the network but its route then only consists of that edge. If keepRoute is set to 2 the vehicle has all the freedom of keepRoute=0 but in addition to that may even move outside the road network. edgeID and lane are optional placement hints to resolve ambiguities. The command fails if no suitable target position is found within the distance given by matchThreshold.
1509 def addSubscriptionFilterLanes(self, lanes, noOpposite=False, downstreamDist=None, upstreamDist=None): 1510 """addSubscriptionFilterLanes(list(integer), bool, double, double) -> None 1511 1512 Adds a lane-filter to the last modified vehicle context subscription (call it just after subscribing). 1513 lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.) 1514 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1515 downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net. 1516 """ 1517 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1518 if noOpposite: 1519 self.addSubscriptionFilterNoOpposite() 1520 if downstreamDist is not None: 1521 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1522 if upstreamDist is not None: 1523 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
addSubscriptionFilterLanes(list(integer), bool, double, double) -> None
Adds a lane-filter to the last modified vehicle context subscription (call it just after subscribing). lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.) noOpposite specifies whether vehicles on opposite direction lanes shall be returned downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net.
1525 def addSubscriptionFilterNoOpposite(self): 1526 """addSubscriptionFilterNoOpposite() -> None 1527 1528 Omits vehicles on other edges than the ego's for the last modified vehicle context subscription 1529 (call it just after subscribing). 1530 """ 1531 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_NOOPPOSITE)
addSubscriptionFilterNoOpposite() -> None
Omits vehicles on other edges than the ego's for the last modified vehicle context subscription (call it just after subscribing).
1533 def addSubscriptionFilterDownstreamDistance(self, dist): 1534 """addSubscriptionFilterDownstreamDist(float) -> None 1535 1536 Sets the downstream distance along the network for vehicles to be returned by the last modified 1537 vehicle context subscription (call it just after subscribing). 1538 """ 1539 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_DOWNSTREAM_DIST, dist)
addSubscriptionFilterDownstreamDist(float) -> None
Sets the downstream distance along the network for vehicles to be returned by the last modified vehicle context subscription (call it just after subscribing).
1541 def addSubscriptionFilterUpstreamDistance(self, dist): 1542 """addSubscriptionFilterUpstreamDist(float) -> None 1543 1544 Sets the upstream distance along the network for vehicles to be returned by the last modified 1545 vehicle context subscription (call it just after subscribing). 1546 """ 1547 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_UPSTREAM_DIST, dist)
addSubscriptionFilterUpstreamDist(float) -> None
Sets the upstream distance along the network for vehicles to be returned by the last modified vehicle context subscription (call it just after subscribing).
1549 def addSubscriptionFilterCFManeuver(self, downstreamDist=None, upstreamDist=None): 1550 """addSubscriptionFilterCFManeuver() -> None 1551 1552 Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego. 1553 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1554 """ 1555 self.addSubscriptionFilterLeadFollow([0]) 1556 if downstreamDist is not None: 1557 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1558 if upstreamDist is not None: 1559 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
addSubscriptionFilterCFManeuver() -> None
Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego. downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net.
1561 def addSubscriptionFilterLCManeuver(self, direction=None, noOpposite=False, downstreamDist=None, upstreamDist=None): 1562 """addSubscriptionFilterLCManeuver(int) -> None 1563 1564 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1565 and follower of the ego. 1566 direction - lane change direction (in {-1=right, 1=left}) 1567 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1568 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1569 Combine with: distance filters; vClass/vType filter. 1570 """ 1571 if direction is None: 1572 # Using default: both directions 1573 lanes = [-1, 0, 1] 1574 elif not (direction == -1 or direction == 1): 1575 warnings.warn("Ignoring lane change subscription filter " + 1576 "with non-neighboring lane offset direction=%s." % direction) 1577 return 1578 else: 1579 lanes = [0, direction] 1580 self.addSubscriptionFilterLeadFollow(lanes) 1581 if noOpposite: 1582 self.addSubscriptionFilterNoOpposite() 1583 if downstreamDist is not None: 1584 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1585 if upstreamDist is not None: 1586 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
addSubscriptionFilterLCManeuver(int) -> None
Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader and follower of the ego. direction - lane change direction (in {-1=right, 1=left}) noOpposite specifies whether vehicles on opposite direction lanes shall be returned downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. Combine with: distance filters; vClass/vType filter.
1588 def addSubscriptionFilterLeadFollow(self, lanes): 1589 """addSubscriptionFilterLCManeuver(lanes) -> None 1590 1591 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1592 and follower of the ego. 1593 Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter. 1594 """ 1595 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LEAD_FOLLOW) 1596 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes)
addSubscriptionFilterLCManeuver(lanes) -> None
Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader and follower of the ego. Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter.
1598 def addSubscriptionFilterTurn(self, downstreamDist=None, foeDistToJunction=None): 1599 """addSubscriptionFilterTurn(double, double) -> None 1600 1601 Restricts vehicles returned by the last modified vehicle context subscription to foes on upcoming junctions 1602 """ 1603 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_TURN, foeDistToJunction) 1604 if downstreamDist is not None: 1605 self.addSubscriptionFilterDownstreamDistance(downstreamDist)
addSubscriptionFilterTurn(double, double) -> None
Restricts vehicles returned by the last modified vehicle context subscription to foes on upcoming junctions
1607 def addSubscriptionFilterVClass(self, vClasses): 1608 """addSubscriptionFilterVClass(list(String)) -> None 1609 1610 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given classes 1611 """ 1612 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VCLASS, vClasses)
addSubscriptionFilterVClass(list(String)) -> None
Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given classes
1614 def addSubscriptionFilterVType(self, vTypes): 1615 """addSubscriptionFilterVType(list(String)) -> None 1616 1617 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given types 1618 """ 1619 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VTYPE, vTypes)
addSubscriptionFilterVType(list(String)) -> None
Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given types
1621 def addSubscriptionFilterFieldOfVision(self, openingAngle): 1622 """addSubscriptionFilterFieldOfVision(float) -> None 1623 1624 Restricts vehicles returned by the last modified vehicle context subscription 1625 to vehicles within field of vision with given opening angle 1626 """ 1627 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_FIELD_OF_VISION, openingAngle)
addSubscriptionFilterFieldOfVision(float) -> None
Restricts vehicles returned by the last modified vehicle context subscription to vehicles within field of vision with given opening angle
1629 def addSubscriptionFilterLateralDistance(self, lateralDist, downstreamDist=None, upstreamDist=None): 1630 """addSubscriptionFilterLateralDist(double, double, double) -> None 1631 1632 Adds a lateral distance filter to the last modified vehicle context subscription 1633 (call it just after subscribing). 1634 downstreamDist and upstreamDist specify the longitudinal range of the search 1635 for surrounding vehicles along the ego vehicle's route. 1636 """ 1637 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LATERAL_DIST, lateralDist) 1638 if downstreamDist is not None: 1639 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1640 if upstreamDist is not None: 1641 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
addSubscriptionFilterLateralDist(double, double, double) -> None
Adds a lateral distance filter to the last modified vehicle context subscription (call it just after subscribing). downstreamDist and upstreamDist specify the longitudinal range of the search for surrounding vehicles along the ego vehicle's route.
Inherited Members
- traci._vehicletype.VTypeDomain
- getLength
- getMaxSpeed
- getActionStepLength
- getSpeedFactor
- getSpeedDeviation
- getAccel
- getDecel
- getEmergencyDecel
- getApparentDecel
- getImperfection
- getTau
- getVehicleClass
- getEmissionClass
- getShapeClass
- getMinGap
- getWidth
- getHeight
- getMass
- getColor
- getMinGapLat
- getMaxSpeedLat
- getLateralAlignment
- getPersonCapacity
- getBoardingDuration
- getImpatience
- setImpatience
- setBoardingDuration
- setLength
- setMaxSpeed
- setVehicleClass
- setSpeedFactor
- setEmissionClass
- setShapeClass
- setWidth
- setHeight
- setMass
- setMinGap
- setAccel
- setDecel
- setEmergencyDecel
- setApparentDecel
- setImperfection
- setTau
- setColor
- setMinGapLat
- setMaxSpeedLat
- setLateralAlignment
- setActionStepLength
- traci.domain.Domain
- DOMAIN_ID
- getIDList
- getIDCount
- domainID
- subscribe
- unsubscribe
- getSubscriptionResults
- getAllSubscriptionResults
- subscribeContext
- unsubscribeContext
- getContextSubscriptionResults
- getAllContextSubscriptionResults
- getParameter
- getParameterWithKey
- subscribeParameterWithKey
- setParameter