Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/bugs/ticket2321/runner.py
169708 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
4
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file runner.py
16
# @author Jakob Erdmann
17
# @date 2017-01-23
18
19
20
from __future__ import print_function
21
from __future__ import absolute_import
22
import os
23
import sys
24
25
if 'SUMO_HOME' in os.environ:
26
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
27
import traci # noqa
28
import sumolib # noqa
29
30
traci.start([sumolib.checkBinary('sumo'), "-c", "sumo.sumocfg"])
31
firstPos = None
32
endPos = None
33
34
vehID = "v0"
35
traci.simulationStep()
36
traci.route.add("r0", ["SC", "CN"])
37
traci.vehicle.addLegacy(vehID, "r0")
38
traci.vehicle.setImperfection(vehID, 0)
39
while traci.simulation.getMinExpectedNumber() > 0:
40
traci.simulationStep()
41
try:
42
if firstPos is None:
43
firstPos = traci.vehicle.getPosition(vehID)
44
endPos = traci.simulation.convert2D("CN", 90)
45
currPos = traci.vehicle.getPosition(vehID)
46
currEdge = traci.vehicle.getRoadID(vehID)
47
currLanePos = traci.vehicle.getLanePosition(vehID)
48
print(("step=%s road=%s lane=%s pos=%.2f dist=%.2f simDist=%.2f simDistToEnd=%.2f distToInt=%.2f " +
49
"distToEnd=%.2f simDist2DToInt=%.2f simDist2DToEnd=%.2f") % (
50
traci.simulation.getTime(),
51
currEdge,
52
traci.vehicle.getLaneID(vehID),
53
traci.vehicle.getLanePosition(vehID),
54
traci.vehicle.getDistance(vehID),
55
traci.simulation.getDistance2D(firstPos[0], firstPos[1], currPos[0], currPos[1], isDriving=True),
56
traci.simulation.getDistance2D(currPos[0], currPos[1], endPos[0], endPos[1], isDriving=True),
57
traci.vehicle.getDrivingDistance(vehID, ":C_10", 13.8),
58
traci.vehicle.getDrivingDistance(vehID, "CN", 90),
59
traci.simulation.getDistanceRoad(currEdge, currLanePos, ":C_10", 13.8),
60
traci.simulation.getDistanceRoad(currEdge, currLanePos, "CN", 90)
61
))
62
except traci.TraCIException:
63
pass
64
65
traci.close()
66
67