Skip to content

Driving Example

Overview

The SightLab Driving Simulation provides a flexible platform for creating and customizing driving experiences. Located in the ExampleScripts-Driving folder, it supports various hardware configurations including desktop, VR headsets, and custom input devices.

Features

Core Features

  • Modifiable car models and environments
  • Realistic vehicle controls (gas, brake, steering)
  • Real-time collision detection
  • Interactive headlights system
  • Dynamic engine audio with speed-based pitch adjustment
  • Elevation and ramp support
  • Variable Speed Control
  • HUD display of speed, fixations, timestamp
  • Multi-user capabilities

Analysis Features

  • Driver attention and fixation tracking
  • Car velocity, position and rotation saved to data files (can add custom data as well)
  • Interactive session replay
  • Gaze pattern visualization
  • Performance metrics logging
  • Physiological tracking integration
  • Heat map analysis
  • Instructor view with real time control and monitoring

Environmental Features

  • Day/Night/Fog cycles
  • Variable lighting conditions
  • Traffic simulation
  • 360° media integration
  • Customizable obstacles and pedestrians

Included Scripts

Driving_GUI.py uses the GUI version

Driving_GUI_Jeep.py shows a car with a steering wheel that turns based on the car turning

Driving_GUI_Classic.py is regular version with classic car and wheel doesn't move

Driving_example.py uses only code, but has similar functionality to Driving_GUI

Driving_GUI_Traffic.py shows adding some cross traffic flow. Can modify the code to adjust speed and number of additional cars. Uses collision detection to check whether your vehicle collides with any others.

Driving_Ramps.py (additional download) - shows driving over elevations

Driving_Simulator_360 (additional download) - shows using a 360 video to simulate driving in New York

Controls

Desktop Controls

  • Movement: WASD keys
  • Gas: = key
  • Brake: - key
  • View adjustment: T, F, G, H keys
  • Start/Next trial: Spacebar

VR Controls

General VR

  • Steering: Left Stick- Turn left or right
  • Gas: Right Trigger
  • Brake: Left Trigger
  • Reverse: Hold B while pressing the gas or the brake
  • View adjustment: WASD, X, and Z keys

XBOX/Game Controller

  • Steering: Left Stick- Turn left or right
  • Gas: Right Trigger
  • Brake: Left Trigger
  • Reverse: Hold X while pressing the gas or the brake
  • Look Around: Right stick or use the mouse

SteamVR/Vive Specific

  • Steering: RH trackpad (left/right)
  • Gas: RH system button
  • Brake: RH grip button

Running the GUI Example

Pressing spacebar will start the experiment or proceed to the next trial. Trial 1 shows a daytime cycle, while Trial 2 shows a nighttime cycle with the car headlights toggled on. Trial 3 goes back to the Day Cycle. This can all be modified (see below).

Session Replay

After running a session, use SessionReplay to view a playback of your session, including the car's movement.

Customization

Changing the Environment

  1. Place a new environment file in the Resources/environments folder.
  2. (for the GUI) Select the new environment using the GUI:

    • Click "Modify" on the GUI screen
    • Choose the new environment
  3. With code

ENVIRONMENT_MODEL = 'path/to/environment.osgb' 
vizfx.addChild(ENVIRONMENT_MODEL)

Changing the Vehicle

Change the path to your new vehicle when calling the car class

my_car = Car(model_path=CAR_MODEL, use_headlights=True, steering_wheel_name=STEERING_WHEEL_NAME, engine_audio=ENGINE_AUDIO)

Basic Setup Using Code

  1. Import car class from module (make sure car_module.py exists next to your main script):
from car_module import Car
  1. Set up the car instance:
    CAR_MODEL = 'Resources/jeepmodel.osgb' 
    STEERING_WHEEL_NAME = 'Steering_Real Car 22_Body_0' 
    ENGINE_AUDIO = 'Resources/engine_sound8.wav' 
    
    my_car = Car(model_path=CAR_MODEL, use_headlights=True,    steering_wheel_name=STEERING_WHEEL_NAME,engine_audio=ENGINE_AUDIO )
    
    Code to access underlying car object
    car = my_car.car
    
  2. Add car as a sceneObject so that it will be tracked in the session replay
    sightlab.addSceneObject("car", car)
    
  3. Start the engine sound and perform other setup actions (such as toggling on headlights if needed) after the SightLab main loop starts

def sightLabExperiment():
    while True:
        for i in range(sightlab.getTrialCount()):
            if sightlab.getTrialNumber() == 1:
                print('trial 1 day')
            elif sightlab.getTrialNumber() == 2:
                print('trial 2 night')
                my_car.toggle_headlights(True)
            yield viztask.waitKeyDown(' ')
            yield sightlab.startTrial()
            my_car.start_engine_sound(volume=1)
5. Setup the link of the driving transport to the car
rawTransport = vizconnect.getRawTransport('driving')
transport = vizconnect.getTransport('driving')
transportNode = transport.getNode3d()
my_car.link_to_transport(transportNode)
#Optionally change position of transport
transportNode.setPosition([0.25, 0.65, 0.35])

Changing View Position in Car

  1. Run the script using the Vizard editor and use either the TFGH, ZX keys to position your viewpoint if Desktop or WASD, ZX for HMD
  2. Press the 'v' key when your position looks correct
  3. This will print out your current position in the Vizard interactive window
  4. Copy and paste this position into the code below after "tranportNode2.setPosition" depending on which hardware you are using
if sightlab.getConfig() in ['Driving Desktop']:
    transportNode2.setPosition([0.25, 0.65, 0.35])

elif sightlab.getConfig() in ['Driving SteamVR']:
    transportNode2.setPosition([0.188, 1.315, 0.8676])

Car Class Configuration

The Car class provides extensive customization options:

class Car:
    def __init__(self, model_path, use_headlights=True, steering_wheel_name=None, engine_audio=None):
        #Speed Settings
        self.model_path = model_path
        self.car = vizfx.addChild(model_path)
        self.car.disable(viz.INTERSECTION)
        self.use_headlights = use_headlights
        self.steering_wheel_name = steering_wheel_name
        self.engine_sound = viz.addAudio(engine_audio) if engine_audio else None
        self.headlights = {}
        self.current_speed = 1
        self.max_speed = 20
        self.min_speed = 0
        self.acceleration_rate = 1
        self.deceleration_rate = 1
        self.acceleration_interval = 0.5
        self.deceleration_interval = 0.3
        self.is_accelerating = False
        self.is_decelerating = False
        self.transport_node = None

        # Velocity tracking
        self.previous_position = None
        self.previous_time = None
        self.velocity_x = 0
        self.velocity_y = 0
        self.velocity_z = 0

        self.is_coasting = False  # Track if the car is coasting
        self.coasting_rate = 0.1  # Gradual deceleration rate during coasting
        self.coasting_interval = 0.1  # Time interval for coasting updates
        self.braking_rate = 2.0  # Stronger deceleration rate during braking

Key parameters:

  • model_path: Path to the 3D car model file
  • use_headlights: Enable/disable headlight functionality
  • steering_wheel_name: Name of the steering wheel node in the model
  • engine_audio: Path to engine sound file

Saving velocity and position data

Add this code to your script (added in template scripts)

sightlab.addTrackingTrialDataColumn("my_car", my_car, dataType=SIXDOFmode=viz.ABS_GLOBAL)
    def saveVelocity():
            my_car.update_velocity()  # Properly invoke the update_velocity method
            carVelocity = my_car.get_velocity()
            my_car.update_hud()
            # Round the velocity values to 4 decimal places
            velocity_x = round(carVelocity[0], 4)
            velocity_y = round(carVelocity[1], 4)
            velocity_z = round(carVelocity[2], 4)

            # Save rounded values to custom trial data
            sightlab.setCustomTrialData(str(velocity_x), 'Car Velocity X')
            sightlab.setCustomTrialData(str(velocity_y), 'Car Velocity Y')
            sightlab.setCustomTrialData(str(velocity_z), 'Car Velocity Z')
        vizact.onupdate(0,saveVelocity)

Customizing Controls

  1. Navigate to the vizconnect file in util_files/sightlab_utils/vizconnect_configs.
  2. Go to Advanced > Transports > Driving > Mappings and Acceleration/Deceleration under "Events".
  3. Modify the mappings as needed.

Note: You may need to set permissions on the file to edit the vizconnect.

Using Alternative Input Devices

You can connect various joysticks, such as a driving wheel or game controller:

  1. In vizconnect, add a generic or direct input joystick as an input.
  2. For more information, refer to the joystick connection documentation.

Advanced Versions

Contact sales@worldviz.com for information on advanced versions:

  1. Version that shows driving over elevations and ramps
  2. 360 video driving simulator (combining 3D models and 360 videos)
  3. Flying simulator

Adding Ramps/Elevation Detection (SightLab 1.9.8 or higher)

  1. Add this line at the top of your script:
from sightlab_utils import collision
  1. After the "updateCarTransform" function, add:
c = collision.Collision()

360 Driving Simulator Instructions (Available Upon Request)

Controls

  • Reset Position: R key
  • Start/Stop Simulation: Spacebar
  • Pause Video: V key
  • Reset Video: B key
  • Fast Forward: F key
  • Get Current Position: T key
  • Toggle Overlays: H key
  • Toggle Gaze Point: P key
  • Take Screenshot: / key

Notes