Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/bugs/ticket4418/runner.py
169689 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 Leonhard Luecken
17
# @author Michael Behrisch
18
# @author Jakob Erdmann
19
# @author Daniel Krajzewicz
20
# @date 2011-03-04
21
22
23
from __future__ import print_function
24
from __future__ import absolute_import
25
import os
26
import sys
27
28
if "SUMO_HOME" in os.environ:
29
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
30
31
import traci # noqa
32
import sumolib # noqa
33
34
35
def step():
36
s = traci.simulation.getTime()
37
traci.simulationStep()
38
return s
39
40
41
traci.start([sumolib.checkBinary('sumo'), "-c", "sumo.sumocfg"])
42
43
lead = "lead"
44
follow = "follow"
45
46
stopPos = 200
47
slowDownDist = 10
48
49
for i in range(10000):
50
step()
51
remDist = stopPos - traci.vehicle.getLanePosition(follow)
52
if remDist < slowDownDist:
53
# stop after distance remDist (which is the stop position for the leader
54
# (mimics glosa situation in front of traffic light where this problem was observed))
55
# d = v*v/(2*a) => a = v*v/(2*d) => tstop = v/a = 2*d/v
56
speed = traci.vehicle.getSpeed(follow)
57
tstop = 2*remDist / speed
58
print("Commanding slow down for vehicle '%s' at time %s. Remaining distance: %s, speed: %s" %
59
(follow, traci.simulation.getTime(), remDist, speed))
60
traci.vehicle.slowDown(follow, 0, tstop)
61
break
62
63
while traci.simulation.getMinExpectedNumber() > 0:
64
step()
65
# done
66
traci.close()
67
68