0

I am working on SUMO VEINS and OMNEST. To run sumo files on OMNEST, the input of sumo files (.xml) are inputted in veins_launchd, which in turn finds an unused port, starts sumo and bridges the connection between sumo and OMNEST.

I want to control the vehicle's behavior (Speed change) on real time (during the simulation). For this purpose, I have written a Traci script in python language, which calls sumo config file and controls vehicle speed on real time

My issue is, I do not know how to make this Traci script (python) to run on OMNEST via veins. Where should I give this python file as input so that I can visualize the output in OMNEST. My working environment is Linux

Based on some research, I figured out 2 methods.

1. TraCIScenarioManager module

2. Veins_Python

Method1: I understood by using TraCIScenarioManager module, OMNEST can directly connect to the running sumo. But I don't know where should I make the necessary changes inside veins module to use TraCIScenarioManager instead TraCIScenarioManagerLaunchd

Method2: Regarding veins_python, I downloaded the source file from github and did the configuration steps as mentioned. I used windows10 and Versions: Veins5.0, OMNeT++ 5.5.1 and Python3.6 But I got the below error while configuring Veins_Python.

enter image description here

I also tried with the recent versions of software on windows 10 Versions: Veins5.2, OMNEST-5.6.2 and Python3.10 Still I get the same error.

My Sumo Traci script is

import traci
import time
import traci.constants as tc
import pytz
import datetime
from random import randrange
import pandas as pd


def getdatetime():
        utc_now = pytz.utc.localize(datetime.datetime.utcnow())
        currentDT = utc_now.astimezone(pytz.timezone("Asia/Tokyo"))
        DATIME = currentDT.strftime("%Y-%m-%d %H:%M:%S")
        return DATIME

def flatten_list(_2d_list):
    flat_list = []
    for element in _2d_list:
        if type(element) is list:
            for item in element:
                flat_list.append(item)
        else:
            flat_list.append(element)
    return flat_list


sumoCmd = ["sumo-gui", "-c", "osm.sumocfg"]
traci.start(sumoCmd)

packVehicleData = []
packTLSData = []
packBigData = []

while traci.simulation.getMinExpectedNumber() > 0:
       
        traci.simulationStep();
        timestep = traci.simulation.getTime()

        vehicles=traci.vehicle.getIDList();
        trafficlights=traci.trafficlight.getIDList();

        for i in range(0,len(vehicles)):

                vehid = vehicles[i]
                x, y = traci.vehicle.getPosition(vehicles[i])
                coord = [x, y]
                lon, lat = traci.simulation.convertGeo(x, y)
                gpscoord = [lon, lat]
                spd = round(traci.vehicle.getSpeed(vehicles[i])*3.6,2)


                #Packing of all the data for export to CSV/XLSX
                vehList = [getdatetime(), vehid, coord, gpscoord, spd]
                
                
                print("Vehicle: ", vehicles[i], " at datetime: ", getdatetime())
                print(vehicles[i], " >>> Position: ", coord, " | GPS Position: ", gpscoord, " |", \
                                       " Speed: ", round(traci.vehicle.getSpeed(vehicles[i])*3.6,2), "km/h |", \

                       )


                #Pack Simulated Data
                packBigDataLine = flatten_list([vehList, tlsList])
                packBigData.append(packBigDataLine)


                ##----- CONTROL Vehicles ----##

                #***SET FUNCTION FOR VEHICLES***
                #REF: https://sumo.dlr.de/docs/TraCI/Change_Vehicle_State.html
                NEWSPEED = 15 # value in m/s (15 m/s = 54 km/hr)
                if vehicles[i]=='veh2':

                        traci.vehicle.setSpeedMode('veh2',0)
                        traci.vehicle.setSpeed('veh2',NEWSPEED)
                                                                    

traci.close()

#Generate Excel file
columnnames = ['dateandtime', 'vehid', 'coord', 'gpscoord', 'spd'] 
dataset = pd.DataFrame(packBigData, index=None, columns=columnnames)
dataset.to_excel("output.xlsx", index=False)
time.sleep(5)

It would be really helpful if you could suggest me the procedure or tutorial for executing my Sumo's traci script on OMNEST using veins.

Thilaga
  • 1
  • 1

1 Answers1

0

I think what you want is not possible since traci supports only a single client (which is veins in your setup) or if you want multiple clients veins needs to be changed. You might try to send the messages inside veins though, see How to access TraCI command interface from TraCIDemoRSU11p in Veins Car2X simulator?

Michael
  • 3,510
  • 1
  • 11
  • 23