[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sumo-user] CAVs Vehicle's simulation
|
Hi Everyone,
I am working on a project that involves simulating five
passenger vehicles with different colors on four routes. I want to generate the
acceleration of each vehicle at each time step. The vehicles have the following
specifications:
- one yellow and one green
color vehicle starts from route 1 and travels via route 2 and 3 to reach route 4.
- One green and one red vehicle starts from route 2 and
travels via route 3 to reach Route 4.
- One magnetic vehicle starts from route 3 and reaches route
4 directly.
However, I encountered some problems with my Python TraCI
code and it could not run the simulation. I have attached the code for your
reference. I would appreciate any assistance or suggestions from you. Thank you.
Hello Simon,
Have you considered using TraCI API? You can use Python to access TraCI-specific functions which you can use to collect acceleration data at every timestep. You can access TraCI documentation (including simple applications)
here. For more specific commands, you can find a list
here and
here.
A simple command for accessing the acceleration would look something like:
accel = traci.vehicle.getAcceleration(veh_id)
Alternatively, you can choose to subscribe to each vehicle upon injection into the network (
info for variable subscription)
You can save the accel value into a dictionary with a key for each veh_id and use matplotlib to create your profile.
Hope that this helps.
Jerry
Hello Everyone,
I am a new user
of SUMO software and I am interested in simulating the traffic flow of fully
Connected and Automated Vehicles by adjusting the IDM model parameters. I want
to generate acceleration profiles for each vehicle in the simulation. Does
anyone have any suggestions or references for this task? I would appreciate any
help or guidance. Thank you
-- Simon Michael
Road and Transport Engineer
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user
-- Simon Michael
Road and Transport Engineer
import traci
# Start connection with SUMO
traci.start(["sumo", "-c", "C:\\Users\\pro\\OneDrive\\Desktop\\sumo\\new17.sumocfg"])
# Define the routes and their corresponding vehicle colors
routes = ['route1', 'route2', 'route3']
colors = [['yellow', 'green'], ['green', 'red'], ['magenta']]
# Define the routes for each vehicle
routes = ['route1', 'route2', 'route3', 'route4']
vehicle_routes = [['route1', 'route2', 'route3', 'route4'], # Route for yellow vehicle
['route1', 'route2', 'route3', 'route4'], # Route for first green vehicle
['route2', 'route3', 'route4'], # Route for second green vehicle
['route2', 'route3', 'route4'], # Route for red vehicle
['route3', 'route4'] # Route for magenta vehicle]
# Add vehicles and set their routes
for i in range(5):
vehicle_id = f'vehicle{i+1}'
traci.vehicle.add(vehicle_id, vehicle_routes[i][0])
traci.vehicle.setColor(vehicle_id, colors[i])
for route in vehicle_routes[i][1:]:
traci.vehicle.appendDrivingStage(vehicle_id, route, traci.constants.STAGE_DRIVING)
# Print acceleration of each vehicle at every time step
for vehicle_id in traci.vehicle.getIDList():
acceleration = traci.vehicle.getAcceleration(vehicle_id)
print(f'Acceleration of {vehicle_id} at time step {step}: {acceleration}')
# Python code to calculate acceleration of a vehicle
# at each time step.
def calculate_acceleration(speed1, speed2, time1, time2):
"""Calculate the acceleration of a vehicle at a given time step.
Parameters:
speed1 (float): The speed of the vehicle at the first time point.
speed2 (float): The speed of the vehicle at the second time point.
time1 (float): The first time point.
time2 (float): The second time point.
Returns:
float: The acceleration of the vehicle at the given time step.
"""
acceleration = (speed2 - speed1) / (time2 - time1)
return acceleration
# test the function
speed = 50 # in km/h
distance = 100 # in meters
acceleration = calculate_acceleration(speed, distance)
print(f'Acceleration of the vehicle: {acceleration} m/s^2')
for step in range(1000):
traci.simulationStep()
for vehicle_id in traci.vehicle.getIDList():
acceleration = traci.vehicle.getAcceleration(vehicle_id)
print(f'Acceleration of {vehicle_id} at time step {step}: {acceleration}')
traci.close()