This repository contains a suite of Python scripts designed to interface with the CARLA Simulator. It is designed to generate ego-relative LiDAR point clouds and 3D bounding boxes for training autonomous driving perception models to detect False Data Injection (FDI) attacks.
spawn_traffic.pyPopulates the CARLA map with rule-abiding background traffic. It interfaces directly with the CARLA Traffic Manager and syncs with the simulation clock. All spawned vehicles are forced to drive perfectly (no erratic lane changes, strict adherence to speed limits) to establish a controlled baseline environment.self_drive_tesla.pyActs as the autonomous controller for the Ego Vehicle. It handles the routing and driving logic for the target Tesla, allowing the data collection scripts to passively record the environment as the car navigates the map.
baseline_dataset_generator_traffic.pyThe clean data collector. Records the ego-vehicle driving through the traffic-populated environment without any adversarial attacks present. Background traffic bounding boxes are explicitly labeled as Class 1 (c = 1.0).adversarial_generator_setting1.pyRuns the core False Data Injection simulation in an isolated environment. Uses a dynamic timer to spawn and despawn a spoofed "ghost" vehicle directly in front of the ego vehicle to simulate a sudden sensor spoofing attack.adversarial_generator_setting1_traffic.pyThe Master Attack Spawner. Combines the FDI attack logic with the background traffic environment. It records standard traffic as Class 1, and explicitly labels the spoofed ghost vehicle as Class 2 (c = 2.0) so the perception model can learn to classify the anomaly.adversarial_generator_setting2.pyGenerates adversarial sequences under "Setting 2" parameters, altering the attack duration and deployment window to test the ML model's temporal sliding window memory.
dataset_viewer_v2.pyA custom Matplotlib 3D visualizer built to verify coordinate matrix transformations. It parses the dynamically generated datasets, renders the point clouds in a high-contrast White Mode, and draws mathematically exact 3D wireframe boxes around the vehicles. Standard traffic is boxed in Blue, while spoofed attacks are boxed in Red with an explicit[STATUS: SPOOFED]warning in the title.
All generator scripts output synchronized folders containing the following structures for OpenPCDet ingestion:
-
snapshot_XXX.npy: The ego-relative LiDAR point cloud for the 100ms sweep. -
bboxes_XXX.npy: An$N \times 10$ array containing the 3D bounding boxes for all vehicles within a 50-meter radius, mathematically transformed to match the ego-LiDAR coordinate frame:[x, y, z, l, w, h, theta, vx, vy, class]. -
snapshot_XXX_ghost.npy: (Adversarial scripts only) Isolated point cloud clusters representing the spoofed vehicle. -
labels.csv: A comprehensive index logging the file paths, attack status, and the Ego Vehicle's global position and absolute speed per frame.
To ensure proper synchronization with the CARLA server, execute the scripts in the following order across separate terminal instances:
- Launch the CARLA Server.
- Run
python3 self_drive_tesla.pyto spawn and route the Ego Vehicle. - (Optional) Run
python3 spawn_traffic.pyto populate the map. - Run your chosen Generator Script (e.g.,
python3 adversarial_generator_setting1_traffic.py) to begin the collection loop. - Use
python3 dataset_viewer_v2.pyto inspect the generated arrays.