Code Examples

Ready-to-Use Implementation Examples

Back to Project

Complete INS/DVL/LBL Integration

Full navigation system implementation with sensor fusion.

// Complete Navigation System class NavigationSystem { constructor(config) { this.filter = new ExtendedKalmanFilter(config); this.imu = new IMU(config.imu); this.dvl = new DVL(config.dvl); this.lbl = new LBL(config.lbl); this.state = { position: [0, 0, 100], velocity: [0, 0, 0], attitude: [0, 0, 0] }; } update(dt) { // High-rate IMU prediction const gyro = this.imu.readGyro(); const accel = this.imu.readAccel(); this.filter.predict(gyro, accel, dt); // DVL velocity update (5 Hz) if (this.dvl.hasNewData()) { const velocity = this.dvl.read(); if (velocity.isValid()) { this.filter.updateDVL(velocity.data, 0.01); } } // LBL position fix (0.5 Hz) if (this.lbl.hasNewFix()) { const position = this.lbl.getPosition(); const gdop = this.lbl.getGDOP(); if (gdop < 3.0) { this.filter.updateLBL(position, 6.25); } } this.state = this.filter.getState(); return this.state; } } // Usage const nav = new NavigationSystem({ imu: { rate: 100, gyroNoise: 0.001, accelNoise: 0.01 }, dvl: { rate: 5, accuracy: 0.1 }, lbl: { transponders: [[-500, -500, 0], [500, -500, 0], ...] } }); setInterval(() => { const state = nav.update(0.01); console.log(`Position: ${state.position}`); }, 10);

Mission Planning Example

Plan a survey mission with waypoints and uncertainty analysis.

// Mission Planner function planSurveyMission(area, spacing) { const waypoints = []; let direction = 1; for (let y = area.minY; y <= area.maxY; y += spacing) { if (direction === 1) { waypoints.push({ x: area.minX, y: y, z: 100 }); waypoints.push({ x: area.maxX, y: y, z: 100 }); } else { waypoints.push({ x: area.maxX, y: y, z: 100 }); waypoints.push({ x: area.minX, y: y, z: 100 }); } direction *= -1; } // Compute mission stats const totalDistance = computePathLength(waypoints); const missionTime = totalDistance / 2.0; // 2 m/s speed const maxUncertainty = predictMaxError(waypoints); return { waypoints, distance: totalDistance, duration: missionTime, maxError: maxUncertainty }; } // Example usage const mission = planSurveyMission( { minX: -400, maxX: 400, minY: -300, maxY: 300 }, 100 // 100m line spacing ); console.log(`Mission: ${mission.waypoints.length} waypoints`); console.log(`Distance: ${mission.distance.toFixed(0)}m`); console.log(`Duration: ${mission.duration.toFixed(0)}s`);

Sound Velocity Profile Correction

Apply SVP correction to acoustic range measurements.

// Ray trace through SVP to get corrected range function raytraceSVP(depth, offset, svp) { const numSteps = 100; let x = 0, z = 0; let angle = Math.atan2(depth, offset); let totalDistance = 0; for (let i = 0; i < numSteps; i++) { const c = getSoundSpeed(z, svp); const dcDz = getSoundSpeedGradient(z, svp); const ds = Math.sqrt(depth*depth + offset*offset) / numSteps; x += ds * Math.cos(angle); z += ds * Math.sin(angle); // Apply Snell's law angle += ds * (dcDz / c) * Math.cos(angle); totalDistance += ds; } return totalDistance; } // Correct LBL ranges const svp = measureSVP(); // Get current sound velocity profile const rawRanges = getLBLRanges(); const correctedRanges = rawRanges.map((range, i) => { const transponder = transponders[i]; return raytraceSVP(vehicleDepth, Math.sqrt(transponder.x**2 + transponder.y**2), svp); });

Data Export Example

Export navigation data in multiple formats.

// Export to CSV function exportToCSV(navData) { let csv = 'Time,X,Y,Z,VX,VY,VZ,Roll,Pitch,Yaw\n'; navData.forEach(d => { csv += `${d.time},${d.pos.join(',')},${d.vel.join(',')},${d.att.join(',')}\n`; }); return csv; } // Export to JSON function exportToJSON(navData) { return JSON.stringify({ metadata: { mission: 'Survey Mission 2024-01-15', vehicle: 'AUV-01', sensors: ['IMU', 'DVL', 'LBL'] }, data: navData }, null, 2); } // Export to MATLAB function exportToMATLAB(navData) { let matlab = '% Navigation Data\n'; matlab += `time = [${navData.map(d => d.time).join(', ')}];\n`; matlab += `x = [${navData.map(d => d.pos[0]).join(', ')}];\n`; matlab += `y = [${navData.map(d => d.pos[1]).join(', ')}];\n`; matlab += `figure; plot(x, y); xlabel('East'); ylabel('North');\n`; return matlab; } // Usage const csvData = exportToCSV(navigationLog); downloadFile('mission.csv', csvData);
Tutorials Back to Project