|
| 1 | +# Drone Models |
| 2 | + |
| 3 | +Drone Models provides several model types with different complexity levels and capabilities. Understanding these differences will help you choose the right model for your application. |
| 4 | + |
| 5 | +## Model Types Overview |
| 6 | + |
| 7 | +| Model | Rotor Dynamics | Complexity | Physics Level | Best For | |
| 8 | +|-------|----------------|------------|---------------|----------| |
| 9 | +| `first_principles` | Yes | High | Full rigid body | High-fidelity simulation, MPC | |
| 10 | +| `so_rpy` | No | Low | Simplified | Fast simulation, learning | |
| 11 | +| `so_rpy_rotor` | Yes | Medium | Simplified + rotors | Balanced performance | |
| 12 | +| `so_rpy_rotor_drag` | Yes | High | Simplified + effects | High-speed flight | |
| 13 | + |
| 14 | +## Physics-Based Models |
| 15 | + |
| 16 | +### First Principles Model |
| 17 | + |
| 18 | +The most comprehensive model based on full rigid body dynamics with quaternion representation. |
| 19 | + |
| 20 | +**Features:** |
| 21 | +- Quaternion-based attitude representation (no singularities) |
| 22 | +- Full 6-DOF rigid body dynamics |
| 23 | +- Rotor spin-up dynamics with time constants |
| 24 | +- External force and torque disturbances |
| 25 | +- Mixing matrix for arbitrary motor configurations |
| 26 | + |
| 27 | +**When to use:** |
| 28 | +- High-fidelity simulations |
| 29 | +- Model Predictive Control (MPC) |
| 30 | +- Research requiring accurate dynamics |
| 31 | +- Hardware-in-the-loop testing |
| 32 | + |
| 33 | +```python |
| 34 | +from drone_models.first_principles import dynamics |
| 35 | +from drone_models.core import parametrize |
| 36 | + |
| 37 | +# Create parametrized model |
| 38 | +model = parametrize(dynamics, "cf2x_L250") |
| 39 | + |
| 40 | +# Use with rotor dynamics |
| 41 | +pos_dot, quat_dot, vel_dot, ang_vel_dot, rotor_vel_dot = model( |
| 42 | + pos, quat, vel, ang_vel, cmd, rotor_vel=rotor_vel |
| 43 | +) |
| 44 | +``` |
| 45 | + |
| 46 | +### SO(3) Roll-Pitch-Yaw Models |
| 47 | + |
| 48 | +Simplified models using Euler angle representation for faster computation. |
| 49 | + |
| 50 | +#### `so_rpy` - Basic Model |
| 51 | +- Direct thrust/torque mapping (no rotor dynamics) |
| 52 | +- Euler angle representation |
| 53 | +- Fastest execution |
| 54 | + |
| 55 | +#### `so_rpy_rotor` - With Rotor Dynamics |
| 56 | +- Adds rotor spin-up dynamics |
| 57 | +- Models motor response delays |
| 58 | +- Good balance of speed and accuracy |
| 59 | + |
| 60 | +#### `so_rpy_rotor_drag` - With Aerodynamic Effects |
| 61 | +- Includes drag and aerodynamic forces |
| 62 | +- Most complete simplified model |
| 63 | +- Better at high speeds |
| 64 | + |
| 65 | +**When to use:** |
| 66 | +- Real-time applications requiring speed |
| 67 | +- Reinforcement learning training |
| 68 | +- Educational demonstrations |
| 69 | +- Rapid prototyping |
| 70 | + |
| 71 | +```python |
| 72 | +from drone_models.so_rpy import dynamics as so_rpy_dynamics |
| 73 | +from drone_models.so_rpy_rotor import dynamics as so_rpy_rotor_dynamics |
| 74 | + |
| 75 | +# Fast model without rotor dynamics |
| 76 | +basic_model = parametrize(so_rpy_dynamics, "cf2x_L250") |
| 77 | + |
| 78 | +# Balanced model with rotor dynamics |
| 79 | +balanced_model = parametrize(so_rpy_rotor_dynamics, "cf2x_L250") |
| 80 | +``` |
| 81 | + |
| 82 | +## Data-Driven Models |
| 83 | + |
| 84 | +While the current focus is on physics-based models, the framework is designed to support data-driven approaches: |
| 85 | + |
| 86 | +**Planned features:** |
| 87 | +- Neural network residual models |
| 88 | +- Gaussian Process corrections |
| 89 | +- System identification tools |
| 90 | +- Sim-to-real adaptation |
| 91 | + |
| 92 | +## Model Capabilities |
| 93 | + |
| 94 | +### Rotor Dynamics |
| 95 | + |
| 96 | +Models with rotor dynamics (`first_principles`, `so_rpy_rotor`, `so_rpy_rotor_drag`) include: |
| 97 | + |
| 98 | +- **Motor time constants**: Realistic spin-up/spin-down behavior |
| 99 | +- **Command to thrust mapping**: Non-instantaneous response |
| 100 | +- **Rotor state tracking**: Additional state variables for rotor velocities |
| 101 | + |
| 102 | +### Symbolic Variants |
| 103 | + |
| 104 | +Each model provides both numeric and symbolic implementations: |
| 105 | + |
| 106 | +```python |
| 107 | +# Numeric for simulation |
| 108 | +from drone_models.first_principles import dynamics |
| 109 | + |
| 110 | +# Symbolic for optimization |
| 111 | +from drone_models.first_principles import symbolic_dynamics |
| 112 | + |
| 113 | +# Generate CasADi function for MPC |
| 114 | +X_dot, X, U, Y = symbolic_dynamics(model_rotor_vel=True) |
| 115 | +f = cs.Function('dynamics', [X, U], [X_dot]) |
| 116 | +``` |
| 117 | + |
| 118 | +### External Disturbances |
| 119 | + |
| 120 | +All models support external force and torque disturbances: |
| 121 | + |
| 122 | +```python |
| 123 | +# Add wind disturbance |
| 124 | +wind_force = np.array([2.0, 0.0, 0.0]) # 2 N force in x-direction |
| 125 | +turbulence_torque = np.array([0.1, 0.1, 0.0]) # Small torque disturbance |
| 126 | + |
| 127 | +derivatives = model(pos, quat, vel, ang_vel, cmd, rotor_vel, |
| 128 | + dist_f=wind_force, dist_t=turbulence_torque) |
| 129 | +``` |
| 130 | + |
| 131 | +## Choosing the Right Model |
| 132 | + |
| 133 | +### For Real-Time Control |
| 134 | +- **Fast control loops (>500 Hz)**: `so_rpy` |
| 135 | +- **Standard control (100-200 Hz)**: `so_rpy_rotor` |
| 136 | +- **High-fidelity control**: `first_principles` |
| 137 | + |
| 138 | +### For Simulation |
| 139 | +- **Educational/demos**: `so_rpy` or `so_rpy_rotor` |
| 140 | +- **Research simulation**: `first_principles` |
| 141 | +- **Large-scale studies**: `so_rpy` for speed |
| 142 | + |
| 143 | +### For Optimization (MPC) |
| 144 | +- **Real-time MPC**: `so_rpy_rotor` symbolic |
| 145 | +- **High-fidelity MPC**: `first_principles` symbolic |
| 146 | +- **Trajectory optimization**: Any symbolic variant |
| 147 | + |
| 148 | +### For Machine Learning |
| 149 | +- **RL training**: `so_rpy` for speed |
| 150 | +- **Sim-to-real**: `first_principles` + planned data-driven extensions |
| 151 | +- **System identification**: `first_principles` as ground truth |
| 152 | + |
| 153 | +## Performance Considerations |
| 154 | + |
| 155 | +### Computational Cost (relative) |
| 156 | +1. `so_rpy`: 1x (baseline) |
| 157 | +2. `so_rpy_rotor`: ~1.5x |
| 158 | +3. `so_rpy_rotor_drag`: ~2x |
| 159 | +4. `first_principles`: ~3x |
| 160 | + |
| 161 | +### Memory Usage |
| 162 | +- All models have minimal memory footprint |
| 163 | +- Batching scales linearly with batch size |
| 164 | +- GPU memory usage depends on batch size and backend |
| 165 | + |
| 166 | +### Accuracy Trade-offs |
| 167 | +- **Highest accuracy**: `first_principles` |
| 168 | +- **Good accuracy**: `so_rpy_rotor_drag` |
| 169 | +- **Acceptable accuracy**: `so_rpy_rotor` |
| 170 | +- **Basic accuracy**: `so_rpy` |
| 171 | + |
| 172 | +--- |
| 173 | + |
| 174 | +*Choose your model based on the trade-off between accuracy, computational cost, and your specific application requirements.* |
0 commit comments