A Go-based server for autonomous drone control via the MAVLink protocol. For the front-end, see the Flightpath UI repository.
flightpath/
βββ cmd/ # Main applications for this project
β βββ server/ # Server entry point
β βββ main.go
βββ examples/ # API usage examples
βββ gen/ # gRPC code generated from protobufs
β βββ go/
β βββ ts/
βββ internal/ # Private application and library code
β βββ config/
β β βββ config.go # Configuration structure
β β βββ loader.go # Configuration loader
β βββ logger/ # Structured logger based on slog
β β βββ logger.go
β βββ mavlink/ # Drone side communication code
β β βββ command_dispatcher.go # Sends commands to drone
β β βββ message_receiver.go # Receives messages from Drone
β βββ middleware/ # Handlers to process HTTP requests
β β βββ cors.go # CORS middleware
β β βββ logging.go # Request logging middleware
β β βββ recovery.go # Panic recovery middleware
β βββ server/ # Server state and lifecycle management
β β βββ server.go
β βββ services/ # Core functionality offered by the application
β βββ context.go # Shared context for all services (config, logger, etc.)
β βββ mavlink_service.go # Distributes MAVLink messages to gRPC subscribers
βββ proto/ # Protocol Buffers definitions
β βββ flightpath/
β βββ mavlink_service.proto # Handles commands and messages from gRPC clients
βββ go.mod
βββ go.sum
# 1. Clone repository
git clone https://github.com/flightpath-dev/flightpath
cd flightpath
# 2. Install dependencies
go mod tidyStart a PX4 SITL by following the instructions in PX4 SITL Setup.
# 1. Run server
go run cmd/server/main.go
# 2. Monitor messages from the SITL
go run examples/message_monitor_flightpath/main.goSee sample logs:
# 1. Turn on the drone
# 2. Run the server with a serial port configuration
./scripts/run-serial.sh
# 3. Monitor messages from the drone
go run examples/message_monitor_flightpath/main.go# 1. Turn on the drone
# 2. Run the server with a UDP configuration
./scripts/run-udp.sh
# 3. Monitor messages from the drone
go run examples/message_monitor_flightpath/main.goFlightpath uses environment variables for configuration, following the 12-factor app pattern.
- FLIGHTPATH_GRPC_HOST: gRPC server host (string, default: "0.0.0.0")
- FLIGHTPATH_GRPC_PORT: gRPC server port (integer, 1-65535, default: 8080)
- FLIGHTPATH_GRPC_CORS_ORIGINS: Comma-separated list of allowed CORS origins (default: "http://localhost:3000")
- FLIGHTPATH_MAVLINK_ENDPOINT_TYPE: MAVLink endpoint type (string, required, default:
udp-server)- Valid values:
serial,udp-server,udp-client,tcp-server,tcp-client
- Valid values:
- FLIGHTPATH_MAVLINK_SERIAL_DEVICE: Serial device path (string, required if type is "serial")
- Example:
/dev/cu.usbserial-D30JAXGS(Mac),/dev/ttyUSB0(Linux) orCOM3(Windows)
- Example:
- FLIGHTPATH_MAVLINK_SERIAL_BAUD: Serial baud rate (integer, required if type is "serial", default: 57600)
- Example:
57600,115200
- Example:
- FLIGHTPATH_MAVLINK_UDP_ADDRESS: UDP address in "host:port" format (string, required for UDP endpoints, default: "0.0.0.0:14550")
- Example:
0.0.0.0:14550(server) or127.0.0.1:14550(client)
- Example:
- FLIGHTPATH_MAVLINK_TCP_ADDRESS: TCP address in "host:port" format (string, required for TCP endpoints)
- Example:
0.0.0.0:5760(server) or127.0.0.1:5760(client)
- Example:
- FLIGHTPATH_LOG_LEVEL: Log level (string, case-insensitive, default: "INFO")
- Valid values:
DEBUG,INFO,WARN,ERROR - Example:
export FLIGHTPATH_LOG_LEVEL=DEBUG
- Valid values:
- FLIGHTPATH_LOG_FORMAT: Log format (string, case-insensitive, default: "text")
- Valid values:
text,json text: Short, human-readable format (e.g.,INFO [main] Starting the server)json: Structured JSON format for log aggregation tools- Example:
export FLIGHTPATH_LOG_FORMAT=json
- Valid values:
# Server configuration
export FLIGHTPATH_GRPC_HOST=0.0.0.0
export FLIGHTPATH_GRPC_PORT=8080
export FLIGHTPATH_GRPC_CORS_ORIGINS=http://localhost:3000,http://localhost:4000
# MAVLink serial configuration
export FLIGHTPATH_MAVLINK_ENDPOINT_TYPE=serial
export FLIGHTPATH_MAVLINK_SERIAL_DEVICE=/dev/cu.usbserial-D30JAXGS
export FLIGHTPATH_MAVLINK_SERIAL_BAUD=57600
# Or MAVLink UDP configuration
export FLIGHTPATH_MAVLINK_ENDPOINT_TYPE=udp-server
export FLIGHTPATH_MAVLINK_UDP_ADDRESS=0.0.0.0:14550
# Logging configuration
export FLIGHTPATH_LOG_LEVEL=WARN
export FLIGHTPATH_LOG_FORMAT=textRun all tests:
go test ./...Run tests with coverage:
go test -cover ./...Run tests with verbose output:
go test -v ./...MIT
