Skip to content

flightpath-dev/flightpath-server-archived

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flightpath Server

Go backend for controlling drones through a unified, protocol-agnostic API.

Key Features

Protocol-Agnostic Frontend - Frontend only knows drone IDs
Configuration-Driven - All connection details in drones.yaml
Multi-Protocol Support - MAVLink, DJI, custom protocols
Zero Frontend Changes - Add drones by editing config file
Production-Ready - Proper separation of concerns
Full Ground Station - Works independently without QGroundControl

Quick Start

# 1. Clone repository
git clone https://github.com/flightpath-dev/flightpath-server
cd flightpath-server

# 2. Install dependencies
go mod tidy

# 3. Configure your drones (edit this file)
nano data/config/drones.yaml

# 4. Run server
go run cmd/server/main.go

# 5. Connect to drone (in another terminal)
./scripts/test.sh connect alpha

Message Flow

Frontend:

  1. Says "Connect to drone alpha"

Backend:

  1. Looks up "alpha" in drones.yaml
  2. Reads mavlink protocol, /dev/cu.usbserial-D30JAXGS, 57600 baud
  3. Creates MAVLink client
  4. Connects and returns success

Note: Frontend never knows about ports, protocols, or baud rates!

Configuration

Drone Registry

The data/config/drones.yaml file defines available drones. This file is committed to the repository and should be updated when adding new drones.

data/config/drones.yaml

drones:
  - id: "alpha"
    name: "Alpha X500"
    description: "Primary test drone - Holybro X500 V2"
    protocol: "mavlink"
    connection:
      type: "serial"
      port: "/dev/cu.usbserial-D30JAXGS"
      baud_rate: 57600

  - id: "bravo"
    name: "Bravo Quadcopter"
    description: "Secondary test drone"
    protocol: "mavlink"
    connection:
      type: "serial"
      port: "/dev/ttyUSB1"
      baud_rate: 115200

Data Directory Structure

data/
├── config/              # ✅ Version controlled - Configuration files
│   └── drones.yaml      # Drone registry
├── logs/                # ❌ Gitignored - Runtime logs
├── runtime/             # ❌ Gitignored - Runtime state
└── cache/               # ❌ Gitignored - Cached data

Environment Variables

You can override configuration using environment variables:

# Server configuration
export FLIGHTPATH_HOST=0.0.0.0
export FLIGHTPATH_PORT=8080

# MAVLink defaults (used if not specified in drone config)
export FLIGHTPATH_MAVLINK_PORT=/dev/ttyUSB0
export FLIGHTPATH_MAVLINK_BAUD=57600

# Drone registry location
export FLIGHTPATH_DRONE_REGISTRY=./data/config/drones.yaml

# Logging
export FLIGHTPATH_LOG_LEVEL=info  # debug, info, warn, error

Project Structure

flightpath-server/
├── cmd/
│   └── server/
│       └── main.go              # Server entry point
├── data/
│   └── config/
│       └── drones.yaml          # Drone configurations
├── internal/
│   ├── config/
│   │   ├── config.go            # Configuration types
│   │   ├── loader.go            # Environment variable loader
│   │   └── drones.go            # Drone registry loader
│   ├── mavlink/
│   │   └── client.go            # MAVLink protocol implementation
│   ├── middleware/
│   │   ├── cors.go              # CORS middleware
│   │   ├── logging.go           # Request logging
│   │   └── recovery.go          # Panic recovery
│   ├── server/
│   │   ├── dependencies.go      # Shared dependencies
│   │   └── server.go            # HTTP server setup
│   └── services/
│       ├── connection.go        # Connection service (protocol routing)
│       ├── control.go           # Control service
│       ├── mission.go           # Mission service
│       └── telemetry.go         # Telemetry service
├── scripts/
│   └── test.sh                  # Helper script for testing
├── go.mod
└── go.sum

API Services

1. ConnectionService

Manage drone connections by drone id.

# List all drones in registry
./scripts/test.sh list

# Connect to drone
./scripts/test.sh connect alpha

# Get connection status
./scripts/test.sh status alpha

# Disconnect
./scripts/test.sh disconnect alpha

2. ControlService

Send flight control commands.

# Arm drone (⚠️ REMOVE PROPELLERS FOR TESTING!)
./scripts/test.sh arm alpha

# Disarm drone
./scripts/test.sh disarm alpha

# Set flight mode
./scripts/test.sh mode alpha GUIDED

# Takeoff to 10 meters
./scripts/test.sh takeoff alpha 10

# Land
./scripts/test.sh land alpha

# Return home
./scripts/test.sh rtl alpha

# Go to position (must be in GUIDED mode)
./scripts/test.sh goto alpha 42.5063 -71.1097 50

Position Commands:

GoToPosition allows dynamic control of the drone's position. The drone flies to the specified GPS coordinates and altitude.

Requirements:

  • Drone must be in GUIDED mode
  • Drone must be armed
  • GPS lock required (satellite count ≥ 6)

Position Format:

  • Latitude: degrees (e.g., 42.5063)
  • Longitude: degrees (e.g., -71.1097)
  • Altitude: meters MSL (e.g., 50)
# Example: Fly to specific coordinates at 50m altitude
./scripts/test.sh goto alpha 42.5063 -71.1097 50

3. TelemetryService

Stream real-time telemetry data from the drone.

Features:

  • Real-time position (GPS coordinates, altitude)
  • Velocity (3D velocity vector)
  • Attitude (roll, pitch, yaw)
  • Battery status (voltage, current, remaining %)
  • System health (sensors, GPS)
  • Flight mode
  • GPS accuracy and satellite count
# Get telemetry snapshot (single point-in-time reading)
./scripts/test.sh snapshot alpha

# Monitor telemetry (continuous updates every 2 seconds)
./scripts/test.sh monitor alpha

Telemetry Data Available:

  • Position: Latitude, longitude, altitude (MSL)
  • Velocity: North, east, down components (m/s)
  • Attitude: Roll, pitch, yaw (radians)
  • Battery: Voltage (V), current (A), remaining (%)
  • Health: Sensor status, GPS status
  • Navigation: Heading (°), ground speed (m/s), vertical speed (m/s)
  • GPS: Accuracy (m), satellite count
  • Status: Armed state, flight mode

4. MissionService

Autonomous mission planning and execution.

Features:

  • Upload waypoint missions to drone
  • Start/pause/resume mission execution
  • Clear missions from drone
  • Track mission progress (current waypoint)
  • Stream real-time progress updates

Not Yet Implemented:

  • Mission download from drone (planned for future)
# Upload a mission
./scripts/test.sh mission-upload alpha mission.json

# Start mission (switches to AUTO mode)
./scripts/test.sh mission-start alpha

# Pause mission (switches to LOITER)
./scripts/test.sh mission-pause alpha

# Resume mission
./scripts/test.sh mission-resume alpha

# Get mission progress
./scripts/test.sh mission-progress alpha

# Clear mission
./scripts/test.sh mission-clear alpha

Mission File Format (mission.json):

{
  "mission": {
    "id": "survey-001",
    "name": "Area Survey",
    "waypoints": [
      {
        "sequence": 0,
        "action": "ACTION_TAKEOFF",
        "position": {
          "latitude": 42.5063,
          "longitude": -71.1097,
          "altitude": 20
        }
      },
      {
        "sequence": 1,
        "action": "ACTION_WAYPOINT",
        "position": {
          "latitude": 42.5070,
          "longitude": -71.1090,
          "altitude": 30
        },
        "hold_time_sec": 5,
        "acceptance_radius": 2.0
      },
      {
        "sequence": 2,
        "action": "ACTION_LAND",
        "position": {
          "latitude": 42.5063,
          "longitude": -71.1097,
          "altitude": 0
        }
      }
    ]
  }
}

Waypoint Actions:

  • ACTION_TAKEOFF - Takeoff to altitude
  • ACTION_LAND - Land at position
  • ACTION_WAYPOINT - Fly to waypoint
  • ACTION_LOITER - Circle indefinitely at position
  • ACTION_HOLD - Hold position for specified time

Waypoint Parameters:

  • sequence - Waypoint order (0-indexed)
  • position - Latitude, longitude, altitude (MSL in meters)
  • hold_time_sec - How long to hold at waypoint (optional)
  • acceptance_radius - Radius to consider waypoint reached (optional, meters)
  • heading - Target heading at waypoint (optional, degrees)

Flight Modes for API Control

Flightpath is designed for API-controlled flight without RC transmitter. Understanding flight modes is critical for safe operation.

GUIDED Mode (Recommended for API Control)

Use for: Dynamic position commands from the API

What is GUIDED?

  • Holds GPS position automatically (no drift)
  • Accepts position/velocity commands from API
  • Responds immediately to GoToPosition commands
  • When not commanded, hovers safely in place
  • Think: "Position hold + API control enabled"

Stay in GUIDED for entire flight:

# 1. Connect and arm
./scripts/test.sh connect alpha
./scripts/test.sh arm alpha

# 2. Set GUIDED mode
./scripts/test.sh mode alpha GUIDED

# 3. Takeoff
./scripts/test.sh takeoff alpha 20

# 4. Send position commands
./scripts/test.sh goto alpha 42.5070 -71.1090 25
./scripts/test.sh goto alpha 42.5065 -71.1085 30

# 5. Land
./scripts/test.sh land alpha

# 6. Disarm
./scripts/test.sh disarm alpha

Why GUIDED?

  • ✅ Can send position commands at any time
  • ✅ Holds position safely when not commanded
  • ✅ No mode switching between commands
  • ✅ Most responsive to API commands

POSITION_HOLD Mode (Safety Lockdown)

Use for: Preventing API commands (safety feature)

What is POSITION_HOLD?

  • Holds GPS position automatically (no drift)
  • Rejects position/velocity commands from API
  • Only responds to RC stick inputs (if connected)
  • Think: "Hold position and ignore external commands"
# Switch to POSITION_HOLD to "freeze" drone
./scripts/test.sh mode alpha POSITION_HOLD

When to use:

  • 🔒 Lock drone in place (prevent buggy API commands)
  • 🛑 Pause API control temporarily
  • ⏸️ Debugging/development pause

Key Difference:

Scenario: API sends GoToPosition command

GUIDED mode:
  → ✅ "Roger, flying to new position"

POSITION_HOLD mode:
  → ❌ "Ignoring command, holding current position"

AUTO Mode (Mission Control) ⭐ Safest for Autonomous

Use for: Pre-programmed waypoint missions

What is AUTO?

  • Follows uploaded waypoint mission
  • Fully autonomous (takeoff → waypoints → land)
  • Safest for predictable, pre-planned flights
  • No real-time API commands needed

Mission workflow:

# 1. Create mission file with waypoints (see mission.json format above)

# 2. Connect and upload mission
./scripts/test.sh connect alpha
./scripts/test.sh mission-upload alpha mission.json

# 3. Arm and start mission
./scripts/test.sh arm alpha
./scripts/test.sh mission-start alpha

# Mission runs automatically: takeoff → waypoints → land
# Monitor progress
./scripts/test.sh mission-progress alpha

# Pause if needed
./scripts/test.sh mission-pause alpha

# Resume
./scripts/test.sh mission-resume alpha

Why AUTO for missions?

  • ✅ Pre-planned safe path (reviewed before flight)
  • ✅ Includes takeoff and landing waypoints
  • ✅ Most predictable behavior
  • ✅ Best for unattended operations
  • ✅ Automatic failsafes (geofence, battery RTL)

RTL Mode (Return to Launch)

Use for: Emergency return home

What is RTL?

  • Autonomous return to launch position
  • Climbs to safe altitude, flies home, lands
  • Triggered automatically on low battery or geofence breach
  • Can be commanded via API
# Emergency return home
./scripts/test.sh rtl alpha

Other Modes

Additional modes available for specific use cases:

STABILIZED - Attitude stabilization only (manual control)

./scripts/test.sh mode alpha STABILIZED

ALTITUDE_HOLD - Holds altitude, manual horizontal control

./scripts/test.sh mode alpha ALTITUDE_HOLD

MANUAL - Full manual control (no stabilization)

./scripts/test.sh mode alpha MANUAL

LOITER - Circle around current position

./scripts/test.sh mode alpha LOITER

Mode Comparison

Mode Accepts API Commands Best For Safety
GUIDED ✅ Yes Dynamic API control ⭐⭐⭐⭐
POSITION_HOLD ❌ No Safety lockdown ⭐⭐⭐⭐⭐
AUTO (Mission) ❌ No (follows mission) Pre-planned autonomous ⭐⭐⭐⭐⭐
RTL ❌ No (autonomous return) Emergency return ⭐⭐⭐⭐⭐
ALTITUDE_HOLD ❌ No Manual flight with altitude hold ⭐⭐⭐
STABILIZED ❌ No Manual flight with stabilization ⭐⭐
MANUAL ❌ No Full manual control
LOITER ❌ No Circle position ⭐⭐⭐⭐

PX4 Mode Mapping Reference

Flightpath uses generic flight mode names that map to PX4-specific modes:

Flightpath Mode PX4 Main Mode PX4 Sub Mode PX4 Mode Value Description
MANUAL MANUAL (1) - 1 Full manual control
STABILIZED STABILIZED (7) - 7 Attitude stabilization
ALTITUDE_HOLD ALTCTL (2) - 2 Altitude control
POSITION_HOLD POSCTL (3) - 3 GPS position hold
GUIDED OFFBOARD (6) - 6 External position control (API)
AUTO AUTO (4) MISSION (4) 262148 Follow mission waypoints
RETURN_HOME AUTO (4) RTL (5) 327684 Return to launch
LAND AUTO (4) LAND (6) 393220 Land at position
TAKEOFF AUTO (4) TAKEOFF (2) 131076 Takeoff
LOITER AUTO (4) LOITER (3) 196612 Circle position

PX4 Mode Encoding:

  • Simple modes: Use main mode value directly
  • AUTO sub-modes: main_mode | (sub_mode << 16)
    • Example: RTL = 4 | (5 << 16) = 327684

Recommended Approach

For API Control (Dynamic Flight):

  1. Stay in GUIDED mode for entire flight
  2. Use GoToPosition to fly dynamically
  3. Drone holds position when not commanded (safe)
  4. Responds immediately to position commands
  5. Switch to POSITION_HOLD only to "freeze" drone

For Autonomous Operations (Pre-planned):

  1. Use AUTO mode with pre-programmed missions
  2. Upload mission including takeoff and landing
  3. Start mission and monitor progress
  4. Most predictable and safest for unattended flight

Flight Safety

Pre-Flight Checklist (No RC)

Before flying with API only:

  1. ⚠️ Remove propellers for initial testing
  2. ✅ Test mission in simulator first (if using AUTO mode)
  3. ✅ Verify GPS lock (satellite count ≥ 8)
  4. ✅ Check battery level (> 50% recommended)
  5. ✅ Confirm geofence is set correctly
  6. ✅ Set home position (for RTL)
  7. ✅ Verify clear flight area
  8. ✅ Test Return Home procedure
  9. ✅ Monitor telemetry during flight

Safe Command Sequence (API Control with Position Commands)

# Complete dynamic flight sequence with GUIDED mode

# 1. Connect to drone
./scripts/test.sh connect alpha

# 2. Check telemetry before flight
./scripts/test.sh snapshot alpha

# 3. Arm drone
./scripts/test.sh arm alpha

# 4. Set GUIDED mode (accepts API commands)
./scripts/test.sh mode alpha GUIDED

# 5. Takeoff
./scripts/test.sh takeoff alpha 20

# 6. Monitor telemetry
./scripts/test.sh snapshot alpha

# 7. Send position commands (fly square pattern)
./scripts/test.sh goto alpha 42.5070 -71.1097 25   # North
./scripts/test.sh goto alpha 42.5070 -71.1090 25   # East
./scripts/test.sh goto alpha 42.5063 -71.1090 25   # South
./scripts/test.sh goto alpha 42.5063 -71.1097 25   # West (back to start)

# 8. Land
./scripts/test.sh land alpha

# 9. Disarm
./scripts/test.sh disarm alpha

# 10. Disconnect
./scripts/test.sh disconnect alpha

Safe Command Sequence (Mission Mode)

# Complete autonomous mission sequence

# 1. Connect to drone
./scripts/test.sh connect alpha

# 2. Upload mission
./scripts/test.sh mission-upload alpha mission.json

# 3. Check telemetry
./scripts/test.sh snapshot alpha

# 4. Arm drone
./scripts/test.sh arm alpha

# 5. Start mission (automatically switches to AUTO mode)
./scripts/test.sh mission-start alpha

# 6. Monitor mission progress
./scripts/test.sh mission-progress alpha

# 7. Pause if needed
./scripts/test.sh mission-pause alpha

# 8. Resume if paused
./scripts/test.sh mission-resume alpha

# 9. After completion, disarm
./scripts/test.sh disarm alpha

# 10. Clear mission
./scripts/test.sh mission-clear alpha

# 11. Disconnect
./scripts/test.sh disconnect alpha

Emergency Procedures (No RC)

If something goes wrong:

  1. Return Home (Most Common)

    ./scripts/test.sh rtl alpha
  2. Hold Position (Stop and hover - switch to POSITION_HOLD)

    ./scripts/test.sh mode alpha POSITION_HOLD
  3. Pause Mission (If in AUTO mode)

    ./scripts/test.sh mission-pause alpha
  4. Emergency Land (Land immediately at current location)

    ./scripts/test.sh land alpha

⚠️ DO NOT use EmergencyStop - it cuts motors and drone will fall!

Automatic Failsafes

PX4/ArduPilot automatically handles:

  • Low Battery → Triggers RTL automatically
  • GPS Lost → Enters ALTITUDE_HOLD and hovers
  • Geofence Breach → Triggers RTL or LAND
  • Datalink Loss → Configured failsafe action (default: RTL)

API Connection Loss

If API/network connection is lost:

  • GUIDED mode → Continues hovering at last position (safe)
  • AUTO mode → Continues mission as programmed
  • If connection lost > timeout → Triggers failsafe (RTL)

Adding a New Drone

Step 1: Edit Configuration

Add your drone to data/config/drones.yaml:

drones:
  # ... existing drones ...
  
  - id: "charlie"
    name: "Charlie Custom"
    description: "Custom built quadcopter"
    protocol: "mavlink"
    connection:
      type: "serial"
      port: "/dev/ttyUSB2"
      baud_rate: 115200

Step 2: Restart Server

go run cmd/server/main.go

Step 3: Connect

./scripts/test.sh connect charlie

No code changes needed!

Supported Protocols

  • MAVLink (PX4, ArduPilot)
    • Serial connection (USB, UART)
    • UDP connection (for simulators) - planned
    • Full flight mode control
    • Arm/Disarm, Takeoff/Land, RTL
    • Real-time telemetry streaming
    • Mission upload and execution
    • Position commands (GoToPosition)
    • Ground station functionality:
      • Sends periodic HEARTBEAT (identifies as GCS)
      • Sends SYSTEM_TIME (GPS assistance for faster lock)
      • Requests telemetry data streams at 10 Hz
      • Satisfies PX4's COM_DL_LOSS_T datalink requirements
      • Works independently without QGroundControl
  • 🔜 DJI SDK - Planned
  • 🔜 Custom - Extensible architecture

Ground Station Features

Flightpath implements core ground control station functionality according to MAVLink protocol standards, enabling independent operation without QGroundControl.

Implemented MAVLink Services

1. Heartbeat Service (MAVLink Spec)

  • Sends periodic HEARTBEAT messages (1 Hz)
  • Identifies Flightpath as MAV_TYPE_GCS (Ground Control Station)
  • Satisfies PX4's COM_DL_LOSS_T datalink requirement

2. Command Protocol (MAVLink Spec)

  • ARM/DISARM commands
  • Takeoff, Land, Return-to-Launch
  • Flight mode changes
  • Position commands (GUIDED mode)

3. Mission Protocol (MAVLink Spec)

  • Upload waypoint missions
  • Start/pause/resume missions
  • Clear missions
  • Track mission progress
  • Note: Mission download not yet implemented

4. Telemetry Streams

  • Requests position, attitude, battery, GPS data
  • 10 Hz telemetry updates
  • Real-time monitoring via API

5. System Time Synchronization

  • Sends SYSTEM_TIME messages for GPS assistance
  • Enables GPS "warm start" (1-2 min lock vs 5-10 min cold start)

Not Implemented

Advanced GCS Features:

  • Parameter read/write (use QGC for parameter changes)
  • Flight log download (use QGC for logs)
  • File transfer protocol
  • Camera/gimbal control
  • Geofence/rally point management

References

Benefits

Independent Operation - Core functions work without QGroundControl
Fast GPS Lock - SYSTEM_TIME provides 1-2 minute acquisition
Full Flight Control - Complete API-driven flight operations
Mission Execution - Upload and run autonomous missions
Standards Compliant - Follows MAVLink protocol specifications

For Advanced Features: Use QGroundControl for parameter tuning, log analysis, and initial setup. After setup, Flightpath handles all flight operations.

Frontend Example

import { createClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-web";
import { ConnectionService } from "@flightpath-dev/flightpath-proto/gen/ts/drone/v1/connection_connect";

// Create transport
const transport = createConnectTransport({
  baseUrl: "http://localhost:8080",
});

// Create client
const client = createClient(ConnectionService, transport);

// Connect - that's all the frontend needs to know!
const response = await client.connect({
  droneId: "alpha"
});

console.log(response.message); 
// "Connected to Alpha X500 (System ID: 1)"

Testing

Complete Test Flow

# 1. Start server
go run cmd/server/main.go

# 2. In another terminal - test connection
./scripts/test.sh list                # List all drones
./scripts/test.sh connect alpha       # Connect to alpha
./scripts/test.sh status alpha        # Check status

# 3. Test telemetry
./scripts/test.sh snapshot alpha      # Get single telemetry reading
./scripts/test.sh monitor alpha       # Monitor telemetry (Ctrl+C to stop)

# 4. Test flight modes (propellers off!)
./scripts/test.sh arm alpha                  # Arm
./scripts/test.sh mode alpha GUIDED          # Set GUIDED mode
./scripts/test.sh mode alpha POSITION_HOLD   # Set POSITION_HOLD
./scripts/test.sh mode alpha AUTO            # Set AUTO mode
./scripts/test.sh disarm alpha               # Disarm

# 5. Test mission planning
./scripts/test.sh mission-upload alpha mission.json   # Upload mission
./scripts/test.sh mission-progress alpha              # Check progress
./scripts/test.sh mission-clear alpha                 # Clear mission

# 6. Test position commands (propellers off!)
./scripts/test.sh arm alpha                       # Arm
./scripts/test.sh mode alpha GUIDED               # Set GUIDED mode
./scripts/test.sh goto alpha 42.5063 -71.1097 50  # Send position
./scripts/test.sh disarm alpha                    # Disarm

# 7. Full flight test with position commands (after successful tests)
./scripts/test.sh arm alpha                       # Arm
./scripts/test.sh mode alpha GUIDED               # Set GUIDED mode
./scripts/test.sh takeoff alpha 20                # Takeoff to 20m
./scripts/test.sh goto alpha 42.5070 -71.1097 25  # Fly north
./scripts/test.sh goto alpha 42.5070 -71.1090 25  # Fly east
./scripts/test.sh land alpha                      # Land
./scripts/test.sh disarm alpha                    # Disarm

# 8. Full mission test (after successful mode tests)
./scripts/test.sh mission-upload alpha mission.json  # Upload
./scripts/test.sh arm alpha                          # Arm
./scripts/test.sh mission-start alpha                # Start mission
./scripts/test.sh mission-progress alpha             # Monitor
./scripts/test.sh disarm alpha                       # After completion

# 9. Emergency procedures
./scripts/test.sh rtl alpha                     # Return home
./scripts/test.sh mode alpha POSITION_HOLD      # Hold position
./scripts/test.sh mission-pause alpha           # Pause mission

# 10. Cleanup
./scripts/test.sh disconnect alpha    # Disconnect

Available Test Commands

./scripts/test.sh list                                # List drones
./scripts/test.sh connect <drone_id>                  # Connect to drone
./scripts/test.sh disconnect <drone_id>               # Disconnect
./scripts/test.sh status <drone_id>                   # Get status
./scripts/test.sh snapshot <drone_id>                 # Get telemetry snapshot
./scripts/test.sh monitor <drone_id>                  # Monitor telemetry (live)
./scripts/test.sh arm <drone_id>                      # Arm
./scripts/test.sh disarm <drone_id>                   # Disarm
./scripts/test.sh mode <drone_id> <MODE>              # Set flight mode
./scripts/test.sh takeoff <drone_id> <alt>            # Takeoff
./scripts/test.sh land <drone_id>                     # Land
./scripts/test.sh rtl <drone_id>                      # Return home
./scripts/test.sh goto <drone_id> <lat> <lon> <alt>   # Go to position
./scripts/test.sh mission-upload <drone_id> <file>    # Upload mission
./scripts/test.sh mission-start <drone_id>            # Start mission
./scripts/test.sh mission-pause <drone_id>            # Pause mission
./scripts/test.sh mission-resume <drone_id>           # Resume mission
./scripts/test.sh mission-progress <drone_id>         # Get progress
./scripts/test.sh mission-clear <drone_id>            # Clear mission

Available modes: MANUAL, STABILIZED, ALTITUDE_HOLD, POSITION_HOLD, GUIDED, AUTO, RETURN_HOME, LAND, TAKEOFF, LOITER

Development

Install Dependencies

# Install Go dependencies
go mod tidy

# Install buf (for proto generation)
brew install bufbuild/buf/buf  # macOS
# or
go install github.com/bufbuild/buf/cmd/buf@latest

Update Proto Definitions

Proto definitions are in a separate repository: flightpath-proto

To update to a new proto version:

# Update proto dependency
go get -u github.com/flightpath-dev/flightpath-proto@latest

# Update go.mod
go mod tidy

# Restart server
go run cmd/server/main.go

Run Tests

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run specific package tests
go test ./internal/config

Troubleshooting

"Drone not found in registry"

Check that your drone ID exists in data/config/drones.yaml:

# List available drones
./scripts/test.sh list

"Failed to create MAVLink connection"

  1. Check serial port exists:

    # Linux
    ls /dev/ttyUSB*
    
    # macOS
    ls /dev/tty.usbserial-*
  2. Check permissions:

    # Linux - add user to dialout group
    sudo usermod -a -G dialout $USER
    
    # macOS - no special permissions needed
  3. Verify baud rate matches your drone's configuration (usually 57600 or 115200)

"Connection timeout"

  1. Check drone is powered on
  2. Verify serial cable is connected
  3. Confirm baud rate in drones.yaml matches drone settings
  4. Test with QGroundControl first to verify hardware connection

"Mode change failed" or "Command denied"

  1. Check drone is armed (some modes require armed state)
  2. Verify GPS lock for GPS-dependent modes (GUIDED, POSITION_HOLD, AUTO, RTL)
  3. Check pre-arm checks passed
  4. Review drone logs for specific error messages

"No telemetry data" or "Zero values"

  1. Ensure drone is fully powered on and booted
  2. Wait for GPS lock (satellite count ≥ 6)
  3. Verify MAVLink messages are being received (check server logs)
  4. Some telemetry requires GPS lock before reporting valid data

"Mission upload failed"

  1. Verify mission JSON format is correct
  2. Check waypoint coordinates are valid (lat/lon in degrees)
  3. Ensure drone is connected and responsive
  4. Verify at least one waypoint in mission
  5. Check server logs for specific error messages

"Drone must be in GUIDED mode"

GoToPosition commands require GUIDED mode:

# Set GUIDED mode first
./scripts/test.sh mode alpha GUIDED

# Then send position commands
./scripts/test.sh goto alpha 42.5063 -71.1097 50

GPS Not Locking (Red LED)

With Flightpath as GCS:

  1. Ensure you're outdoors with clear sky view
  2. Wait 1-2 minutes for GPS warm start (Flightpath sends SYSTEM_TIME)
  3. Check GPS antenna is facing up (ceramic side)
  4. Verify GPS module is powered and connected
  5. Check server logs for "Sending SYSTEM_TIME" messages

First time setup:

  • Use QGroundControl once to calibrate compass
  • Compass must be calibrated at your flying location
  • After compass calibration, Flightpath will work independently

Port already in use

# Check what's using port 8080
lsof -i :8080

# Kill the process
kill -9 <PID>

# Or use a different port
export FLIGHTPATH_PORT=8081
go run cmd/server/main.go

Roadmap

  • Iteration 1 ✅ - Connection and basic control (MAVLink)
  • Iteration 2 ✅ - Protocol-agnostic architecture
  • Iteration 3 ✅ - Flight mode control (GUIDED, POSITION_HOLD, AUTO, RTL)
  • Iteration 4 ✅ - Real-time telemetry streaming
  • Iteration 5 ✅ - Mission planning and waypoints
  • Iteration 6 ✅ - Position commands (GoToPosition)
  • Iteration 7 ✅ - Proper ground station (HEARTBEAT, SYSTEM_TIME, data streams)
  • Iteration 8 📋 - React frontend
  • Iteration 9 📋 - Authentication

License

MIT

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

For proto changes, see the flightpath-proto repository.

Support

For issues or questions:

  • Open an issue on GitHub
  • Check existing documentation
  • Review the proto definitions at flightpath-proto

About

Go backend for controlling drones through a unified, protocol-agnostic API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published