Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/vehicle/cfmodel/CACC/runner.py
169779 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2009-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 Lena Kalleske
16
# @author Daniel Krajzewicz
17
# @author Michael Behrisch
18
# @author Jakob Erdmann
19
# @author Leonhard Luecken
20
# @date 2009-03-26
21
22
# @author Robert Alms
23
# @date 2023-02.23
24
25
from __future__ import absolute_import
26
from __future__ import print_function
27
28
import os
29
import sys
30
31
# we need to import python modules from the $SUMO_HOME/tools directory
32
try:
33
sys.path.append(os.path.join(os.environ.get("SUMO_HOME", os.path.join(
34
os.path.dirname(__file__), "..", "..", "..", "..")), "tools"))
35
except ImportError:
36
sys.exit("please declare environment variable 'SUMO_HOME'")
37
import traci
38
from sumolib import checkBinary
39
40
41
def run(mode, fname):
42
traci.start([sumoBinary,
43
"-n", "input_net.net.xml",
44
"-r", "input_routes.rou.xml",
45
"--fcd-output", fname,
46
"--fcd-output.attributes", "speed",
47
"--default.speeddev", "0",
48
"--step-length", "0.5",
49
"--no-step-log"])
50
51
traci.vehicle.setParameter("ego", "carFollowModel.caccCommunicationsOverrideMode", str(mode))
52
print("Set OverrideMode: %s , get OverrideMode: %s" % (
53
mode,
54
traci.vehicle.getParameter("ego", "carFollowModel.caccCommunicationsOverrideMode")))
55
56
while traci.simulation.getMinExpectedNumber() > 0:
57
traci.simulationStep()
58
traci.close()
59
60
61
sumoBinary = checkBinary('sumo')
62
for mode, fname in zip(range(0, 4), ['fcd.xml', 'fcd2.xml', 'fcd3.xml', 'fcd4.xml']):
63
run(mode, fname)
64
65