# How a self-driving car decides to brake

> A process map exported from forks.world (https://forks.world). Author: Brian. Source: https://forks.world/p/cmv0kpygt000yjv06sqksgh6g
> It describes who does what, in what order, and with which technology. Read the plain-language sections first; the JSON at the end is the exact, complete data.

## Summary

- 17 steps across 2 layers
- Persona: Safety driver or passengers
- Technology / systems: Cameras, radar and lidar, The driving software, The car

## Pain points

Where this process hurts, worst first:

- **Monitor, and take over if needed** (How a self-driving car decides to brake; painful): Handoffs between a human and the software are a known risk

## How to read this file

- A process is made of **layers**. The main layer is the top level; any step of kind `subprocess` opens a detail layer with its own lanes and steps.
- **Lanes** are either persona (people/roles) or technology (systems). Each step belongs to one lane; `using` lists tools a person uses for that step.
- Step kinds: `start`, `task`, `decision` (its arrows carry the answer as a label), `subprocess`, `end`.

## How a self-driving car decides to brake

Lanes:
- Cameras, radar and lidar: technology / system (id `sensors`)
- The driving software: technology / system (id `brain`)
- The car: technology / system (id `car`)
- Safety driver or passengers: person / role (id `human`)

Steps, in the order they run:

1. **Sense the world many times a second** [start; Cameras, radar and lidar; id `s1`]
   - then Perception: where are the cars, people and lanes?
2. **Perception: where are the cars, people and lanes?** [subprocess; The driving software; id `s2`], opens the detail layer "Seeing the road"
   - then Prediction: what will each of them do next?
3. **Prediction: what will each of them do next?** [task; The driving software; id `s3`]
   - then Planning: pick a safe path
4. **Planning: pick a safe path** [task; The driving software; id `s4`]
   - then Is something in the way?
5. **Is something in the way?** [decision; The driving software; id `s5`]
   - if "Yes" go to Is the software sure what it is?; if "No" go to Continue
6. **Is the software sure what it is?** [decision; The driving software; id `s6`]
   - if "Yes" go to Brake or steer around it; if "No" go to Slow down and treat it cautiously
7. **Brake or steer around it** [task; The car; id `s7`]
   - then Monitor, and take over if needed
8. **Monitor, and take over if needed** [task; Safety driver or passengers; id `s9`] ⚠ PAIN POINT (painful): Handoffs between a human and the software are a known risk
   - then Sense the world many times a second
9. **Slow down and treat it cautiously** [task; The driving software; id `s6a`]
   - then Brake or steer around it
10. **Continue** [task; The car; id `s8`]
   - then Monitor, and take over if needed

```mermaid
flowchart LR
  subgraph l_sensors["Cameras, radar and lidar"]
    n_s1(["Sense the world many times a second"])
  end
  subgraph l_brain["The driving software"]
    n_s2[["Perception: where are the cars, people and lanes?"]]
    n_s3["Prediction: what will each of them do next?"]
    n_s4["Planning: pick a safe path"]
    n_s5{"Is something in the way?"}
    n_s6{"Is the software sure what it is?"}
    n_s6a["Slow down and treat it cautiously"]
  end
  subgraph l_car["The car"]
    n_s7["Brake or steer around it"]
    n_s8["Continue"]
  end
  subgraph l_human["Safety driver or passengers"]
    n_s9["Monitor, and take over if needed"]
  end
  n_s1 --> n_s2
  n_s2 --> n_s3
  n_s3 --> n_s4
  n_s4 --> n_s5
  n_s5 -->|"Yes"| n_s6
  n_s5 -->|"No"| n_s8
  n_s6 -->|"Yes"| n_s7
  n_s6 -->|"No"| n_s6a
  n_s6a --> n_s7
  n_s7 --> n_s9
  n_s8 --> n_s9
  n_s9 --> n_s1
```

### Seeing the road (detail of step "Perception: where are the cars, people and lanes?")

Lanes:
- Cameras, radar and lidar: technology / system (id `sensors`)
- The driving software: technology / system (id `brain`)

Steps, in the order they run:

1. **Cameras see color and signs** [start; Cameras, radar and lidar; id `p1`]
   - then Radar measures speed in rain and fog
2. **Radar measures speed in rain and fog** [task; Cameras, radar and lidar; id `p2`]
   - then Lidar builds a 3D shape map
3. **Lidar builds a 3D shape map** [task; Cameras, radar and lidar; id `p3`]
   - then Fuse them into one picture
4. **Fuse them into one picture** [task; The driving software; id `p4`]
   - then Do the sensors disagree?
5. **Do the sensors disagree?** [decision; The driving software; id `p5`]
   - if "Yes" go to Trust the safest reading; if "No" go to A clean view of the road
6. **Trust the safest reading** [task; The driving software; id `p6`]
   - then A clean view of the road
7. **A clean view of the road** [end; The driving software; id `p7`]

```mermaid
flowchart LR
  subgraph l_sensors["Cameras, radar and lidar"]
    n_p1(["Cameras see color and signs"])
    n_p2["Radar measures speed in rain and fog"]
    n_p3["Lidar builds a 3D shape map"]
  end
  subgraph l_brain["The driving software"]
    n_p4["Fuse them into one picture"]
    n_p5{"Do the sensors disagree?"}
    n_p6["Trust the safest reading"]
    n_p7(["A clean view of the road"])
  end
  n_p1 --> n_p2
  n_p2 --> n_p3
  n_p3 --> n_p4
  n_p4 --> n_p5
  n_p5 -->|"Yes"| n_p6
  n_p5 -->|"No"| n_p7
  n_p6 --> n_p7
```

## Full data (JSON)

```json
{
  "title": "How a self-driving car decides to brake",
  "maps": {
    "m_root": {
      "id": "m_root",
      "lanes": [
        {
          "id": "sensors",
          "name": "Cameras, radar and lidar",
          "type": "system"
        },
        {
          "id": "brain",
          "name": "The driving software",
          "type": "system"
        },
        {
          "id": "car",
          "name": "The car",
          "type": "system"
        },
        {
          "id": "human",
          "name": "Safety driver or passengers",
          "type": "person"
        }
      ],
      "steps": [
        {
          "id": "s1",
          "kind": "start",
          "lane": "sensors",
          "next": [
            {
              "to": "s2"
            }
          ],
          "uses": [],
          "label": "Sense the world many times a second"
        },
        {
          "id": "s2",
          "kind": "subprocess",
          "lane": "brain",
          "next": [
            {
              "to": "s3"
            }
          ],
          "uses": [],
          "child": "m_percept",
          "label": "Perception: where are the cars, people and lanes?"
        },
        {
          "id": "s3",
          "kind": "task",
          "lane": "brain",
          "next": [
            {
              "to": "s4"
            }
          ],
          "uses": [],
          "label": "Prediction: what will each of them do next?"
        },
        {
          "id": "s4",
          "kind": "task",
          "lane": "brain",
          "next": [
            {
              "to": "s5"
            }
          ],
          "uses": [],
          "label": "Planning: pick a safe path"
        },
        {
          "id": "s5",
          "kind": "decision",
          "lane": "brain",
          "next": [
            {
              "to": "s6",
              "label": "Yes"
            },
            {
              "to": "s8",
              "label": "No"
            }
          ],
          "uses": [],
          "label": "Is something in the way?"
        },
        {
          "id": "s6",
          "kind": "decision",
          "lane": "brain",
          "next": [
            {
              "to": "s7",
              "label": "Yes"
            },
            {
              "to": "s6a",
              "label": "No"
            }
          ],
          "uses": [],
          "label": "Is the software sure what it is?"
        },
        {
          "id": "s6a",
          "kind": "task",
          "lane": "brain",
          "next": [
            {
              "to": "s7"
            }
          ],
          "uses": [],
          "label": "Slow down and treat it cautiously"
        },
        {
          "id": "s7",
          "kind": "task",
          "lane": "car",
          "next": [
            {
              "to": "s9"
            }
          ],
          "uses": [],
          "label": "Brake or steer around it"
        },
        {
          "id": "s8",
          "kind": "task",
          "lane": "car",
          "next": [
            {
              "to": "s9"
            }
          ],
          "uses": [],
          "label": "Continue"
        },
        {
          "id": "s9",
          "kind": "task",
          "lane": "human",
          "next": [
            {
              "to": "s1"
            }
          ],
          "pain": {
            "note": "Handoffs between a human and the software are a known risk",
            "level": 2
          },
          "uses": [],
          "label": "Monitor, and take over if needed"
        }
      ],
      "title": "How a self-driving car decides to brake",
      "parent": null
    },
    "m_percept": {
      "id": "m_percept",
      "lanes": [
        {
          "id": "sensors",
          "name": "Cameras, radar and lidar",
          "type": "system"
        },
        {
          "id": "brain",
          "name": "The driving software",
          "type": "system"
        }
      ],
      "steps": [
        {
          "id": "p1",
          "kind": "start",
          "lane": "sensors",
          "next": [
            {
              "to": "p2"
            }
          ],
          "uses": [],
          "label": "Cameras see color and signs"
        },
        {
          "id": "p2",
          "kind": "task",
          "lane": "sensors",
          "next": [
            {
              "to": "p3"
            }
          ],
          "uses": [],
          "label": "Radar measures speed in rain and fog"
        },
        {
          "id": "p3",
          "kind": "task",
          "lane": "sensors",
          "next": [
            {
              "to": "p4"
            }
          ],
          "uses": [],
          "label": "Lidar builds a 3D shape map"
        },
        {
          "id": "p4",
          "kind": "task",
          "lane": "brain",
          "next": [
            {
              "to": "p5"
            }
          ],
          "uses": [],
          "label": "Fuse them into one picture"
        },
        {
          "id": "p5",
          "kind": "decision",
          "lane": "brain",
          "next": [
            {
              "to": "p6",
              "label": "Yes"
            },
            {
              "to": "p7",
              "label": "No"
            }
          ],
          "uses": [],
          "label": "Do the sensors disagree?"
        },
        {
          "id": "p6",
          "kind": "task",
          "lane": "brain",
          "next": [
            {
              "to": "p7"
            }
          ],
          "uses": [],
          "label": "Trust the safest reading"
        },
        {
          "id": "p7",
          "kind": "end",
          "lane": "brain",
          "next": [],
          "uses": [],
          "label": "A clean view of the road"
        }
      ],
      "title": "Seeing the road",
      "parent": {
        "map": "m_root",
        "step": "s2"
      }
    }
  }
}
```
