Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/vehicle/lateralCollision/sublaneChanging/runner.py
169730 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2025 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 runner.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2012-10-19
18
19
from __future__ import absolute_import
20
from __future__ import print_function
21
22
import os
23
import sys
24
25
sumoHome = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', '..', '..', '..'))
26
sys.path.append(os.path.join(sumoHome, "tools"))
27
import sumolib # noqa
28
import traci # noqa
29
30
31
if sys.argv[1] == "sumo":
32
sumoCall = [sumolib.checkBinary('sumo')]
33
else:
34
sumoCall = [sumolib.checkBinary('sumo-gui'), '-S', '-Q']
35
36
37
def runSingle(traciEndTime, latDist, vehID):
38
step = 0
39
traci.start(sumoCall + ["-c", "sumo.sumocfg",
40
"--lateral-resolution", "0.1"])
41
42
# disable safety checks and set constant speed
43
print("old lanechangemode", format(traci.vehicle.getLaneChangeMode(vehID), '012b'))
44
print("old speedmode", traci.vehicle.getSpeedMode(vehID))
45
for veh in ("collider", "left", "right"):
46
traci.vehicle.setLaneChangeMode(veh, 0b010001010101)
47
traci.vehicle.setSpeedMode(veh, 0)
48
traci.vehicle.setSpeed(veh, 20)
49
print("new lanechangemode", format(traci.vehicle.getLaneChangeMode(vehID), '012b'))
50
print("new speedmode", traci.vehicle.getSpeedMode(vehID))
51
52
while not step > traciEndTime:
53
traci.simulationStep()
54
55
# check if vehID has arrived at destination
56
arrivedList = traci.simulation.getArrivedIDList()
57
if vehID in arrivedList:
58
print("[%03d] Vehicle '%s' has arrived at destination" % (step, vehID))
59
break
60
61
print("trying to change lateral position by %.2f..." % (latDist))
62
traci.vehicle.changeSublane(vehID, latDist)
63
print("[%03d] lane %d, lateral pos: %.2f" %
64
(step, traci.vehicle.getLaneIndex(vehID), traci.vehicle.getLateralLanePosition(vehID)))
65
sys.stdout.flush()
66
67
step += 1
68
69
print("Print ended at step %s" % traci.simulation.getTime())
70
traci.close()
71
sys.stdout.flush()
72
73
74
sys.stdout.flush()
75
sys.stderr.flush()
76
runSingle(50, float(sys.argv[2]), "collider")
77
78