From 0e30546ed7b19754ac1ae950c7ba3110e3eb9fe3 Mon Sep 17 00:00:00 2001 From: Mahbubul Alam Palash Date: Mon, 30 Dec 2024 13:48:57 -0500 Subject: [PATCH 1/3] TT-113 Updating the Carla Town5 Sumo route file with generated background traffic --- .../scenarios/Town05/sumo/Town05.rou.xml | 831 +++++++++--------- 1 file changed, 430 insertions(+), 401 deletions(-) diff --git a/co-simulation/bundle/src/assembly/resources/scenarios/Town05/sumo/Town05.rou.xml b/co-simulation/bundle/src/assembly/resources/scenarios/Town05/sumo/Town05.rou.xml index 1dd0a6c0..12fa165d 100644 --- a/co-simulation/bundle/src/assembly/resources/scenarios/Town05/sumo/Town05.rou.xml +++ b/co-simulation/bundle/src/assembly/resources/scenarios/Town05/sumo/Town05.rou.xml @@ -1,603 +1,632 @@ - + + + + - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + From f13df67efe3192d47d8427df166dc1997edb1aec Mon Sep 17 00:00:00 2001 From: Mahbubul Alam Palash Date: Mon, 30 Dec 2024 14:59:04 -0500 Subject: [PATCH 2/3] TT-113 Created a directory tools under co-simulation and added a bash script geneate_background_traffic.sh for generating background traffic for any Sumo network --- .../tools/geneate_background_traffic.sh | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 co-simulation/tools/geneate_background_traffic.sh diff --git a/co-simulation/tools/geneate_background_traffic.sh b/co-simulation/tools/geneate_background_traffic.sh new file mode 100755 index 00000000..4d31d6d0 --- /dev/null +++ b/co-simulation/tools/geneate_background_traffic.sh @@ -0,0 +1,69 @@ +#!/bin/bash +#This script will generate random traffic to be used in Sumo-carla co simulation for a any Sumo Network File given the simulation duration, number of vehicles and a random number seed +# This script requires installation of Sumo tools randomTrips.py and Python +echo "Sumo Network Files in this directoryi:" +ls *.net.xml +# Prompt for user inputs +echo +echo "Enter the Sumo Network File Name:" +read net_file + +echo "Output File Name:" +read out_file + +echo "Enter Duration of the Simulation:" +read sim_duration + +echo "How many vehicles you want to instantiate?:" +read veh_number + +echo "Enter Random Number Seed (Different Seed will genrate different traffic):" +read seed + +# Calculate the rate of vehicle generation +rate=$(echo "$sim_duration / $veh_number" | bc -l) + + +# Run the Python script with the provided inputs +python3 /usr/share/sumo/tools/randomTrips.py -n $net_file -r $out_file --fringe-factor 5 -e $sim_duration -p $rate --vehicle-class passenger --validate --random --seed $seed + + +#Changing vehicle Types matching pasenger car of CARLA +# List of Passenger vehicle classes in CARLA + +vehicle_classes=( + "vehicle.audi.a2" + "vehicle.audi.tt" + "vehicle.jeep.wrangler_rubicon" + "vehicle.chevrolet.impala" + "vehicle.mini.cooper_s" + "vehicle.mercedes.coupe" + "vehicle.bmw.grandtourer" + "vehicle.citroen.c3" + "vehicle.ford.mustang" + "vehicle.lincoln.mkz_2017" + "vehicle.seat.leon" + "vehicle.nissan.patrol" + "vehicle.nissan.micra" +) + +temp_file="temp.xml" + +# Read the generated route file line by line +while IFS= read -r line; do + if [[ "$line" == *'type="passenger"'* ]]; then + # Select a random vehicle class + random_vehicle=${vehicle_classes[$RANDOM % ${#vehicle_classes[@]}]} + # Replace type="passenger" with the random vehicle class + line=$(echo "$line" | sed "s/type=\"passenger\"/type=\"$random_vehicle\"/") + fi + # Write the updated line to a temporary file + echo "$line" >> "$temp_file" +done < "$out_file" + +# Replace the original file with the updated file +mv "$temp_file" "$out_file" +rm trips.trips.xml +echo "Route file $out_file generated" + + From 857a3655d9ef3607e575e2b5cd9b4cb3691ab963 Mon Sep 17 00:00:00 2001 From: Mahbubul Alam Palash Date: Tue, 7 Jan 2025 04:59:19 -0500 Subject: [PATCH 3/3] TT-113 updating the generate_background_traffic.sh script to take command line argumenets as well --- .../tools/geneate_background_traffic.sh | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/co-simulation/tools/geneate_background_traffic.sh b/co-simulation/tools/geneate_background_traffic.sh index 4d31d6d0..51f48454 100755 --- a/co-simulation/tools/geneate_background_traffic.sh +++ b/co-simulation/tools/geneate_background_traffic.sh @@ -1,24 +1,48 @@ #!/bin/bash #This script will generate random traffic to be used in Sumo-carla co simulation for a any Sumo Network File given the simulation duration, number of vehicles and a random number seed # This script requires installation of Sumo tools randomTrips.py and Python -echo "Sumo Network Files in this directoryi:" -ls *.net.xml -# Prompt for user inputs -echo -echo "Enter the Sumo Network File Name:" -read net_file -echo "Output File Name:" -read out_file +#Usage: +# 1. Run with arguments: +# ./generate_background_traffic.sh +# Example: ./generate_traffic.sh network.net.xml routes.rou.xml 600 50 42 +# 2. Or run interactively by omitting arguments: +# ./generate_traffic.sh -echo "Enter Duration of the Simulation:" -read sim_duration +# Checking for missing arguments +if [ "$#" -lt 5 ]; then + echo "Missing arguments. You need to provide:" + echo "1. SUMO Network File Name" + echo "2. Output File Name" + echo "3. Duration of the Simulation" + echo "4. Number of Vehicles" + echo "5. Random Number Seed" + echo -echo "How many vehicles you want to instantiate?:" -read veh_number + # Prompting for missing inputs + echo "Enter the SUMO Network File Name:" + read net_file + + echo "Enter the Output File Name:" + read out_file + + echo "Enter Duration of the Simulation:" + read sim_duration + + echo "Enter the Number of Vehicles:" + read veh_number + + echo "Enter Random Number Seed (Different Seed will generate different traffic):" + read seed +else + # Assigning inputs from command-line arguments + net_file=$1 + out_file=$2 + sim_duration=$3 + veh_number=$4 + seed=$5 +fi -echo "Enter Random Number Seed (Different Seed will genrate different traffic):" -read seed # Calculate the rate of vehicle generation rate=$(echo "$sim_duration / $veh_number" | bc -l)