diff --git a/Spwan_Fahrzeuge_Wetterbedingungen _Nna.py b/Spwan_Fahrzeuge_Wetterbedingungen _Nna.py index 00f1021..ef4a1e6 100644 --- a/Spwan_Fahrzeuge_Wetterbedingungen _Nna.py +++ b/Spwan_Fahrzeuge_Wetterbedingungen _Nna.py @@ -125,10 +125,12 @@ def manage_uncontrolled_intersections(): else: vehicle.waiting_time += world.get_snapshot().timestamp.delta_seconds print(f"Vehicle {vehicle.id} is waiting for {vehicle.waiting_time:.1f} sec.") + + - - - +#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 @@ -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 time.sleep(0.1) - - # Suppression du capteur + # Suppression du capteur sensor.destroy() # Vérification et affichage du message @@ -320,7 +321,6 @@ def adjust_truck_steering(truck, world): right_clearance = get_clearance(truck.vehicle, "right", world) front_clearance = get_clearance(truck.vehicle, "front", world) - control = truck.vehicle.get_control() # Ajuster la direction pour éviter les obstacles @@ -339,9 +339,7 @@ def adjust_truck_steering(truck, world): if front_clearance < 3.0: # Si un véhicule est trop proche devant control.brake = 0.5 # Appliquer le freinage control.throttle = 0.0 # Réduire la vitesse à zéro pour éviter une collision - - - + # fonction pour freiner 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 truck.vehicle.apply_control(control) - - - # Filtrer les camions dans la simulation vehicles = world.get_actors().filter('vehicle.*') @@ -372,9 +367,11 @@ def adjust_truck_steering(truck, world): - -# Pour suivre le temps d'arrêt des véhicules - +#The code based of the speed and stop_time of vehicles +# 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 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*') spawn_points = world.get_map().get_spawn_points() + # Spawn 30 vehicles randomly distributed throughout the map # for each spawn point, we choose a random vehicle from the blueprint library vehicles = [] for i in range(0,30): vehicles.append(world.try_spawn_actor(random.choice(vehicle_blueprints), random.choice(spawn_points))) +#display the available vehicles blueprint_library = world.get_blueprint_library() print("Available vehicule models:", blueprint_library.filter('vehicle.*')) - +#display the Number of spwan points print("Number of spawn points:", len(spawn_points)) @@ -457,16 +455,14 @@ if vehicle is not None: else: print(f"Failed to create vehicle after several attempts.") - +#The vehicles start the control system for vehicle in world.get_actors().filter('*vehicle*'): if vehicle.attributes['role_name'] != 'ego': 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.ClearNoon) world.set_weather(carla.WeatherParameters.HardRainNight)