mavsdk_drone_show

Swarm Trajectory Feature Documentation

Version: 1.0.0
Date: September 2025
Status: Production Ready
Mission Type: 4 (SWARM_TRAJECTORY)


๐Ÿ“‹ Table of Contents

  1. Overview
  2. Architecture
  3. User Workflow
  4. Developer Guide
  5. File Structure
  6. API Reference
  7. Troubleshooting
  8. Future Enhancements

๐ŸŽฏ Overview

The Swarm Trajectory Feature enables coordinated drone swarm missions where top leaders follow pre-defined waypoint trajectories while followers maintain precise formations using configured offsets. This creates sophisticated swarm choreography with minimal user input.

Key Capabilities


๐Ÿ—๏ธ Architecture

System Components

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Frontend UI   โ”‚โ”€โ”€โ”€โ”€โ”‚  Backend API    โ”‚โ”€โ”€โ”€โ”€โ”‚   Processing    โ”‚
โ”‚  (React + CSS)  โ”‚    โ”‚  (Flask REST)   โ”‚    โ”‚   Pipeline      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚                        โ”‚
                                โ–ผ                        โ–ผ
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       โ”‚  File Storage   โ”‚    โ”‚  Mission Exec   โ”‚
                       โ”‚  (CSV + Plots)  โ”‚    โ”‚  (drone_show)   โ”‚
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŒ Coordinate System & Processing Logic

Lead Drone Processing (Global Coordinates Only):

Follower Processing (Respects swarm.csv Configuration):

Final Output: All drones receive global lat/lon/alt trajectories for mission execution.

๐ŸŒ Google Earth Integration

KML Export Features:

Cluster-based UI Organization:

Usage: Expand trajectory previews to see cluster formations, download KML files for any drone, view in Google Earth for immersive 3D visualization.

Data Flow

  1. Upload: User uploads leader trajectories via UI
  2. Analysis: System analyzes swarm.csv for leader-follower structure
  3. Processing: Smooth leader trajectories, calculate follower positions
  4. Generation: Create individual CSV files for each drone
  5. Visualization: Generate 3D plots for analysis
  6. Execution: Mission system executes individual drone trajectories

๐Ÿ‘ฅ User Workflow

Step 1: Trajectory Planning

graph LR
    A[Mission Planning Tool] --> B[Export CSV Waypoints]
    B --> C[Save as 'Drone X.csv' format]

CSV Format Required:

Name,Latitude,Longitude,Altitude_MSL_m,TimeFromStart_s,EstimatedSpeed_ms,Heading_deg,HeadingMode
Waypoint 1,35.69466817,51.28617904,1300.00,10.0,8.0,25.8,auto
Waypoint 2,35.72774031,51.30590792,1370.00,520.0,8.0,144.7,auto

Step 2: Upload & Process

  1. Navigate to โ€œSwarm Trajectoryโ€ in dashboard menu
  2. Upload CSV files for each lead drone
  3. Review system status (lead drones found, uploaded count)
  4. Process formation - system calculates all trajectories
  5. Verify results and download individual files if needed

Step 3: Mission Execution

  1. Set Mission Type to 4 (Swarm Trajectory) on all drones
  2. Trigger Mission - each drone reads its individual trajectory
  3. Monitor execution through existing telemetry systems

๐Ÿ‘จโ€๐Ÿ’ป Developer Guide

Core Files & Responsibilities

Backend Processing (functions/)

functions/
โ”œโ”€โ”€ swarm_analyzer.py          # Parse swarm structure, find lead drones
โ”œโ”€โ”€ swarm_global_calculator.py # Calculate follower positions  
โ”œโ”€โ”€ swarm_trajectory_smoother.py # Smooth waypoint trajectories
โ”œโ”€โ”€ swarm_trajectory_processor.py # Main orchestration
โ””โ”€โ”€ swarm_plotter.py           # Generate visualization plots

API Layer (gcs-server/)

gcs-server/
โ”œโ”€โ”€ swarm_trajectory_routes.py # REST API endpoints
โ””โ”€โ”€ app.py                     # Route registration

Frontend (app/dashboard/drone-dashboard/src/)

src/
โ”œโ”€โ”€ pages/SwarmTrajectory.js   # Main UI component
โ”œโ”€โ”€ styles/SwarmTrajectory.css # Modern styling
โ””โ”€โ”€ constants/droneConstants.js # Mission type constants

Mission System

โ”œโ”€โ”€ src/enums.py               # Mission enum definition
โ”œโ”€โ”€ src/drone_setup.py         # Mission handler
โ””โ”€โ”€ swarm_trajectory_mission.py # Execution script

Key Functions

analyze_swarm_structure(swarm_data=None)

Parses swarm configuration to identify leader-follower relationships.

Returns:

{
    'top_leaders': [1, 2, 23],           # HW IDs of top leaders
    'hierarchies': {1: [3,4,5], 2: [6,7]}, # Leader -> followers mapping  
    'swarm_config': {...}                # Full drone configurations
}

process_swarm_trajectories()

Main processing pipeline that orchestrates the entire workflow.

Process:

  1. Analyze swarm structure
  2. Load leader trajectories
  3. Calculate formation origin
  4. Process leaders (smooth trajectories)
  5. Process followers (calculate positions)
  6. Generate visualizations

smooth_trajectory_with_waypoints(waypoints_df, dt=0.05)

Converts waypoint trajectories to smooth interpolated paths.

Input: CSV waypoints
Output: Smooth trajectory at 0.05s intervals with velocities/accelerations


๐Ÿ“ File Structure

Directory Layout

shapes/ (or shapes_sitl/ for simulation)
โ””โ”€โ”€ swarm_trajectory/
    โ”œโ”€โ”€ raw/                   # Uploaded lead drone trajectories
    โ”‚   โ”œโ”€โ”€ Drone 1.csv
    โ”‚   โ”œโ”€โ”€ Drone 2.csv
    โ”‚   โ””โ”€โ”€ ...
    โ”œโ”€โ”€ processed/             # Generated drone trajectories
    โ”‚   โ”œโ”€โ”€ Drone 1.csv
    โ”‚   โ”œโ”€โ”€ Drone 2.csv
    โ”‚   โ””โ”€โ”€ ...
    โ””โ”€โ”€ plots/                 # Visualization plots
        โ”œโ”€โ”€ drone_X_trajectory.jpg      # Individual drone plots
        โ”œโ”€โ”€ cluster_leader_X.jpg        # Cluster formations
        โ”œโ”€โ”€ combined_swarm.jpg          # Complete swarm view
        โ””โ”€โ”€ (KML files generated on-demand, no storage needed)

CSV File Formats

Input (Lead Drone Trajectories)

Name,Latitude,Longitude,Altitude_MSL_m,TimeFromStart_s,EstimatedSpeed_ms,Heading_deg,HeadingMode
Waypoint 1,35.694668,51.286179,1300.0,10.0,8.0,25.8,auto

Output (Processed Drone Trajectories)

t,lat,lon,alt,vx,vy,vz,ax,ay,az,yaw,mode,ledr,ledg,ledb
10.0,35.694668,51.286179,1300.0,0.0001,0.00003,0.211,0.0,0.0,0.0,25.8,70,255,0,0

๐Ÿ”Œ API Reference

Base URL: /api/swarm/

GET /leaders

Get swarm leaders and upload status.

Response:

{
  "success": true,
  "leaders": [1, 2],
  "hierarchies": {"1": 3, "2": 2},
  "uploaded_leaders": [1],
  "simulation_mode": false
}

POST /trajectory/upload/<leader_id>

Upload trajectory CSV for specific leader.

Request: multipart/form-data with CSV file
Response: Success/error message

POST /trajectory/process

Process all uploaded trajectories.

Response:

{
  "success": true,
  "processed_drones": 5,
  "statistics": {"leaders": 2, "followers": 3, "errors": 0}
}

GET /trajectory/status

Get processing status and file counts.

POST /trajectory/clear

Clear all trajectory files.

GET /trajectory/download/<drone_id>

Download processed trajectory CSV for specific drone.

GET /trajectory/download-kml/<drone_id>

Download KML file for Google Earth visualization.

Response: KML file with time-based animation and 3D terrain visualization.


๐Ÿ› ๏ธ Configuration

Parameters (src/params.py)

# Swarm Trajectory Mode Configuration
swarm_trajectory_dt = 0.05              # Interpolation timestep (seconds)
swarm_trajectory_max_speed = 20.0       # Maximum speed limit (future use)

# LED Colors (RGB)
swarm_leader_led_color = (255, 0, 0)    # Red for leaders
swarm_follower_led_color = (0, 255, 0)  # Green for followers

# Error handling
swarm_missing_leader_strategy = 'skip'  # 'skip' or 'error'

Mission Integration


๐Ÿ› Troubleshooting

Common Issues

โ€œNo lead drones foundโ€

โ€œTrajectory processing failedโ€

โ€œFiles not found during executionโ€

โ€œClear all doesnโ€™t delete everythingโ€

Debugging Tips

  1. Check logs for detailed error messages
  2. Verify file structure using ls -la shapes/swarm_trajectory/
  3. Test API endpoints using curl or Postman
  4. Validate CSV format before upload

๐Ÿ”ฎ Future Enhancements

Planned Features

v1.1 - Enhanced Safety

v1.2 - Advanced Formation Control

v1.3 - Improved User Experience

v1.4 - Analytics & Optimization

Technical Improvements


๐Ÿ“Š Performance Metrics

Current Performance

Resource Requirements


๐Ÿค Contributing

Development Workflow

  1. Create feature branch from main-candidate
  2. Implement changes following existing patterns
  3. Test with both SITL and real hardware modes
  4. Update documentation
  5. Submit pull request with test results

Code Standards

Testing Checklist


๐Ÿ“œ Change Log

v1.0.0 - Initial Release (September 2025)

Known Issues (v1.0.0)


๐Ÿ“ž Support

For Users

For Developers

Emergency Contacts


Last Updated: September 6, 2025
Next Review: October 2025
Maintained By: MAVSDK Drone Show Development Team