Path: blob/main/tests/complex/traci/vehicle/lateralCollision/laneChanging/runner.py
169720 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, laneIndex, vehID):37step = 038traci.start(sumoCall + ["-c", "sumo.sumocfg"])3940# disable safety checks and set constant speed41print("old lanechangemode", format(traci.vehicle.getLaneChangeMode(vehID), '012b'))42print("old speedmode", traci.vehicle.getSpeedMode(vehID))43for veh in ("collider", "left", "right"):44traci.vehicle.setLaneChangeMode(veh, 0b010001010101)45traci.vehicle.setSpeedMode(veh, 0)46traci.vehicle.setSpeed(veh, 20)47print("new lanechangemode", format(traci.vehicle.getLaneChangeMode(vehID), '012b'))48print("new speedmode", traci.vehicle.getSpeedMode(vehID))4950while not step > traciEndTime:51traci.simulationStep()5253if step == 5:54print("trying to change lane...")55traci.vehicle.changeLane(vehID, laneIndex, traciEndTime)5657# check if vehID has arrived at destination58arrivedList = traci.simulation.getArrivedIDList()59if vehID in arrivedList:60print("[%03d] Vehicle '%s' has arrived at destination" % (step, vehID))61break6263print("[%03d] lane %d, lateral pos: %.2f" %64(step, traci.vehicle.getLaneIndex(vehID), traci.vehicle.getLateralLanePosition(vehID)))65sys.stdout.flush()6667step += 16869print("Print ended at step %s" % traci.simulation.getTime())70traci.close()71sys.stdout.flush()727374sys.stdout.flush()75sys.stderr.flush()76runSingle(50, int(sys.argv[2]), "collider")777879