PROJECT STUDY

Mining Fatigue Guard

Alarm in the cab, action in the control room.

In-cab fatigue and driving monitoring for open-pit haul trucks: a microsleep alarm in the cab and a control-room console where supervisors see, acknowledge and act on each alarm.

Explore the build
Dark control-room illustration: a live alert queue with an unacknowledged critical microsleep alert for truck HT-07 on Ramp B above an acknowledged overspeed warning for HT-11, beside a pit map and a fleet list that pairs each truck's status with a shape and a label.
Original interface illustration · Synthetic demo data.View larger

At a glance

Industry
Mining
Capabilities
8
Technologies
14
Year
2026

The challenge

A microsleep at the wheel of a loaded haul truck can end in a serious incident, and nobody in the control room can watch every cab.

Operators in Indonesian open-pit coal mines drive 10 to 12 hour shifts, many of them at night, while eyes off the road, a phone in the hand, overspeeding on a ramp or a stop in the wrong place add to the risk.

Mining Fatigue Guard makes the safety decision in the cab, where the cab agent sounds the alarm as soon as the eyes have stayed closed for half a second. It then gives supervisors one console to see, acknowledge and answer every alarm across the fleet, and no alarm is lost when the pit network drops.

What we built

A cab agent, a site server and a control-room console work as one system, with a simulator that drives a synthetic fleet for the demo and the tests.

In-cab fatigue detection

Face landmarks from MediaPipe Face Landmarker give eye closure, blinks, PERCLOS, yawning and head pose against each operator's own baseline. A microsleep (eyes closed for 0.5 s by default) sounds the cab alarm while the eyes are still closed, and head nods, eyes off the road and an operator the camera cannot see raise their own alerts

In-cab fatigue detection

Face landmarks from MediaPipe Face Landmarker give eye closure, blinks, PERCLOS, yawning and head pose against each operator's own baseline. A microsleep (eyes closed for 0.5 s by default) sounds the cab alarm while the eyes are still closed, and head nods, eyes off the road and an operator the camera cannot see raise their own alerts

Phone use while driving

A YOLOX-Nano detector on ONNX Runtime looks for a phone near the operator three times a second, and phone use raises an alarm only while the truck is moving

Driving compliance

GNSS and accelerometer telemetry are checked against per-zone speed limits, for harsh braking and acceleration, and for stops inside no-stop zones such as a ramp or a busy junction

One alert per episode

A NORMAL, CAUTION and ALARM state machine with hysteresis, minimum durations and cooldowns turns flickering signals into episodes, so repeats raise a count on one alert instead of flooding the queue

Store-and-forward delivery

Every event is written to a SQLite outbox in the cab before it is sent, then delivered with an idempotency key, critical events first, and retried with backoff through coverage gaps

Control-room console

A live alarm queue, an SVG pit map with zones and trucks, a truck list with heartbeat status and an acknowledgement dialog that records who acted, when and how: a radio call, stopping the truck, an operator swap or a false alarm. Nuisance alarms from faulty equipment can be shelved for up to four hours, and the console runs in English and Bahasa Indonesia

Reports, fleet health and thresholds

Shift reports count alerts by hour of shift and per operator, with time to acknowledge and alarm floods. A fleet page shows heartbeats, links, outbox backlogs and the configuration each cab runs, and supervisors edit versioned, bounded thresholds that every cab fetches

Privacy by default

No video leaves the cab: events carry measurements, fatigue events add a 12-second signal trace, and a snapshot travels only when site policy allows, downscaled and face-blurred unless evidence snapshots are switched on

How it works

  1. Calibrate at shift start

    For the first 30 seconds of each shift, the agent measures the operator's open-eye ratio, blink depth, resting mouth and forward head pose, then freezes that baseline for the shift. Until it finishes, eye closure is judged against a population baseline, so an early microsleep still sounds the alarm. MediaPipe Face Landmarker supplies the landmarks from a camera or video through OpenCV, behind a replaceable landmark provider interface.

  2. Decide in the cab

    Eye aspect ratio, mouth aspect ratio, PERCLOS and head pose from OpenCV solvePnP feed the alarm state machine on every frame, and the phone detector runs three times a second. The driving rules run on the same device over GNSS and accelerometer telemetry, and the cab alarm is set on the same frame, before anything is written or sent.

  3. Deliver through coverage gaps

    A separate delivery thread sends due outbox batches and settles each event only when the site server answers accepted, duplicate or rejected; anything else is retried with backoff. Heartbeats report each cab's state, its outbox backlog and the threshold version it runs, and cabs poll for new thresholds with the version as an ETag.

  4. Act in the control room

    A FastAPI service authenticates each device against a stored token hash, stores every event once, rebuilds one alert per episode and pushes it over WebSockets to the React console. Supervisors acknowledge each alarm with the action taken, and the shift report shows alerts by hour of shift and by operator.

Engineering insights

Every safety decision is made in the cab; everything after it is built to survive a weak pit network and a busy control room.

Stack by layer

Frontend
  • React
  • TypeScript
  • Vite
  • TanStack Router
  • TanStack Query
  • ts-pattern
  • CSS Modules
  • SVG
  • Lucide icons
Backend
  • Python
  • FastAPI
  • Uvicorn
  • Pydantic
  • WebSockets
  • HTTPX
Data
  • SQLite
  • SQLAlchemy
AI
  • MediaPipe Face Landmarker
  • OpenCV
  • NumPy
  • ONNX Runtime
  • YOLOX-Nano
Infrastructure
  • uv
  • Docker Compose
  • nginx
  • pytest
  • Vitest
  • Playwright
  • Ruff
  • mypy
  • Biome
  1. A personal baseline, frozen for the shift

    Fixed eye-ratio thresholds fail across faces, glasses and camera angles, so each operator is judged against their own open and closed eyes, calibrated at shift start and then frozen: a baseline that kept learning would slowly accept drowsy eyes as normal. In the synthetic evaluation (8 synthetic operators at 15 fps), it raised no false microsleep in 8 hours of normal driving, where a fixed threshold of 0.20 raised 95, and both caught all 120 injected microsleeps

  2. Eye closure judged only facing the road

    A glance down at the dashboard lowers the eyelids much as drowsiness does, so closure counts only while the head faces the road, and head pose covers the rest: a fast head drop after closing eyes is a nod, one with open eyes is a look down. A closure starts at 80 percent and ends only after two frames below 60 percent, timed where it crossed each threshold, so one noisy frame cannot split a microsleep and the tests reach the same decision at 10, 15 and 30 fps

  3. Phone use from imperfect detections

    One detection proves little, because detectors flicker and a radio handset can look like a phone for a frame. The rule needs a phone close to the operator in 60 percent of the detector runs over 2 s while the truck moves, and clears only after four empty runs in a row, so a hand briefly covering the phone does not end and restart the episode

  4. One alarm per episode, each with a response

    Minimum durations and cooldowns turn a flickering condition into one state change, and repeats raise an occurrence count instead of new alerts. Following ANSI/ISA-18.2 alarm-management practice, only events that need a timely response require acknowledgement, slow blinks, yawning and harsh braking are recorded for coaching, and an acknowledged alert that escalates comes back for a new acknowledgement

  5. Exactly once over a dropping network

    Each event keeps its idempotency key across every retry, with equal-jitter exponential backoff capped at five minutes, and a unique constraint on the server stores it once. Alerts are rebuilt from all events of an episode in the cab's sequence order, so duplicates and reordered arrivals give the same alert, and a truck whose heartbeat stops shows as unknown, never as normal. An end-to-end test drops a quarter of the requests and a fifth of the responses and still finds every event stored exactly once

  6. Telemetry corrected for ramps and pit walls

    On a 10 percent descent gravity puts about 0.1 g on the accelerometer's forward axis, which reads like braking, so harsh braking uses filtered deceleration with the surveyed grade removed and must be confirmed by a drop in GNSS speed. Zone membership needs 5 m beyond a boundary to leave and holds its last state when a fix is less accurate than 15 m, so a truck near a high wall does not flicker between speed limits

Design system

Control room: a dark theme for rooms kept dim around the clock, built on alarm-management practice. Off-white text on a near-black blue-grey limits glare through night shifts, and colour is reserved for status, so critical, warning, normal and info each keep one meaning across the queue, the truck list and the pit map.

Colour palette

  • Night background#0b1117Page background for a control room kept dim around the clock, and the text colour on filled severity badges
  • Panel surface#111a22Panels, the top bar and the navigation rail, outlined with #22303c borders
  • Off-white text#e6edf3Primary text, softer than pure white to limit glare
  • Critical red#ff4d4fMicrosleeps, head nods, stops in a no-stop zone and the cab ALARM state; the only colour that blinks, and only while unacknowledged
  • Warning amber#ffb020Eyes off the road, phone use, rising PERCLOS, an operator the camera cannot see, overspeeding, the CAUTION state and delayed links
  • Normal green#2ecc71Trucks reporting within limits and online links, kept small so it never competes with an alarm
  • Info cyan#22d3eeRecords kept for coaching, calibration, focus rings and the selected option
  • Muted grey#8b9babSecondary text, labels and trucks whose status is unknown
  • Colour

    Status colours sit on quiet panels with thin borders, so a screen of normal trucks stays mostly grey with small green marks. Filled severity badges set dark text on the colour, and only an unacknowledged critical alarm blinks, in a one-second step that becomes a steady outline when reduced motion is on

  • Typography

    Inter Variable, bundled with the console instead of loaded from a CDN, with tabular numerals for times, speeds, counts and durations so live values keep their width as they update

  • Components

    In-house React components on CSS custom properties and CSS Modules, with no component library: the alarm queue with acknowledge and shelve dialogs on the native dialog element, an SVG pit map whose truck labels move aside to stay readable, a signal-trace chart and an hour-of-shift chart with an accessible table behind it

  • Accessibility

    Severity always pairs a shape, a colour and a text label: a diamond for critical, a triangle for warning, a filled circle for normal, a rounded square for info and a hollow dashed circle for unknown. Text and every status colour reach WCAG AA, checked in code, and every control shows a visible focus ring

Where this fits

Sites that run heavy equipment around the clock need alarms that reach the right person and a record of what was done. We build computer vision that runs at the edge, AI solutions around your safety rules and web applications for the people who respond. Talk to us about your site.

Talk to us about your site

Let’s connect the dots

Let's put these ideas to work.

Share a process, product, or problem you want to improve. We will work through the possibilities together.

Discuss your project