Skip to content

Commit

Permalink
Merge pull request #626 from Qi-Zha0/noetic-devel
Browse files Browse the repository at this point in the history
generate traffic
  • Loading branch information
sergiopaniego authored Sep 11, 2023
2 parents 683bec9 + 65d3c2e commit cd04eb8
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 8 deletions.
78 changes: 78 additions & 0 deletions behavior_metrics/configs/default_carla_traffic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Behaviors:
Robot:
Sensors:
Cameras:
Camera_0:
Name: 'camera_0'
Topic: '/carla/ego_vehicle/rgb_front/image'
Camera_1:
Name: 'camera_1'
Topic: '/carla/ego_vehicle/rgb_view/image'
Camera_2:
Name: 'camera_2'
Topic: '/carla/ego_vehicle/semantic_segmentation_front/image'
Camera_3:
Name: 'camera_3'
Topic: '/carla/ego_vehicle/dvs_front/image'
Pose3D:
Pose3D_0:
Name: 'pose3d_0'
Topic: '/carla/ego_vehicle/odometry'
BirdEyeView:
BirdEyeView_0:
Name: 'bird_eye_view_0'
Topic: ''
Speedometer:
Speedometer_0:
Name: 'speedometer_0'
Topic: '/carla/ego_vehicle/speedometer'
Actuators:
CARLA_Motors:
Motors_0:
Name: 'motors_0'
Topic: '/carla/ego_vehicle/vehicle_control_cmd'
MaxV: 3
MaxW: 0.3
BrainPath: 'brains/CARLA/brain_carla_bird_eye_deep_learning.py'
PilotTimeCycle: 50
AsyncMode: False
Parameters:
Model: '20230126-183457_deepestLSTMTinyPilotNet_CARLA_14_12_dataset_bird_eye_400_epochs_no_flip_3_output_both_directions_all_towns__less_learning_rate_PAPER_cp.h5'
ImageCropped: True
ImageSize: [ 100,50 ]
ImageNormalized: True
PredictionsNormalized: True
GPU: True
UseOptimized: True
ImageTranform: ''
Type: 'CARLA'
Simulation:
World: configs/CARLA_launch_files/town_01_anticlockwise.launch
RandomSpawnPoint: False
NumberOfVehicle: 50
NumberOfWalker: 50
PercentagePedestriansRunning: 0.5
PercentagePedestriansCrossing: 0.5
Dataset:
In: '/tmp/my_bag.bag'
Out: ''
Stats:
Out: './'
PerfectLap: './perfect_bags/lap-simple-circuit.bag'
Layout:
Frame_0:
Name: frame_0
Geometry: [1, 1, 1, 1]
Data: rgbimage
Frame_1:
Name: frame_1
Geometry: [0, 1, 1, 1]
Data: rgbimage
Frame_2:
Name: frame_2
Geometry: [0, 2, 1, 1]
Data: rgbimage
Frame_3:
Name: frame_3
Geometry: [1, 2, 1, 1]
Data: rgbimage
12 changes: 10 additions & 2 deletions behavior_metrics/driver_carla.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
import glob
import json

from pilot_carla import PilotCarla

from ui.tui.main_view import TUI
from utils import environment
from utils.traffic import TrafficManager
from utils.colors import Colors
from utils.configuration import Config
from utils.controller_carla import ControllerCarla
from utils.logger import logger
from utils.tmp_world_generator import tmp_world_generator
from utils import metrics_carla
from datetime import datetime
from pilot_carla import PilotCarla

import matplotlib.pyplot as plt
import pandas as pd


def check_args(argv):
"""Function that handles argument checking and parsing.
Expand Down Expand Up @@ -281,6 +282,12 @@ def main():
if not config_data['script']:
environment.launch_env(app_configuration.current_world, random_spawn_point=app_configuration.experiment_random_spawn_point, carla_simulator=True)
controller = ControllerCarla()
traffic_manager = TrafficManager(app_configuration.number_of_vehicle,
app_configuration.number_of_walker,
app_configuration.percentage_walker_running,
app_configuration.percentage_walker_crossing,
app_configuration.async_mode)
traffic_manager.generate_traffic()

# Launch control
if hasattr(app_configuration, 'experiment_model'):
Expand All @@ -293,6 +300,7 @@ def main():
logger.info('Executing app')
main_win(app_configuration, controller)
logger.info('closing all processes...')
traffic_manager.destroy()
pilot.kill_event.set()
environment.close_ros_and_simulators()
else:
Expand Down
2 changes: 2 additions & 0 deletions behavior_metrics/pilot_carla.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def run(self):
time.sleep((self.time_cycle - ms) / 1000.0)
self.real_time_factors.append(self.real_time_factor)
self.brain_iterations_simulated_time.append(self.ros_clock_time - start_time_ros)
if not self.async_mode:
self.controller.world.tick()
self.execution_completed = True
self.kill()
logger.info('Pilot: pilot killed.')
Expand Down
10 changes: 7 additions & 3 deletions behavior_metrics/robot/interfaces/birdeyeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ def __init__(self):
client, # carla.Client
target_size=PixelDimensions(width=100, height=300),
pixels_per_meter=10,
render_lanes_on_junctions=True,
crop_type=BirdViewCropType.FRONT_AREA_ONLY
)

def getImage(self, vehicle):
birdview = self.birdview_producer.produce(
agent_vehicle=vehicle # carla.Actor (spawned vehicle)
)
try:
birdview = self.birdview_producer.produce(
agent_vehicle=vehicle # carla.Actor (spawned vehicle)
)
except Exception as ex:
print(ex)
# Mask to RGB image
image = BirdViewProducer.as_rgb(birdview)
return image
17 changes: 17 additions & 0 deletions behavior_metrics/utils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ def initialize_configuration(self, config_data):
self.spawn_points = config_data['Behaviors']['Simulation']['SpawnPoints']
else:
self.spawn_points = []

if 'NumberOfVehicle' in config_data['Behaviors']['Simulation']:
self.number_of_vehicle = config_data['Behaviors']['Simulation']['NumberOfVehicle']
else:
self.number_of_vehicle = 0
if 'NumberOfWalker' in config_data['Behaviors']['Simulation']:
self.number_of_walker = config_data['Behaviors']['Simulation']['NumberOfWalker']
else:
self.number_of_walker = 0
if 'PercentagePedestriansRunning' in config_data['Behaviors']['Simulation']:
self.percentage_walker_running = config_data['Behaviors']['Simulation']['PercentagePedestriansRunning']
else:
self.percentage_walker_running = 0.0
if 'PercentagePedestriansCrossing' in config_data['Behaviors']['Simulation']:
self.percentage_walker_crossing = config_data['Behaviors']['Simulation']['PercentagePedestriansCrossing']
else:
self.percentage_walker_crossing = 0.0

if self.robot_type == 'f1rl':
self.action_set = robot['Parameters']['action_set']
Expand Down
3 changes: 0 additions & 3 deletions behavior_metrics/utils/controller_carla.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
import rosbag
import json
import math

from utils.logger import logger
try:
import carla
except ModuleNotFoundError as ex:
logger.error('CARLA is not supported')

from std_srvs.srv import Empty
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
Expand All @@ -45,7 +43,6 @@
except ModuleNotFoundError as ex:
logger.error('CARLA is not supported')
from PIL import Image

__author__ = 'sergiopaniego'
__contributors__ = []
__license__ = 'GPLv3'
Expand Down
Loading

0 comments on commit cd04eb8

Please sign in to comment.