Day 03 The Mission
Module 3 • Sim-to-Real Deployment

Crossing the Reality Gap

Hardening your AI for terrestrial environments and SAR deployment.

Protocol 1: Domain Randomization

The simulation is "perfect." Real sensors have noise. Real motors have friction. A model trained in a perfect simulation will fail on the first rock it sees in the real world.

Visual Randomization Script

Create a new script RandomizeEnv.cs and attach it to your Cave Segment.

public override void OnEpisodeBegin() {
    // 1. Randomize Friction
    float friction = Random.Range(0.3f, 0.9f);
    GetComponent().material.dynamicFriction = friction;

    // 2. Randomize Scale (Tunnel Width)
    float width = Random.Range(0.8f, 1.2f);
    transform.localScale = new Vector3(width, 1, 1);

    // 3. Randomize Lighting (Simulate failing headlamps)
    float intensity = Random.Range(0.1f, 1.0f);
    RenderSettings.ambientIntensity = intensity;
}

Effect: The drone learns to fly in slippery, narrow, and dark caves—not just the "ideal" one.


Protocol 2: Exporting the Brain (ONNX)

Once training is complete (Mean Reward > 50), the "Brain" exists as a .onnx file.

Step 2.1: Locate the Model

Go to your project folder > results > CaveRun1 > CaveExplorer.onnx.

Drag this file into your Unity Project Assets folder.

Step 2.2: Inference Setup

  1. Select your DroneAgent prefab.
  2. In the Behavior Parameters component:
    • Model: Drag your CaveExplorer.onnx here.
    • Behavior Type: Set to Inference Only.
  3. Press Play. The drone is now flying using its trained neural network, without Python!

Protocol 3: The "Base Station" Loop

In a real SAR mission, the drone must return data. We simulate this with a "Homing" reward.

Advanced Challenge: The Return Trip

Modify CaveExplorerAgent.cs:

  1. Add a state variable: bool returningHome = false;.
  2. When the drone reaches Z=50m, toggle returningHome = true.
  3. Change the reward:
    if(returningHome) {
        // Reward for getting closer to (0,0,0)
        AddReward(-distanceToStart * 0.01f); 
    }

Congratulations!

You have developed an autonomous navigation system.

You can now take this project, change the environment (e.g. to a forest or city), and retrain the agent for your specific Team Project needs.

Return to Workshop Home