A lightweight Python system for collecting MAVLink telemetry data from PX4 autopilots and performing real-time fault detection using neural network models. This system is designed for drone/UAV applications with defensive security and monitoring capabilities.
Waterfall Lite consists of several interconnected components that work together to:
- Stream MAVLink data from PX4 flight controllers at maximum rate
- Package data into uniform time batches for ML consumption
- Detect flight anomalies using trained neural networks
- Collect flight data for analysis and model training
- Inject parameter changes for flight controller reconfiguration
- firehose.py - High-frequency MAVLink data streaming from PX4
- uniform_pump.py - Time-batched data packaging for ML pipelines
- data_collector.py - Flight data collection and storage
- fault_detector.py - Real-time fault detection using neural networks
- models.py - Neural network architectures (CNN and NN classifiers)
- inject.py - Parameter injection and flight controller communication
- px4_param_api.py - Direct C API interface for PX4 parameters
- test.py - Testing and parameter manipulation utilities
- waterfall_dashboard.py - Unified real-time visualization dashboard
PX4 Autopilot → firehose.py → uniform_pump.py → {data_collector.py, fault_detector.py}
↓
models.py (fault detection)
↓
inject.py (parameter correction)
Install using uv (recommended):
uv add pymavlink
uv add torch
uv add numpy
uv add rich
uv syncOr with pip:
pip install pymavlink torch numpy rich rclpy- PX4-compatible flight controller (hardware or SITL)
- USB/serial connection to flight controller
- Python 3.8+ environment
- Connect flight controller via USB serial
- Default connection:
/dev/ttyACM0at2000000baud - Verify connection with:
lsusb(should show flight controller)
- Start PX4 SITL:
make px4_sitl gazebo - Default connection:
udp:127.0.0.1:14550
Launch the unified real-time visualization dashboard:
uv run python waterfall_dashboard.pyFeatures:
- Interactive Multi-Section Interface: Navigate with number keys [1-5]
- [1] System Overview - High-level status of all components
- [2] Firehose - Real-time MAVLink data streams with live attitude visualization
- [3] Uniform Pump - Data batching pipeline with animated packet flow
- [4] Fault Detector - Drone status monitoring with ASCII drone visualization
- [5] Drone Visualization - Comprehensive flight data (attitude, position, sensors, battery, RC)
Dashboard Sections:
🔥 Firehose Section:
- Live data stream rates for all MAVLink message types
- Real-time attitude visualization with roll/pitch/yaw bars
- Historical sparklines for attitude trends
- Connection status and message throughput
⚡ Uniform Pump Section:
- Animated packet flow visualization showing data condensation
- Real-time batch progress countdown with progress bar
- Multi-step/single-step mode animations
- Bleeding domain statistics and recent batch history
🧠 Fault Detector Section:
- ASCII drone diagram showing motor status (●=OK, ✗=Failed)
- Real-time fault monitoring with expected fault types
- Fault history table with timestamps and severity
- Motor RPM visualization (simulated)
🚁 Drone Visualization Section:
- 3D attitude display with animated bars
- Top-down position map showing drone location
- Battery level with trend analysis
- RC input channel visualization
- Comprehensive sensor data (IMU, GPS, magnetometer)
Optional Model Loading:
uv run python waterfall_dashboard.py --model-path /path/to/fault_model.pthNavigation:
- Number keys [1-5]: Switch between sections
- Q: Quit dashboard
- Real-time updates at 10Hz
Collect flight data during drone operations:
uv run python data_collector.pyWhat it does:
- Waits for drone takeoff
- Continuously collects sensor data during flight
- Saves timestamped data batches to
data/directory - Automatically stops when drone lands
Configuration:
- Data directory:
data/(auto-created) - Batch interval: Configurable in UniformPump
- Data format: JSON with timestamps
Run real-time fault detection:
uv run python fault_detector.py --model-path /path/to/model.pthWhat it does:
- Loads pre-trained neural network model
- Monitors flight data in real-time
- Detects anomalies and triggers alerts
- Initiates safety protocols when faults detected
- Reconfigures flight parameters automatically
Test parameter changes:
uv run python inject.pyWhat it does:
- Connects to flight controller via MAVLink
- Reads current PWM_MAIN_FUNC4 parameter
- Sets parameter to new value (default: 101)
- Verifies parameter change
Interactive testing and parameter manipulation:
uv run python test.py- data_collector.py: Main data collection application - run this during flights
- fault_detector.py: Real-time fault monitoring - run with trained models
- inject.py: Parameter injection utility - for testing parameter changes
- test.py: Development testing and debugging
- firehose.py: MAVLink data streaming engine with terminal dashboard
- uniform_pump.py: Data batching and time synchronization
- models.py: Neural network model definitions (CNN, NN_classifier)
- px4_param_api.py: Low-level PX4 parameter API wrapper
Edit connection strings in main() functions:
# Hardware connection
firehose = MavFirehose(
manager1,
connection='serial:/dev/ttyACM0:2000000',
serial_port='/dev/ttyACM0',
serial_baud=2000000,
)
# SITL connection
firehose = MavFirehose(
manager1,
connection='udp:127.0.0.1:14550'
)Configure uniform_pump.py settings:
uniformPump = UniformPump(
firehose,
multi_step_count=5, # Number of time steps
condensation_mode='multi_step', # 'raw', 'single_step', 'multi_step'
batch_interval=1.0, # Seconds between batches
bleeding_domain_duration=15.0, # Historical data window
)Neural network models in models.py:
- CNN: Convolutional neural network for image-like data (1x16x32 filters)
- NN_classifier: Fully connected network (86→256→256→64→3 neurons)
- Both support Monte Carlo dropout for uncertainty estimation
{
"data": {
"imu": [[accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z], ...],
"attitude": [[roll, pitch, yaw, rollspeed, pitchspeed, yawspeed], ...],
"position": [[x, y, z], ...],
"battery": [[voltage, current, remaining], ...]
},
"_batch_metadata": {
"batch_number": 123,
"condensation_mode": "multi_step",
"total_messages_in_batch": 45
}
}- imu: Accelerometer and gyroscope data
- attitude: Roll, pitch, yaw and rates
- position: Local NED coordinates
- velocity: Linear velocities
- battery: Power system status
- rc_channels: Radio control inputs
- servo_output: Actuator commands
This system is designed for defensive security applications only:
- ✅ Flight anomaly detection
- ✅ Safety monitoring and alerts
- ✅ Data collection for analysis
- ✅ Parameter validation and correction
- ❌ No offensive capabilities
- ❌ No malicious parameter injection
- ❌ No unauthorized system access
# Check USB connection
lsusb | grep -i px4
# Test serial connection
python -c "from pymavlink import mavutil; m = mavutil.mavlink_connection('/dev/ttyACM0', baud=2000000); print(m.wait_heartbeat())"
# Check permissions
sudo chmod 666 /dev/ttyACM0- Ensure drone is armed and flying for data collection to start
- Check
data/directory permissions - Monitor console output for connection status
- Verify MAVLink stream rates in firehose.py
- Verify model file path exists
- Check PyTorch model compatibility
- Ensure model architecture matches models.py definitions
- Validate input data dimensions (86 features for NN_classifier)
- Add message handling in
firehose.py_publish_typed_message() - Update data structures in
uniform_pump.py - Modify condensation logic for new data format
- Test with live MAVLink stream
- Collect training data using
data_collector.py - Process data according to model input requirements
- Train models using PyTorch (external training pipeline)
- Test models with
fault_detector.py
- Add new parameter types in
px4_param_api.py - Extend encoding/decoding in
inject.py - Test parameter changes in safe environment
- Validate with PX4 parameter documentation
This project is intended for research, education, and defensive security applications. Use responsibly and in accordance with applicable regulations.