Path: blob/main/tests/complex/traci/vehicle/lateralCollision/sublaneChanging/runner.py
169730 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file runner.py14# @author Daniel Krajzewicz15# @author Michael Behrisch16# @date 2012-10-191718from __future__ import absolute_import19from __future__ import print_function2021import os22import sys2324sumoHome = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', '..', '..', '..'))25sys.path.append(os.path.join(sumoHome, "tools"))26import sumolib # noqa27import traci # noqa282930if sys.argv[1] == "sumo":31sumoCall = [sumolib.checkBinary('sumo')]32else:33sumoCall = [sumolib.checkBinary('sumo-gui'), '-S', '-Q']343536def runSingle(traciEndTime, latDist, vehID):37step = 038traci.start(sumoCall + ["-c", "sumo.sumocfg",39"--lateral-resolution", "0.1"])4041# disable safety checks and set constant speed42print("old lanechangemode", format(traci.vehicle.getLaneChangeMode(vehID), '012b'))43print("old speedmode", traci.vehicle.getSpeedMode(vehID))44for veh in ("collider", "left", "right"):45traci.vehicle.setLaneChangeMode(veh, 0b010001010101)46traci.vehicle.setSpeedMode(veh, 0)47traci.vehicle.setSpeed(veh, 20)48print("new lanechangemode", format(traci.vehicle.getLaneChangeMode(vehID), '012b'))49print("new speedmode", traci.vehicle.getSpeedMode(vehID))5051while not step > traciEndTime:52traci.simulationStep()5354# check if vehID has arrived at destination55arrivedList = traci.simulation.getArrivedIDList()56if vehID in arrivedList:57print("[%03d] Vehicle '%s' has arrived at destination" % (step, vehID))58break5960print("trying to change lateral position by %.2f..." % (latDist))61traci.vehicle.changeSublane(vehID, latDist)62print("[%03d] lane %d, lateral pos: %.2f" %63(step, traci.vehicle.getLaneIndex(vehID), traci.vehicle.getLateralLanePosition(vehID)))64sys.stdout.flush()6566step += 16768print("Print ended at step %s" % traci.simulation.getTime())69traci.close()70sys.stdout.flush()717273sys.stdout.flush()74sys.stderr.flush()75runSingle(50, float(sys.argv[2]), "collider")767778