[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sumo-user] Vehicles are not Responding to Commands in TraCI
|
Hi Ifezue,
with some slight modifications both batterie request and slowDown
in your script works fine
leader ('6', 39.15839766767725)
14516 Slowdown vehicle 5 with current speed 5.8
leader ('6', 33.86887170421031)
14517 Slowdown vehicle 5 with current speed 5.3
leader ('6', 29.05112082833128)
14518 Slowdown vehicle 5 with current speed 4.8
leader ('6', 25.030976798088826)
14519 Slowdown vehicle 5 with current speed 4.0
leader ('6', 21.36720949786841)
14520 Slowdown vehicle 5 with current speed 3.7
leader ('6', 18.027421043122573)
14521 Slowdown vehicle 5 with current speed 3.3
leader ('6', 14.982158811535452)
14522 Slowdown vehicle 5 with current speed 3.0
leader ('6', 12.2046476919108)
14523 Slowdown vehicle 5 with current speed 2.8
leader ('6', 9.670546674070202)
14524 Slowdown vehicle 5 with current speed 2.5
leader ('6', 7.357727566942389)
14525 Slowdown vehicle 5 with current speed 2.3
leader ('6', 5.246073833189829)
14526 Slowdown vehicle 5 with current speed 2.1
leader ('6', 3.333195595135593)
14527 Slowdown vehicle 5 with current speed 1.9
leader ('6', 2.0003173570813555)
14528 Slowdown vehicle 5 with current speed 1.3
leader ('6', 1.200590414248813)
14529 Slowdown vehicle 5 with current speed 0.8
leader ('6', 0.7207542485492882)
14530 Slowdown vehicle 5 with current speed 0.5
leader ('6', 0.4328525491295725)
14531 Slowdown vehicle 5 with current speed 0.3
leader ('6', 0.26011152947774363)
14532 Slowdown vehicle 5 with current speed 0.2
leader ('6', 0.15646691768664578)
100 secs is a long time to increase the distance between two
vehicles close to each other, i have chosen 10 sec
In your battery stuff you should query the vehicle, not the
vehicleType.
Regards, Harald
Am 13.10.21 um 02:57 schrieb
vincentobiako:
Hello Everyone
I am fairly new to Python and SUMO. I have
a bus route, referred to as a Green Bus Route, that is running
in SUMO. This bus route has two buses on its line/route and
somehow these buses manage to get bunched up together,
offering no headway between the two vehicles. I am currently
trying to solve this issue by having the follower bus slow
down for some time so that it can get some adequate headway
between it and the leading bus. In order to this, I am having
the following bus “detect” the lead bus through the
traci.vehicle.getLeader() method and having the bus slow down
with traci.vehicle.slowDown() method. However, when I run
my script in the simulation, the simulation runs with no
errors, but the green buses don’t seem to do what I had
intended them to do in the Python script.
I have attached some test files to this
email for reference to clear up any confusion. Please refer to
the Python function named “maintain_headway” for where this
issue seems to be occurring.
Thanks for the help in advance
Ifezue
Sent from Mail for Windows
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
#!/usr/bin/python3
import traci
# import time
# import csv
from sumolib import checkBinary
import argparse
parser = argparse.ArgumentParser(
prog='compute-pass-per-vehicle-with-sumo.py',
usage='%(prog)s [optional arguments] -- SUMOARGS',
description='Run SUMO and compute passengers per vehicle',
epilog="Examples\n"
' compute-pass-per-vehicle-with-sumo.py -f 500 -l 1000 -v tram1 tram4 -- -c loopAraya.sumocfg\n'
' run SUMO with loopAraya.sumocfg, collect data between 500 and 1000 sec for vehicles tram1 and tram4\n'
' compute-pass-per-vehicle-with-sumo.py -f 3600 -t 4000 -v 0 1 2 3 -- -c test.sumocfg\n'
' run SUMO with test.sumocfg, collect data between 3600 and 4000 sec for vehicles 0,1,2 and 3'
, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-f','--first', type=int, default=0, help='From time')
parser.add_argument('-l','--last', type=int, default=3600, help='To time')
parser.add_argument('-v','--vehicles', nargs='+', help='Vehicles to observe')
parser.add_argument('-g','--gui', action='store_true', help='Use sumo-gui')
parser.add_argument('sumoargs', nargs='+')
args = parser.parse_args()
if args.gui:
sumoBinary = checkBinary ("sumo-gui")
else:
sumoBinary = checkBinary ("sumo")
sumoCmd = [sumoBinary, "--quit-on-end", "--start"]
sumoCmd.extend(args.sumoargs)
print('Run ' + ' '.join(sumoCmd))
traci.start(sumoCmd)
step = 0
csvfile = open('passengers.csv', 'w')
# plugins for the main loop fror different questions
def fueling_behavior(current_time):
if 3600 <= current_time <= 4000:
current_fuel_Level = traci.vehicle.getParameter("0", "device.battery.actualBatteryCapacity")
print ('%.0f Vehicle %s Battery %8.2f' % (current_time, '0', float(current_fuel_Level)))
# print (current_fuel_Level)
def maintain_headway(current_time):
#For Green Route Buses (ONLY)
# Detect Vehicle 6 so that Vehicle 5 can slow down
if current_time >= 3600:
secondVehicle = '5'
leader = traci.vehicle.getLeader(secondVehicle, 30)
if leader != None:
print('leader', leader)
#print('Leader of 5 %s' % leader_id)
if leader[0] == "6" and leader[1] <= 50:
oldSpeed = traci.vehicle.getSpeed(secondVehicle)
traci.vehicle.slowDown(secondVehicle, 0.1, 10)
#traci.vehicle.slowDown(secondVehicle, 0.1, 100)
print('%.0f Slowdown vehicle %s with current speed %4.1f' % (current_time, secondVehicle, oldSpeed))
# if leader_id >= ("6", 15):
# traci.vehicle.openGap("5", 360, 1850, 300, -0.5, -0.5, "6")
# traci.vehicle.getSt
# main loop, current_time serves as step
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
current_time = traci.simulation.getTime()
# Execution for Beginning of Simulation
# do nothing special
# Execution for collecting Ridership within Bus Vehicles
# call plugins
maintain_headway(current_time)
fueling_behavior(current_time)
if args.first <= step:
# This set of code gets the number of riders currently within the bus
list_of_ridership = [str(current_time)]
for id in args.vehicles:
# take care, if vehicle does not exist
try:
ridership = traci.vehicle.getPersonNumber(id)
except:
ridership = 0
list_of_ridership.append(str(ridership))
# create a comma-separated list
print(','.join(list_of_ridership), file=csvfile, flush=True)
if step > args.last:
break
step += 1 # not really used any more
csvfile.close()
traci.close()