Path: blob/main/tests/complex/traci/vehicle/moveToXY/short_edges/runner.py
169998 views
#!/usr/bin/env python1# -*- coding: utf-8 -*-2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo3# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file runner.py15# @author Jakob Erdmann16# @date 2017-01-23171819from __future__ import print_function20from __future__ import absolute_import21import os22import sys2324if "SUMO_HOME" in os.environ:25sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))2627import traci # noqa28import sumolib # noqa2930WATCH = False3132sumoBinary = 'sumo-gui' if WATCH else sumolib.checkBinary('sumo')33cmd = [34sumoBinary,35'-n', 'input_net.net.xml',36'--no-step-log', ]37if not WATCH:38cmd += ['-S', '-Q']3940traci.start(cmd)4142ANGLE_UNDEF = traci.constants.INVALID_DOUBLE_VALUE43INVALID = traci.constants.INVALID_DOUBLE_VALUE4445vehID = "v0"464748def check(x, y, angle, exLane, exPos, exPosLat, comment):49traci.vehicle.moveToXY(vehID, "", 0, x, y, angle, keepRoute=2)50traci.simulationStep()51x2, y2 = traci.vehicle.getPosition(vehID)52lane2 = traci.vehicle.getLaneID(vehID)53pos2 = traci.vehicle.getLanePosition(vehID)54posLat2 = traci.vehicle.getLateralLanePosition(vehID)55if (abs(x - x2) > 0.1 or56abs(y - y2) > 0.1 or57(exLane is not None and exLane != lane2) or58(exPos is not None and abs(exPos - pos2) > 0.1) or59(exPosLat is not None and abs(exPosLat - posLat2) > 0.1)):60print(comment, ("failed: x=%s, x2=%s, y=%s, y2=%s, lane=%s, lane2=%s, pos=%s, pos2=%s " +61"posLat=%s posLat2=%s") % (x, x2, y, y2, exLane, lane2, exPos, pos2, exPosLat, posLat2))62else:63# print(comment, "success")64pass656667traci.simulationStep()68traci.vehicle.add(vehID, "")6970check(6.54, -1.50, ANGLE_UNDEF, "A0toB0_0", None, None, "middle of the first edge")71check(23.00, -1.50, ANGLE_UNDEF, "B0toC0_0", None, None, "middle of the second edge")72check(37.11, -1.67, ANGLE_UNDEF, "C0toD0_0", None, None, "middle of the third edge")73traci.simulationStep()74traci.simulationStep()75traci.close()767778