This repository implements end-to-end vision-based control for autonomous drone navigation through ring sequences, combining imitation learning (DAgger) with Lyapunov-based safety verification. The system learns both a neural controller and a neural Lyapunov function jointly, ensuring stable and safe navigation behavior.
This work extends the joint training method for controllers and Lyapunov functions (inspired by Joint Training of Control Policies and Lyapunov Certificates) to vision-based end-to-end learning with a differentiable renderer. The key innovations are:
- Vision-based control: CNN-based controller processes rendered camera images to output control commands
- Differentiable rendering: End-to-end gradient flow from camera images through the controller
- Joint training: Simultaneous learning of both the control policy and Lyapunov safety certificate
- Safety guarantees: Learned Lyapunov function provides formal stability guarantees
- End-to-end vision control: Camera images → CNN → Control actions
- Joint training pipeline: Controller + Lyapunov function trained together
- Standalone controller training: DAgger-based imitation learning (no Lyapunov)
- Differentiable environment: Full gradient propagation through rendering
- Safety verification: Lyapunov-based stability certificates
- Adversarial training: PGD-based sampling for robust Lyapunov functions
Simultaneously learns both:
- Vision-based controller: CNN processes images to output control commands
- Lyapunov function: Neural network certifies stability and safety
This method alternates between:
- DAgger data collection from expert PID policy
- Adversarial sampling using PGD to find Lyapunov violations
- Joint optimization of both networks with safety-aware losses
python scripts/train/lyapdag_trainer.py --visualizeOutputs:
weights/joint_controller.pth- Trained vision-based controllerweights/joint_lyap.pth- Trained Lyapunov function
Traditional DAgger imitation learning that trains only the controller (no Lyapunov function). Useful for:
- Baseline comparisons
- Initial controller pretraining
- Systems where safety verification is not required
python scripts/train/dagger_trainer.py --visualizeOutputs:
weights/dagger_weights.pth- Trained controller weights
- Input:
- Rendered camera image (50×50×3)
- Velocity vector (4D: radial, vertical, yaw components)
- Relative gate position (3D)
- Architecture: CNN (feature extraction) + MLP (control mapping)
- Output: Control actions
[a_r, a_z, a_yaw](radial acceleration, vertical acceleration, yaw rate)
- Input: Drone state
[x, y, z, v_r, v_z, yaw, yaw_rate](7D) - Output: Scalar Lyapunov value V(x)
- Properties: Ensures V(x) decreases along trajectories, certifying stability
- Perspective projection with sigmoid edges
- Batch rendering support for efficient training
- Full gradient flow enables end-to-end learning
- 7D state space: position, velocity, yaw, yaw rate
- Physics simulation with gravity
- Double integrator dynamics
├── config.py # Centralized device/dtype configuration
├── agent.py # Drone dynamics & state update
├── controller.py # CNN-based vision controller
├── pid_controller.py # Expert PID controller (for DAgger)
├── environment.py # Differentiable ring rendering
├── map.py # Ring & map definitions
├── lyap.py # Lyapunov network definitions
├── utils.py # Rotations, trajectories, utilities
├── utils2.py # Lyapunov sampling, violation & projection
├── sampler.py # State space sampling
├── sublevel_sampler.py # Sublevel set sampling
├── scripts/
│ ├── train/ # Training scripts
│ │ ├── dagger_trainer.py # Standalone controller training
│ │ └── lyapdag_trainer.py # Joint controller + Lyapunov training
│ └── test/ # Testing scripts
│ ├── test_controller.py # Closed-loop testing
│ ├── lyap_tester.py # Lyapunov verification
│ └── propogate.py # Closed loop propagation gradient check
├── weights/ # Saved model weights (.pth files)
└── visualizations/ # Visualization tools
Install required packages:
pip install -r requirements.txtOr manually install:
pip install torch torchvision numpy matplotlib scipy Pillow- PyTorch (≥1.9.0): Deep learning framework for neural networks
- NumPy (≥1.19.0): Numerical computing
- Matplotlib (≥3.3.0): Visualization and plotting
- SciPy (≥1.5.0): Scientific computing (spline interpolation)
- Pillow (≥8.0.0): Image processing
- torchvision (≥0.10.0): Image transforms and utilities
-
Install dependencies (see Prerequisites section):
pip install -r requirements.txt
-
Train joint controller + Lyapunov function:
python scripts/train/lyapdag_trainer.py --visualize
-
Test the trained controller:
python scripts/test/test_controller.py --visualize
This work is inspired by the joint training approach described in:
Joint Training of Control Policies and Lyapunov Certificates
arXiv:2404.07956
Paper Link
Joint Training (lyapdag_trainer.py):
- Initialize controller and Lyapunov networks
- For each episode:
- Collect DAgger data: Expert PID policy generates (image, action) pairs
- Find adversarial samples: PGD searches for states violating Lyapunov conditions
- Optimize both networks: Joint loss includes control MSE + Lyapunov violation penalties
- Safety-aware losses ensure controller respects Lyapunov certificate
Standalone Training (dagger_trainer.py):
- Expert PID policy generates trajectories with mixed expert/learned actions (β-schedule)
- Train controller to mimic expert via MSE loss
- No Lyapunov component
test_controller.py: Closed-loop testing with visualizationlyap_tester.py: Verify Lyapunov function propertiespropogate.py: One-step forward propagation analysis