# donkeycar_sb3_runner.py - Documentation

This script is a robust Stable-Baselines3 RL agent for DonkeyCar
with support for multiple consecutive episodes in one connection.

## Typical invocation:

    python3 donkeycar_sb3_runner.py

- Connects once to DonkeyCar sim (port 9091)
- Runs EPISODES consecutive RL episodes (edit in script)
- Calls env.reset() each time to start a new episode
- Random action for demonstration; replace action policy as needed
- Calls env.close() and sleeps 2 seconds before exit

## Usage:
- Intended to be called by batch script for robust automation
- Always ensure sim is running, agent is cleanly closed between runs

## Key logic block in main():

    for episode in range(EPISODES):
        obs = env.reset()
        done = False
        while not done:
            action = env.action_space.sample()
            obs, reward, done, *_ = env.step(action)
    env.close()

## Troubleshooting:
- If car disappears or sim blanks after batch, ensure no stuck python process
- Wait 2+ seconds after run before restarting process
- If stuck, restart Unity sim
