CHAPTER 6

Phase 3 - Protocol

Real-time control of construction 3D printing requires continuous, low-latency communication beyond request-response APIs. This chapter explores Phase 3 protocols for robot control, material flow management, sensor data streaming, and safety monitoring using WebSocket and specialized communication patterns.

Real-Time Communication Requirements

Construction 3D printing involves coordinating multiple systems in real-time: robotic motion controllers, material pumps, sensors, safety systems, and monitoring tools. These systems require communication patterns different from traditional request-response APIs.

Characteristics of Real-Time Control

Protocol Technology Stack

The WIA standard adopts WebSocket as the primary real-time protocol with fallback options:

Protocol Use Case Frequency Latency
WebSocket Primary real-time control 10-100 Hz <10ms
MQTT Sensor data streaming 1-50 Hz <50ms
gRPC High-performance control 100+ Hz <5ms
UDP (custom) Emergency shutdown As needed <1ms

WebSocket Foundation

WebSocket provides full-duplex communication channel over a single TCP connection, ideal for real-time control scenarios.

Connection Establishment

// Client initiates WebSocket connection
const ws = new WebSocket('wss://printer.example.com:8443/wia/v1/control');

ws.onopen = function(event) {
    console.log('Connection established');

    // Authenticate
    ws.send(JSON.stringify({
        type: 'AUTH',
        token: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
    }));
};

ws.onmessage = function(event) {
    const message = JSON.parse(event.data);
    handleMessage(message);
};

ws.onerror = function(error) {
    console.error('WebSocket error:', error);
};

ws.onclose = function(event) {
    console.log('Connection closed:', event.code, event.reason);
};

Message Format

All WebSocket messages follow standardized JSON format:

{
  "type": "MESSAGE_TYPE",
  "timestamp": "2025-03-12T10:30:45.123Z",
  "sequenceNumber": 12345,
  "payload": {
    // Message-specific data
  }
}

Message Types

Type Direction Purpose Frequency
AUTH Client → Server Authentication Once per connection
COMMAND Client → Server Control commands As needed
STATUS Server → Client System status updates 10 Hz
SENSOR Server → Client Sensor data 50 Hz
EVENT Server → Client Significant events As occurs
HEARTBEAT Bidirectional Connection alive 1 Hz
ERROR Bidirectional Error notifications As occurs

Robot Control Protocol

Robotic printing systems require precise motion control coordinated with material deposition. The protocol supports path-based control, velocity management, and real-time adjustments.

Motion Commands

{
  "type": "COMMAND",
  "timestamp": "2025-03-12T10:30:45.123Z",
  "sequenceNumber": 12345,
  "payload": {
    "command": "MOVE",
    "target": {
      "position": {
        "x": 5000.0,
        "y": 2500.0,
        "z": 120.0,
        "unit": "mm"
      },
      "velocity": {
        "linear": 100.0,
        "unit": "mm/s"
      },
      "acceleration": {
        "value": 500.0,
        "unit": "mm/s²"
      }
    },
    "materialFlow": {
      "enabled": true,
      "rate": 1000.0,
      "unit": "mm³/s"
    },
    "coordinateSystem": "absolute"
  }
}

Path Streaming

For smooth continuous motion, path segments are streamed in advance:

{
  "type": "COMMAND",
  "timestamp": "2025-03-12T10:30:45.123Z",
  "sequenceNumber": 12346,
  "payload": {
    "command": "PATH_SEGMENT",
    "pathId": "layer-025-perimeter",
    "segmentNumber": 157,
    "points": [
      {"x": 5000.0, "y": 2500.0, "z": 120.0},
      {"x": 5100.0, "y": 2500.0, "z": 120.0},
      {"x": 5200.0, "y": 2510.0, "z": 120.0}
    ],
    "velocity": 100.0,
    "materialFlow": 1000.0,
    "blending": {
      "enabled": true,
      "radius": 5.0
    }
  }
}

Real-Time Position Feedback

{
  "type": "STATUS",
  "timestamp": "2025-03-12T10:30:45.223Z",
  "sequenceNumber": 45678,
  "payload": {
    "robot": {
      "position": {
        "x": 5075.3,
        "y": 2501.2,
        "z": 120.0
      },
      "velocity": {
        "linear": 98.5,
        "angular": 0.0
      },
      "status": "moving",
      "bufferFill": 0.75,
      "lastCompletedSegment": 156
    },
    "materialPump": {
      "flowRate": 995.0,
      "pressure": 1.18,
      "temperature": 24.3,
      "status": "normal"
    }
  }
}

Command Acknowledgment

All commands receive acknowledgment for reliable delivery:

{
  "type": "ACK",
  "timestamp": "2025-03-12T10:30:45.125Z",
  "payload": {
    "acknowledgedSequence": 12346,
    "status": "accepted",
    "estimatedExecutionTime": "2025-03-12T10:30:46.500Z"
  }
}

Material Flow Management

Precise material control ensures consistent deposition. The protocol manages pump speed, pressure, mixing, and temperature.

{
  "type": "COMMAND",
  "timestamp": "2025-03-12T10:30:45.123Z",
  "sequenceNumber": 12347,
  "payload": {
    "command": "SET_MATERIAL_FLOW",
    "flowRate": {
      "target": 1200.0,
      "unit": "mm³/s",
      "rampTime": 0.5
    },
    "pressure": {
      "target": 1.25,
      "max": 1.5,
      "unit": "MPa"
    },
    "temperature": {
      "target": 25.0,
      "tolerance": 2.0,
      "unit": "celsius"
    },
    "mixer": {
      "enabled": true,
      "speed": 60,
      "unit": "rpm"
    }
  }
}

Material Status Monitoring

{
  "type": "SENSOR",
  "timestamp": "2025-03-12T10:30:45.145Z",
  "sequenceNumber": 78901,
  "payload": {
    "sensor": "material-flow",
    "measurements": {
      "flowRate": {
        "value": 1195.3,
        "unit": "mm³/s"
      },
      "pressure": {
        "value": 1.23,
        "unit": "MPa"
      },
      "temperature": {
        "value": 24.8,
        "unit": "celsius"
      },
      "viscosity": {
        "value": 45.2,
        "unit": "Pa·s"
      },
      "density": {
        "value": 2.38,
        "unit": "g/cm³"
      }
    },
    "status": "normal",
    "alarms": []
  }
}

Sensor Data Streaming

Multiple sensors monitor printing quality, equipment health, and environmental conditions. Data streams enable real-time quality control and predictive maintenance.

Sensor Types

Sensor Category Measurements Update Rate Purpose
Position X, Y, Z coordinates 100 Hz Motion control feedback
Material Flow Flow rate, pressure, temp 50 Hz Material control
Laser Scanner Layer geometry, height 10 Hz Quality verification
Camera Visual inspection 30 FPS Monitoring, documentation
Environmental Temperature, humidity, wind 1 Hz Condition monitoring
Vibration Acceleration, frequency 1000 Hz Equipment health

Laser Scanner Data

{
  "type": "SENSOR",
  "timestamp": "2025-03-12T10:30:45.245Z",
  "sequenceNumber": 78902,
  "payload": {
    "sensor": "laser-scanner",
    "scan": {
      "layerNumber": 25,
      "scanLine": 42,
      "points": [
        {"x": 0.0, "y": 0.0, "z": 119.8},
        {"x": 10.0, "y": 0.0, "z": 120.1},
        {"x": 20.0, "y": 0.0, "z": 119.9},
        // ... hundreds of points
      ],
      "analysis": {
        "meanHeight": 120.0,
        "stdDeviation": 0.5,
        "maxDeviation": 1.2,
        "withinTolerance": true
      }
    }
  }
}

Environmental Monitoring

{
  "type": "SENSOR",
  "timestamp": "2025-03-12T10:30:45.345Z",
  "sequenceNumber": 78903,
  "payload": {
    "sensor": "environmental",
    "measurements": {
      "temperature": {
        "ambient": 22.3,
        "material": 24.8,
        "surface": 23.1,
        "unit": "celsius"
      },
      "humidity": {
        "value": 45.2,
        "unit": "percent"
      },
      "wind": {
        "speed": 2.3,
        "direction": 135,
        "unit": "m/s"
      },
      "precipitation": {
        "detected": false
      }
    },
    "alerts": []
  }
}

Safety Monitoring and Emergency Stop

Safety is paramount in construction. The protocol includes multiple layers of safety monitoring and emergency procedures.

Safety Zones

{
  "type": "COMMAND",
  "timestamp": "2025-03-12T10:30:45.123Z",
  "sequenceNumber": 12348,
  "payload": {
    "command": "DEFINE_SAFETY_ZONE",
    "zoneId": "exclusion-001",
    "type": "exclusion",
    "geometry": {
      "type": "cylinder",
      "center": {"x": 5000, "y": 3000, "z": 0},
      "radius": 500,
      "height": 3000
    },
    "action": "emergency-stop",
    "enabled": true
  }
}

Safety Status

{
  "type": "STATUS",
  "timestamp": "2025-03-12T10:30:45.445Z",
  "sequenceNumber": 45679,
  "payload": {
    "safety": {
      "emergencyStopEngaged": false,
      "safetyZones": [
        {
          "id": "exclusion-001",
          "status": "clear",
          "violations": 0
        }
      ],
      "interlocks": [
        {
          "id": "material-pressure",
          "status": "normal",
          "value": 1.23,
          "threshold": 1.5
        },
        {
          "id": "robot-speed",
          "status": "normal",
          "value": 98.5,
          "limit": 200.0
        }
      ],
      "overallStatus": "safe-to-operate"
    }
  }
}

Emergency Stop

{
  "type": "COMMAND",
  "timestamp": "2025-03-12T10:30:50.001Z",
  "sequenceNumber": 12349,
  "payload": {
    "command": "EMERGENCY_STOP",
    "reason": "safety-zone-violation",
    "details": {
      "zone": "exclusion-001",
      "detectedObject": "person",
      "location": {"x": 5100, "y": 3050, "z": 500}
    },
    "priority": "critical"
  }
}

// System response
{
  "type": "STATUS",
  "timestamp": "2025-03-12T10:30:50.005Z",
  "sequenceNumber": 45680,
  "payload": {
    "system": "emergency-stopped",
    "allMotionCeased": true,
    "materialFlowStopped": true,
    "timestamp": "2025-03-12T10:30:50.003Z"
  }
}

Event Notifications

Significant events are broadcast to all connected clients for coordination and logging.

{
  "type": "EVENT",
  "timestamp": "2025-03-12T10:31:00.123Z",
  "sequenceNumber": 99999,
  "payload": {
    "event": "LAYER_COMPLETED",
    "severity": "info",
    "data": {
      "layerNumber": 25,
      "startTime": "2025-03-12T10:20:00.000Z",
      "endTime": "2025-03-12T10:31:00.123Z",
      "duration": 660.123,
      "materialUsed": 125.5,
      "quality": {
        "dimensionalAccuracy": "pass",
        "surfaceQuality": "pass",
        "overallScore": 96.3
      }
    }
  }
}

Event Types

Event Severity Description
LAYER_STARTED Info New layer printing begun
LAYER_COMPLETED Info Layer successfully finished
MATERIAL_LOW Warning Material inventory below threshold
QUALITY_ISSUE Warning Quality metric outside tolerance
EQUIPMENT_FAULT Error Equipment malfunction detected
SAFETY_VIOLATION Critical Safety system triggered

Connection Management

Robust connection management ensures reliable communication despite network issues.

Heartbeat Protocol

// Client sends heartbeat every second
{
  "type": "HEARTBEAT",
  "timestamp": "2025-03-12T10:30:46.123Z",
  "sequenceNumber": 20001
}

// Server responds
{
  "type": "HEARTBEAT",
  "timestamp": "2025-03-12T10:30:46.125Z",
  "sequenceNumber": 60001,
  "payload": {
    "latency": 2.0,
    "serverLoad": 0.35
  }
}

Reconnection Strategy

// Client-side reconnection logic
let reconnectAttempts = 0;
const maxReconnectAttempts = 10;
const reconnectDelay = [1000, 2000, 5000, 10000]; // ms

function attemptReconnect() {
    if (reconnectAttempts >= maxReconnectAttempts) {
        console.error('Max reconnection attempts reached');
        return;
    }

    const delay = reconnectDelay[Math.min(reconnectAttempts, reconnectDelay.length - 1)];
    console.log(`Reconnecting in ${delay}ms (attempt ${reconnectAttempts + 1})`);

    setTimeout(() => {
        reconnectAttempts++;
        establishConnection();
    }, delay);
}

ws.onclose = function(event) {
    if (!event.wasClean) {
        attemptReconnect();
    }
};

State Resynchronization

// After reconnection, client requests current state
{
  "type": "COMMAND",
  "timestamp": "2025-03-12T10:35:00.000Z",
  "sequenceNumber": 1,
  "payload": {
    "command": "SYNC_STATE"
  }
}

// Server sends complete current state
{
  "type": "STATUS",
  "timestamp": "2025-03-12T10:35:00.050Z",
  "sequenceNumber": 1,
  "payload": {
    "fullState": {
      "job": {
        "id": "job-12345",
        "status": "printing",
        "currentLayer": 27,
        "totalLayers": 50
      },
      "robot": { /* current position, velocity, etc */ },
      "material": { /* current flow, pressure, etc */ },
      "safety": { /* safety status */ }
    }
  }
}

Quality of Service

Different message types require different reliability guarantees. The protocol supports configurable QoS levels.

Message Type QoS Level Delivery Guarantee
EMERGENCY_STOP Highest Guaranteed, ordered, acknowledged
COMMAND High Guaranteed, acknowledged
STATUS Medium Best effort, latest value
SENSOR Low Best effort, okay to drop

Performance Optimization

High-frequency communication requires optimization to minimize latency and bandwidth usage.

Message Compression

// Enable compression for connection
ws = new WebSocket('wss://printer.example.com/wia/v1/control', {
    perMessageDeflate: true
});

// Binary encoding for high-frequency data
{
  "type": "SENSOR",
  "encoding": "binary",
  "payload": Base64EncodedBinaryData
}

Batching

// Batch multiple sensor readings
{
  "type": "SENSOR_BATCH",
  "timestamp": "2025-03-12T10:30:45.345Z",
  "sequenceNumber": 78904,
  "payload": {
    "sensors": [
      {"sensor": "position", "timestamp": "2025-03-12T10:30:45.300Z", "data": {...}},
      {"sensor": "material-flow", "timestamp": "2025-03-12T10:30:45.310Z", "data": {...}},
      {"sensor": "environmental", "timestamp": "2025-03-12T10:30:45.320Z", "data": {...}}
    ]
  }
}

Delta Updates

// Only send changed values
{
  "type": "STATUS_DELTA",
  "timestamp": "2025-03-12T10:30:45.445Z",
  "sequenceNumber": 45680,
  "payload": {
    "changes": {
      "robot.position.x": 5125.8,
      "material.flowRate": 1005.2
    }
    // Unchanged values omitted
  }
}

Chapter Summary

Phase 3 protocols enable real-time control and monitoring of construction 3D printing systems. WebSocket provides full-duplex communication for continuous data exchange with low latency. Standardized message formats cover robot control, material flow management, sensor data streaming, safety monitoring, and event notifications.

Robot control messages support precise motion commands with path streaming and real-time position feedback. Material flow protocols manage pump speed, pressure, mixing, and temperature with continuous monitoring. Sensor streams provide data from position encoders, flow meters, laser scanners, cameras, and environmental monitors at appropriate frequencies.

Safety mechanisms include zone definition, continuous monitoring, and emergency stop procedures with guaranteed delivery. Connection management with heartbeats, reconnection strategies, and state resynchronization ensures reliability. Quality of Service levels match message criticality to delivery guarantees. Performance optimizations including compression, batching, and delta updates enable efficient high-frequency communication.

Key Takeaways

  1. WebSocket Foundation: Full-duplex persistent connections enable real-time bidirectional communication essential for continuous control and monitoring.
  2. Comprehensive Control: Protocols cover all aspects of 3D printing—robot motion, material flow, sensor feedback, safety monitoring—with appropriate message types and frequencies.
  3. Safety Priority: Multiple safety layers including zone monitoring, interlock checking, and emergency stop with highest-priority guaranteed delivery protect workers and equipment.
  4. Reliability Mechanisms: Heartbeats, reconnection strategies, acknowledgments, sequence numbers, and state resynchronization ensure robust communication despite network issues.
  5. Performance Optimization: Compression, batching, delta updates, and configurable QoS levels enable efficient high-frequency communication without overwhelming networks.

Review Questions

  1. Compare request-response APIs (Phase 2) with real-time protocols (Phase 3). What specific characteristics of construction 3D printing require real-time communication beyond traditional APIs?
  2. Explain how path streaming with buffering enables smooth continuous motion. What problems occur without buffering, and how does the buffer fill percentage inform control decisions?
  3. The protocol defines different QoS levels for different message types. Why does emergency stop require highest QoS while sensor data uses best-effort? What are consequences of applying wrong QoS level?
  4. Analyze the safety architecture including zones, interlocks, monitoring, and emergency stop. How do these layers work together? What happens if one layer fails?
  5. Connection interruptions are inevitable in production environments. Trace the complete reconnection process from disconnect detection through state resynchronization. What data could be lost, and how does the system recover?
  6. High-frequency sensor streams generate enormous data volumes. Compare compression, batching, and delta updates as optimization strategies. When is each appropriate, and can they be combined?

Looking Ahead

With data formats (Phase 1), APIs (Phase 2), and real-time protocols (Phase 3) established, Chapter 7 explores Phase 4—Integration with the broader construction ecosystem. We'll examine how 3D printing systems connect with BIM, CAD, ERP, and other platforms, enabling comprehensive digital workflows from design through construction to operations.