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.go# 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
