forked from zhuli90799/Fahrsimulator
Spwan_Fahrzeuge_Wetterbedingungen _Nna.py aktualisiert
This commit is contained in:
parent
94390675ed
commit
1c9b7cc6f5
@ -128,7 +128,9 @@ def manage_uncontrolled_intersections():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#The Code try to adjusts the position of two colliding vehicles to separate them.
|
||||||
|
#if the adjustment fails, the vehicle that cannot free itself is removed from the
|
||||||
|
#wold
|
||||||
|
|
||||||
collision_status = {} # Statut de collision entre véhicules
|
collision_status = {} # Statut de collision entre véhicules
|
||||||
|
|
||||||
@ -253,7 +255,7 @@ def ensure_correct_stop(vehicle):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#The code adjust the position of ambulance
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -294,8 +296,7 @@ def get_clearance(vehicle, side, world):
|
|||||||
# Attendre un instant pour capter les données
|
# Attendre un instant pour capter les données
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# Suppression du capteur
|
||||||
# Suppression du capteur
|
|
||||||
sensor.destroy()
|
sensor.destroy()
|
||||||
|
|
||||||
# Vérification et affichage du message
|
# Vérification et affichage du message
|
||||||
@ -320,7 +321,6 @@ def adjust_truck_steering(truck, world):
|
|||||||
right_clearance = get_clearance(truck.vehicle, "right", world)
|
right_clearance = get_clearance(truck.vehicle, "right", world)
|
||||||
front_clearance = get_clearance(truck.vehicle, "front", world)
|
front_clearance = get_clearance(truck.vehicle, "front", world)
|
||||||
|
|
||||||
|
|
||||||
control = truck.vehicle.get_control()
|
control = truck.vehicle.get_control()
|
||||||
|
|
||||||
# Ajuster la direction pour éviter les obstacles
|
# Ajuster la direction pour éviter les obstacles
|
||||||
@ -340,8 +340,6 @@ def adjust_truck_steering(truck, world):
|
|||||||
control.brake = 0.5 # Appliquer le freinage
|
control.brake = 0.5 # Appliquer le freinage
|
||||||
control.throttle = 0.0 # Réduire la vitesse à zéro pour éviter une collision
|
control.throttle = 0.0 # Réduire la vitesse à zéro pour éviter une collision
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# fonction pour freiner
|
# fonction pour freiner
|
||||||
distance_ahead = get_clearance(truck.vehicle,"front",world)
|
distance_ahead = get_clearance(truck.vehicle,"front",world)
|
||||||
|
|
||||||
@ -356,9 +354,6 @@ def adjust_truck_steering(truck, world):
|
|||||||
# Appliquer le nouveau contrôle au camion
|
# Appliquer le nouveau contrôle au camion
|
||||||
truck.vehicle.apply_control(control)
|
truck.vehicle.apply_control(control)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Filtrer les camions dans la simulation
|
# Filtrer les camions dans la simulation
|
||||||
vehicles = world.get_actors().filter('vehicle.*')
|
vehicles = world.get_actors().filter('vehicle.*')
|
||||||
|
|
||||||
@ -372,9 +367,11 @@ def adjust_truck_steering(truck, world):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#The code based of the speed and stop_time of vehicles
|
||||||
# Pour suivre le temps d'arrêt des véhicules
|
# check if vehicles has 0.0 m/s speed and
|
||||||
|
# stop_time ist more than 30 seconds
|
||||||
|
# that means the vehicle is blocked and
|
||||||
|
# will be removed
|
||||||
stuck_vehicles_time = {} # Stocke le temps d'arrêt des véhicules
|
stuck_vehicles_time = {} # Stocke le temps d'arrêt des véhicules
|
||||||
|
|
||||||
def is_vehicle_blocked(vehicle, max_stop_time=30):
|
def is_vehicle_blocked(vehicle, max_stop_time=30):
|
||||||
@ -421,20 +418,21 @@ def is_spawn_point_occupied(spawn_point, vehicles, max_density=2, remove_stuck_v
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# get the vehicle blueprints and spwan point
|
||||||
|
|
||||||
vehicle_blueprints = world.get_blueprint_library().filter('vehicle*')
|
vehicle_blueprints = world.get_blueprint_library().filter('vehicle*')
|
||||||
spawn_points = world.get_map().get_spawn_points()
|
spawn_points = world.get_map().get_spawn_points()
|
||||||
|
|
||||||
# Spawn 30 vehicles randomly distributed throughout the map
|
# Spawn 30 vehicles randomly distributed throughout the map
|
||||||
# for each spawn point, we choose a random vehicle from the blueprint library
|
# for each spawn point, we choose a random vehicle from the blueprint library
|
||||||
vehicles = []
|
vehicles = []
|
||||||
for i in range(0,30):
|
for i in range(0,30):
|
||||||
vehicles.append(world.try_spawn_actor(random.choice(vehicle_blueprints), random.choice(spawn_points)))
|
vehicles.append(world.try_spawn_actor(random.choice(vehicle_blueprints), random.choice(spawn_points)))
|
||||||
|
|
||||||
|
#display the available vehicles
|
||||||
blueprint_library = world.get_blueprint_library()
|
blueprint_library = world.get_blueprint_library()
|
||||||
print("Available vehicule models:", blueprint_library.filter('vehicle.*'))
|
print("Available vehicule models:", blueprint_library.filter('vehicle.*'))
|
||||||
|
|
||||||
|
#display the Number of spwan points
|
||||||
print("Number of spawn points:", len(spawn_points))
|
print("Number of spawn points:", len(spawn_points))
|
||||||
|
|
||||||
|
|
||||||
@ -457,16 +455,14 @@ if vehicle is not None:
|
|||||||
else:
|
else:
|
||||||
print(f"Failed to create vehicle after several attempts.")
|
print(f"Failed to create vehicle after several attempts.")
|
||||||
|
|
||||||
|
#The vehicles start the control system
|
||||||
for vehicle in world.get_actors().filter('*vehicle*'):
|
for vehicle in world.get_actors().filter('*vehicle*'):
|
||||||
if vehicle.attributes['role_name'] != 'ego':
|
if vehicle.attributes['role_name'] != 'ego':
|
||||||
vehicle.set_autopilot(True)
|
vehicle.set_autopilot(True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#How to set weather and display available carla.weather.parameters
|
||||||
|
|
||||||
|
|
||||||
world.set_weather(carla.WeatherParameters.HardRainNoon)
|
world.set_weather(carla.WeatherParameters.HardRainNoon)
|
||||||
world.set_weather(carla.WeatherParameters.ClearNoon)
|
world.set_weather(carla.WeatherParameters.ClearNoon)
|
||||||
world.set_weather(carla.WeatherParameters.HardRainNight)
|
world.set_weather(carla.WeatherParameters.HardRainNight)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user