DEV Community

Cover image for BridgeSpan AI: Stopping 11-Foot-8 Overhead Collisions with Gemma 4, Edge LiDAR & Google ADK
Robina Mirbahar for Google Developer Experts

Posted on Edited on Originally published at github.com

BridgeSpan AI: Stopping 11-Foot-8 Overhead Collisions with Gemma 4, Edge LiDAR & Google ADK

Author: Robina Mirbahar

AI/ML Google Developer Expert (GDE) | Google Cloud Champion Innovator | WTM Ambassador


Everyone on the internet has watched viral videos of box trucks and semi-trailers getting their roofs peeled back like sardine cans by Durham's notorious 11-Foot-8+8 ("Can Opener") rail trestle, Boston's Storrow Drive, or Melbourne's Montague Street 3.0 m overpass.

Behind the memes sits a massive, expensive civil-engineering failure mode:

  • In the US and UK alone, thousands of low-clearance bridge strikes occur every year, halting commuter rail corridors above and costing millions in steel girder repairs.
  • Far less visible on camera, underwater hydraulic pier scour during flash-flood surges is the #1 cause of highway bridge collapse in the United States, accounting for over 50% of structural failures tracked in the US DOT FHWA National Bridge Inventory (Item 113) and HEC-18 Evaluating Scour at Bridges.
  • Meanwhile, heavy mobile cranes (42 t) and loaded semi-trailers (34.5 t) regularly cross historic trusses or stone-arch parkways rated for 15 t to 22.5 t.

If you ask a standard LLM navigation chatbot "Can my 13'-6\" truck clear that 3.89 m overpass?" or "Is Chain Bridge safe right now?", a single unit-conversion hallucination or ignored river-gauge surge turns into a physical catastrophe.

To solve this properly, I built and open-sourced BridgeSpan AI, a mobile-responsive global fleet and infrastructure safety platform powered by Google Gemma 4 (open weights), the Google Agent Development Kit (ADK), OSRM heavy-truck routing, and a 4,809-span real-world dataset assembled from the 2024 FHWA National Bridge Inventory, OpenStreetMap Overpass API, USGS Water Services, and Copernicus GloFAS.

BridgeSpan AI Live Mobile-Responsive Console


Why Raw LLMs Fail on Physical Bridge Safety

When I tested unguarded prompts on real bridge-dispatch scenarios, three failure patterns appeared immediately:

  1. Imperial (ft-in) vs. Metric (m) Arithmetic Traps: North American trailers declare height in feet and inches (13'-6" = 4.115 m), while urban underpasses in Europe, Australia, Azerbaijan, and Pakistan post signs in meters (3.95 m or 3.0 m). Safe civil clearance also requires a mandatory 0.15 m (6 in) dynamic suspension bounce and asphalt-overlay buffer. An LLM that compares 4.11 m against 4.15 m without the bounce buffer approves a roof strike at highway speed.
  2. Silent Structural Overload: A 12'-0" mobile crane (42.0 metric tons) easily clears a 14'-2" historic steel truss vertically, so height-only checks wave it through even when the span's FHWA Item 064 Operating Rating is capped at 22.5 metric tons.
  3. Blindness to Live River Pier Scour: During heavy rain or monsoon surges, a bridge deck looks dry and unobstructed on GPS maps while fast-moving water erodes riverbed sediment from beneath FHWA Item 113 scour-critical pier footings.

System Architecture: Gemma 4 + Deterministic 4-Gate Civil Interlocks

In safety-critical physical engineering, an LLM should orchestrate tools and explain telemetry, never hold unchecked authority over structural limits.

┌──────────────────────────────────────────────────────────────────────┐
│      BridgeSpan AI Mobile-Responsive Fleet Safety Command UI         │
│   8 Global Corridors (US • AU • AZ • PK) + Dark Leaflet OSRM Map     │
└──────────────────────────────────┬───────────────────────────────────┘
                                   │
                                   ▼
┌──────────────────────────────────────────────────────────────────────┐
│            Google ADK LlmAgent (Gemma 4 via LiteLLM)                 │
│  1. get_bridge_structural_profile() -> Clearance, Item 064, Item 113 │
│  2. get_live_river_scour_and_wind() -> USGS 15-min + GloFAS Gusts    │
│  3. compute_safe_bridge_dispatch()  -> Hard Civil Interlock Engine   │
└──────────────────────────────────┬───────────────────────────────────┘
                                   │
                                   ▼
┌──────────────────────────────────────────────────────────────────────┐
│          4-Gate Deterministic Civil Safety Interlocks (Python)       │
│  • GATE 1 (Clearance): parse_height_m + 0.15m bounce > posted_m      │
│  • GATE 2 (Axle Mass): gross_tons > FHWA Item 064 operating_tons     │
│  • GATE 3 (Pier Scour): Item 113 critical & surge >= +1.80m -> LOCK  │
│  • GATE 4 (Crosswind): high-sided & gust >= 65 km/h -> CLAMP 50km/h  │
└──────────────────────────────────┬───────────────────────────────────┘
                                   │
                                   ▼
┌──────────────────────────────────────────────────────────────────────┐
│     Live Overhead Highway LED Gantry Sign + Safe OSRM Truck Bypass   │
└──────────────────────────────────────────────────────────────────────┘
Enter fullscreen mode Exit fullscreen mode

1. Killing the #1 Cause of Bridge Strikes: Deterministic ft-in to m Parsing

Instead of letting an LLM convert "13'-6\"" or "12'4\"" in token space, bridgespan_agent/guardrails.py parses every Imperial and Metric notation deterministically and adds the 0.15 m (6 in) dynamic suspension bounce margin before evaluating clearance:

import re

DYNAMIC_BOUNCE_BUFFER_M = 0.15  # Mandatory 6-inch suspension bounce & repaving buffer

def parse_height_to_meters(raw_height: str | float) -> float:
    """Deterministically parse '13'-6\"', '13ft 6in', '3.89 m', or '389 cm' into meters."""
    text = str(raw_height or "").strip().lower()

    imp_match = re.match(
        r"^\s*(\d+(?:\.\d+)?)\s*(?:'|ft|feet|foot)\s*[-\s]*(\d+(?:\.\d+)?)?\s*(?:\"|''|in|inch|inches)?\s*$",
        text,
    )
    if imp_match:
        feet = float(imp_match.group(1))
        inches = float(imp_match.group(2)) if imp_match.group(2) is not None else 0.0
        if inches >= 12.0:
            raise ValueError(f"Invalid inches ({inches}) in {raw_height!r}")
        return round((feet * 12.0 + inches) * 0.0254, 3)

    # Metric meters / centimeters handling ...
Enter fullscreen mode Exit fullscreen mode

When a driver declares 13'-6" (4.115 m) approaching Durham's Gregson Street trestle (12'-4" / 3.76 m), the guardrail computes:

Effective Margin = 3.76 m - (4.115 m + 0.15 m bounce) = -0.505 m (STRIKE PREVENTED)
Enter fullscreen mode Exit fullscreen mode

Gate 1 trips immediately (DIVERT_OVERHEIGHT_STRIKE_PREVENTED), updates the overhead LED highway gantry sign (OVERHEIGHT 13'-6" (4.12m) -> DIVERT RIGHT NOW), and reroutes the truck onto the verified OSRM high-clearance arterial bypass.


2. Enforcing Axle Mass, Pier Flood-Scour & Crosswind Rollover Clamps

Inside evaluate_bridge_interlocks(), all four civil-engineering invariants execute in strict safety priority order:

if scour_tripped:          # Item 113 scour-critical pier + >= 1.80 m river stage surge
    status = "CLOSE_BRIDGE_SCOUR_INTERLOCK"
    use_detour = True
elif height_tripped:       # Vehicle height + 0.15 m bounce > posted clearance
    status = "DIVERT_OVERHEIGHT_STRIKE_PREVENTED"
    use_detour = True
elif weight_tripped:       # Gross vehicle tons > FHWA Item 064 operating rating
    status = "DIVERT_OVERWEIGHT_LOAD_LIMIT"
    use_detour = True
elif wind_tripped:         # High-sided trailer + >= 65 km/h deck gust (e.g., Baku Khazri)
    status = "PROCEED_CLAMP_SPEED_50KMH"
    use_detour = False
    approved_speed = 50
else:
    status = "CLEAR_PRIMARY_ROUTE"
Enter fullscreen mode Exit fullscreen mode

I also attached a Google ADK before_tool_callback (bridge_adk_before_tool_guardrail) directly to the LlmAgent so out-of-bounds tool arguments are sanitized before tool execution, and every final response is validated against the Pydantic v2 BridgeDispatchAdvisory schema.


3. Freight Decarbonization Impact (Carbone 4 & Sustainable Logistics Alignment)

Preventing bridge strikes and unscheduled corridor shutdowns is also a measurable freight-emissions win. As documented in heavy-transport decarbonization frameworks by Carbone 4 (Freight & Heavy Mobility Decarbonization) and the Smart Freight Centre GLEC Framework (ISO 14083):

  • A single low-clearance bridge strike triggers multi-hour highway and rail gridlock, forcing hundreds of diesel heavy-duty vehicles (~0.85 to 1.10 kg CO2e per vehicle-km) into stop-and-go idling.
  • Pre-trip deterministic OSRM routing onto a verified +1.07 km high-clearance arterial bypass eliminates catastrophic emergency backtracks (15+ km urban reversals), cranes, and steel girder replacement embodied carbon.
  • Pairing scale-to-zero serverless compute on Google Cloud Run with compact open-weights Gemma 4 models minimizes cloud inference energy overhead when no active dispatch queries are running.

4. Assembling a 100% Real Global Dataset (Zero Synthetic Toy Rows)

Rather than inventing fake bridges, I built an automated multi-source ingestion pipeline (collect_bridgespan_dataset.py) pulling from 5 authoritative public APIs and published both the dataset and a runnable starter notebook on Kaggle:

Table Records Real Public Source
fhwa_nbi_2024_hazard_bridges.csv 4,500 Official 2024 US DOT FHWA National Bridge Inventory (NC, NY, MA, PA, DC, MD) with exact clearances, tonnage ratings & Item 113 scour codes
osm_global_low_clearance_bridges.csv 309 OpenStreetMap Overpass API low-clearance spans across the US, UK, Australia, Pakistan, and Azerbaijan with verbatim maxheight tags
usgs_live_river_scour_telemetry.csv 1,436 USGS NWIS 15-minute instantaneous river stage (00065) & discharge (00060) time series
global_glofas_flood_and_wind_daily.csv 360 Copernicus GloFAS river discharge + Open-Meteo 10m crosswind gusts & rainfall across 8 global corridors
bridgespan_dispatch_benchmark_80.csv 80 Verified 80-scenario heavy-truck benchmark with real OSRM primary vs. safe bypass distances (8/8 pytest suite verifies 100% agreement)

5. Designing a Mobile-Responsive Fleet Safety UI

Commercial dispatchers work on wide desktop monitors, while field supervisors and truck drivers check routes on phones. Taking inspiration from modern fleet telematics platforms, I designed app.py to be intuitive and mobile-responsive out of the box:

  • 1-Tap Scenario Presets & Clean Vehicle Profiles: Test a 13'-6" semi-trailer, 42 t mobile crane, Potomac flood-scour surge, or 78 km/h Baku Khazri crosswind gale in a single tap.
  • At-a-Glance Progress Meters & Overhead Highway LED Gantry Sign: Visualizes exact clearance margin, axle load utilization, river surge, and OSRM bypass distance without raw debug JSON clutter.
  • Keyless Dark OpenStreetMap + OSRM Vector Map: Renders blocked bridges as dashed red lines and verified safe heavy-truck detours as bright emerald routes with zero paid map API keys required.

Try it live right in your browser or on your phone: bridgespan-ai-mvhoucpfp2n5o25dewb2hi.streamlit.app


6. Run Locally or Deploy Scale-to-Zero on Google Cloud Run

git clone https://github.com/RobinaMirbahar/bridgespan-ai.git
cd bridgespan-ai
pip install -r requirements.txt

# Verify all 80 benchmark scenarios & unit-conversion guardrails
pytest -v

# Launch the mobile-responsive operator console
streamlit run app.py
Enter fullscreen mode Exit fullscreen mode

Deploying to Google Cloud Run with scale-to-zero ($0 idle cost) takes a single command:

gcloud run deploy bridgespan-ai \
  --source . \
  --region us-central1 \
  --allow-unauthenticated \
  --min-instances 0
Enter fullscreen mode Exit fullscreen mode

Official Documentation & Standards Referenced


Explore All Project Links


💬 Let's Discuss

What edge-inference guardrails and sensor fail-safes do you prioritize when designing safety-critical IoT systems?

How would you approach latency budgets for sub-100ms multi-agent collision avoidance?

Share your thoughts and architectural approaches in the comments! 👇

Top comments (2)

Collapse
 
raju_dandigam profile image
Raju Dandigam Google Developer Experts •

The four deterministic gates are a strong boundary for clearance, load, and scour decisions. For a dispatch recommendation, do you surface the source timestamp and unit conversion used by each gate alongside the agent's explanation? A stale river reading or mixed unit would be a very different failure from a model hallucination.

Collapse
 
robinamirbahar profile image
Robina Mirbahar Google Developer Experts •

Spot on, @raju_dandigam! A stale USGS gauge or imperial/metric unit mismatch is far more hazardous in physical infrastructure than an agent hallucination because it masquerades as clean data.

To prevent this, we treat every gate decision as a hermetic provenance tuple rather than a bare boolean. Alongside the agent's natural-language dispatch explanation, the platform surfaces a structured audit block:

  1. Provenance & Ingress Timestamps: Every telemetry frame carries observed_at_utc, gateway_received_at_utc, and an active freshness delta freshness_age_s. If freshness_age_s > MAX_STALE_CEILING (e.g. >15 min for river stage, >5s for LiDAR beams), the gate hard-fails with STALE_SENSOR_LOCKOUT before evaluating thresholds.
  2. Canonical SI Normalization: The gates operate strictly in SI base units (meters, kg, m3/s). Raw payloads retain their native representation (raw_value, raw_unit, e.g. 11ft 8in), and the conversion function logs the exact multiplier (factor: 0.3048) and normalized value (3.556m) directly in the gate assertion audit trail.
  3. Decoupled JSON Metadata: In the UI and API response, the LLM explanation explains the operational "why", but the dispatcher console displays an immutable table alongside it showing [Gate Name | Normalized Value | Raw Input + Unit | Sensor Timestamp | Ingress Delta | Pass/Fail].

This ensures dispatchers never have to take the model's word for sensor freshness or conversion math. Really appreciate you highlighting this boundary!