215 lines
6.7 KiB
TypeScript
215 lines
6.7 KiB
TypeScript
/**
|
|
* Robotics Navigation: Adaptive Real-Time Path Planning
|
|
*
|
|
* Use Case: Autonomous robots need real-time similarity search
|
|
* for environment matching and obstacle avoidance.
|
|
*
|
|
* Optimization Priority: BALANCED (latency + accuracy)
|
|
*/
|
|
|
|
import { UnifiedMetrics } from '../../types';
|
|
|
|
export const ROBOTICS_ATTENTION_CONFIG = {
|
|
heads: 8, // Optimal balance (validated)
|
|
forwardPassTargetMs: 10, // 10ms for 100Hz control loop
|
|
batchSize: 4, // Small batches for real-time
|
|
precision: 'float16' as const, // Reduced precision for edge devices
|
|
edgeOptimized: true, // NVIDIA Jetson, Intel NCS optimization
|
|
|
|
// Dynamic attention based on environment complexity
|
|
dynamicHeads: {
|
|
enabled: true,
|
|
simple: 4, // 4 heads for simple environments
|
|
complex: 12, // 12 heads for complex scenes
|
|
adaptationStrategy: 'scene-complexity' as const
|
|
},
|
|
|
|
// Dynamic-k based on navigation context
|
|
dynamicK: {
|
|
min: 5,
|
|
max: 20,
|
|
adaptationStrategy: 'obstacle-density' as const // More obstacles = more candidates
|
|
},
|
|
|
|
// Self-healing for continuous operation
|
|
selfHealing: {
|
|
enabled: true,
|
|
adaptationIntervalMs: 100,
|
|
degradationThreshold: 0.05,
|
|
hardwareMonitoring: true // Battery, temperature, GPU
|
|
}
|
|
};
|
|
|
|
// Robotics-specific metrics
|
|
export interface RoboticsMetrics extends UnifiedMetrics {
|
|
controlLoopLatencyMs: number; // Control loop latency (10ms target)
|
|
navigationAccuracy: number; // Path planning accuracy
|
|
obstacleDetectionRate: number; // Obstacle detection success rate
|
|
powerConsumptionW: number; // Power consumption (battery life)
|
|
temperatureCelsius: number; // Hardware temperature monitoring
|
|
}
|
|
|
|
// Robot context interface
|
|
export interface RobotContext {
|
|
velocity: number;
|
|
batteryPercent: number;
|
|
temperatureCelsius: number;
|
|
missionCriticality: 'low' | 'medium' | 'high';
|
|
}
|
|
|
|
// Navigation plan interface
|
|
export interface NavigationPlan {
|
|
bestMatch: any;
|
|
suggestedPath: any;
|
|
confidence: number;
|
|
latencyMs: number;
|
|
}
|
|
|
|
// Example: Environment matching for navigation
|
|
export async function matchEnvironment(
|
|
currentSensorData: Float32Array, // LIDAR, camera, IMU
|
|
knownEnvironments: any, // HNSWGraph type
|
|
robotContext: RobotContext,
|
|
applyAttention: (data: Float32Array, config: any) => Promise<Float32Array>,
|
|
analyzeSceneComplexity: (data: Float32Array) => number,
|
|
calculateObstacleDensity: (data: Float32Array) => number,
|
|
computePath: (matches: any[]) => any
|
|
): Promise<NavigationPlan> {
|
|
const startTime = Date.now();
|
|
const config = ROBOTICS_ATTENTION_CONFIG;
|
|
|
|
// Adaptive attention based on scene complexity
|
|
const sceneComplexity = analyzeSceneComplexity(currentSensorData);
|
|
const adaptiveHeads = sceneComplexity > 0.7 ? 12 : 4;
|
|
|
|
// Apply attention with adaptive heads
|
|
const enhanced = await applyAttention(currentSensorData, {
|
|
...config,
|
|
heads: adaptiveHeads
|
|
});
|
|
|
|
// Dynamic-k based on obstacle density
|
|
const obstacleDensity = calculateObstacleDensity(currentSensorData);
|
|
const k = Math.round(5 + obstacleDensity * 15); // 5-20 range
|
|
|
|
// Search for similar environments
|
|
const matches = await knownEnvironments.search(enhanced, k);
|
|
|
|
return {
|
|
bestMatch: matches[0],
|
|
suggestedPath: computePath(matches),
|
|
confidence: matches[0].score,
|
|
latencyMs: Date.now() - startTime // Track real-time performance
|
|
};
|
|
}
|
|
|
|
// Performance targets for robotics
|
|
export const ROBOTICS_PERFORMANCE_TARGETS = {
|
|
controlLoopLatencyMs: 10, // 10ms for 100Hz control
|
|
navigationAccuracy: 0.95, // 95% path planning accuracy
|
|
p99LatencyMs: 15, // 15ms p99 (real-time critical)
|
|
powerConsumptionW: 20, // 20W max (battery life)
|
|
uptimePercent: 99.0 // 99% uptime (2 nines, field operation)
|
|
};
|
|
|
|
// Robot platform-specific configurations
|
|
export const ROBOTICS_CONFIG_VARIATIONS = {
|
|
// High-performance robots (Boston Dynamics Spot, ANYmal)
|
|
highPerformance: {
|
|
...ROBOTICS_ATTENTION_CONFIG,
|
|
heads: 12,
|
|
forwardPassTargetMs: 5, // 5ms for 200Hz control
|
|
precision: 'float32' as const, // Full precision available
|
|
powerConsumptionW: 100 // Higher power budget
|
|
},
|
|
|
|
// Consumer drones (DJI, Parrot)
|
|
consumerDrone: {
|
|
...ROBOTICS_ATTENTION_CONFIG,
|
|
heads: 6,
|
|
forwardPassTargetMs: 20, // 50Hz control acceptable
|
|
precision: 'float16' as const,
|
|
powerConsumptionW: 15 // Battery constrained
|
|
},
|
|
|
|
// Industrial AGVs (warehouse robots)
|
|
industrialAGV: {
|
|
...ROBOTICS_ATTENTION_CONFIG,
|
|
heads: 8,
|
|
forwardPassTargetMs: 15,
|
|
precision: 'float32' as const,
|
|
dynamicK: { min: 10, max: 30, adaptationStrategy: 'warehouse-density' as const }
|
|
},
|
|
|
|
// Embedded robots (Raspberry Pi, Arduino)
|
|
embedded: {
|
|
...ROBOTICS_ATTENTION_CONFIG,
|
|
heads: 4,
|
|
forwardPassTargetMs: 50, // Slower acceptable
|
|
precision: 'int8' as const, // Quantized for embedded
|
|
powerConsumptionW: 5 // Very power constrained
|
|
}
|
|
};
|
|
|
|
// Environment adaptation
|
|
export function adaptConfigToEnvironment(
|
|
baseConfig: typeof ROBOTICS_ATTENTION_CONFIG,
|
|
environment: 'indoor' | 'outdoor' | 'underground' | 'aerial'
|
|
): typeof ROBOTICS_ATTENTION_CONFIG {
|
|
switch (environment) {
|
|
case 'indoor':
|
|
return {
|
|
...baseConfig,
|
|
heads: 8,
|
|
dynamicK: { ...baseConfig.dynamicK, min: 5, max: 15 }
|
|
};
|
|
case 'outdoor':
|
|
return {
|
|
...baseConfig,
|
|
heads: 10, // More complexity
|
|
dynamicK: { ...baseConfig.dynamicK, min: 10, max: 25 },
|
|
selfHealing: { ...baseConfig.selfHealing, adaptationIntervalMs: 50 }
|
|
};
|
|
case 'underground':
|
|
return {
|
|
...baseConfig,
|
|
heads: 6, // Limited sensors
|
|
forwardPassTargetMs: 15
|
|
// Note: Network resilience handled at transport layer
|
|
};
|
|
case 'aerial':
|
|
return {
|
|
...baseConfig,
|
|
heads: 12, // Complex 3D navigation
|
|
forwardPassTargetMs: 8,
|
|
dynamicK: { ...baseConfig.dynamicK, min: 8, max: 20 }
|
|
};
|
|
}
|
|
}
|
|
|
|
// Power-aware configuration adjustment
|
|
export function adaptConfigToPower(
|
|
baseConfig: typeof ROBOTICS_ATTENTION_CONFIG,
|
|
batteryPercent: number
|
|
): typeof ROBOTICS_ATTENTION_CONFIG {
|
|
if (batteryPercent < 20) {
|
|
// Critical battery - minimize computation
|
|
return {
|
|
...baseConfig,
|
|
heads: 4,
|
|
batchSize: 1
|
|
// Note: Precision optimization coming in future release
|
|
};
|
|
} else if (batteryPercent < 50) {
|
|
// Low battery - reduce quality slightly
|
|
return {
|
|
...baseConfig,
|
|
heads: 6,
|
|
precision: 'float16' as const
|
|
};
|
|
} else {
|
|
// Normal operation
|
|
return baseConfig;
|
|
}
|
|
}
|