Path planning and autopilot design for a tilt bicopter UAV, covering 6-DOF dynamics, LQR control, AHRS attitude estimation, and RRT-based path planning with obstacle avoidance, implemented in MATLAB and Simulink.
Course: Aerial Robotic Design
Department: Aerospace Engineering, Sharif University of Technology
Authors: Sepehr Mahfar & Mohammad Nayebi
Date: July 2024
This project presents a complete autopilot pipeline for a tilt bicopter — an underactuated UAV with two tilting rotors providing four control channels. The workflow proceeds from Newton–Euler derivation of the equations of motion through LQR control design, AHRS-based state estimation, and finally RRT-based path planning with path smoothing and management.
All derivations, implementation details, and simulation results are documented in Report.pdf.
.
├── Animations/
│ ├── Pitch_ramp.mp4 # Pitch channel ramp response animation
│ ├── Pitch_Sine-.mp4 # Pitch channel sine response animation
│ ├── Roll_Ramp.mp4 # Roll channel ramp response animation
│ ├── Roll_Sine.mp4 # Roll channel sine response animation
│ ├── Yaw_Ramp.mp4 # Yaw channel ramp response animation
│ └── Yaw_Sine.mp4 # Yaw channel sine response animation
├── Codes/
│ ├── RRT_Code.m # RRT path planning algorithm
│ ├── PathSmoothing.m # Path smoothing algorithm
│ ├── insertPoints.m # Path management and waypoint insertion
│ ├── K_Mat.m # LQR gain matrix computation
│ ├── LQR_Controller.slx # Simulink — LQR closed-loop simulation
│ ├── PID_Controller.slx # Simulink — PID closed-loop simulation
│ ├── datacnavlab.mat # Navigation lab sensor data
│ ├── linsys1.mat # Linearised bicopter state-space model
│ ├── Q.mat # LQR state weighting matrix
│ ├── R.mat # LQR input weighting matrix
│ └── Animation Codes/ # Scripts for generating flight animations
└── Report.pdf
The bicopter is modelled as a six-degree-of-freedom system using Newton–Euler relations. Four coordinate frames are defined — inertial, body, and two motor frames (one per rotor). The equations of motion cover:
- Angular velocity dynamics — rotational equations in body frame
- Euler angle kinematics — mapping body rates to Euler angle rates
- Translational dynamics — force balance in body frame
- Position kinematics — inertial position integration
External forces include gravity, aerodynamic drag, and rotor thrust. Moments arise from rotor thrust arms and rotor drag torques.
The bicopter is controlled by a Linear Quadratic Regulator (LQR) with four virtual control channels derived from rotor speeds and tilt angles:
uz = Ω₁² cos δ₁ + Ω₂² cos δ₂ (altitude)
uφ = Ω₁² cos δ₁ − Ω₂² cos δ₂ (roll)
uθ = Ω₁² sin δ₁ + Ω₂² sin δ₂ (pitch)
uψ = Ω₁² sin δ₁ − Ω₂² sin δ₂ (yaw)
The LQR minimises a quadratic cost over the 12-state vector x = [pₐ, pₑ, p_d, u, v, w, φ, θ, ψ, p, q, r]ᵀ. The optimal gain matrix K is computed from the solution to the Algebraic Riccati Equation. Actuator commands (Ω₁, Ω₂, δ₁, δ₂) are recovered analytically via closed-form inversion relations.
Since the LQR requires all vehicle states, an Attitude and Heading Reference System (AHRS) is implemented. GPS provides position and velocity; Euler angles are estimated by fusing gyroscope and accelerometer/magnetometer data through a complementary filter:
- High-pass branch — gyroscope dead reckoning for high-frequency attitude rates
- Low-pass branch — accelerometer/magnetometer for low-frequency fixed positioning
Roll and pitch are initialised from the accelerometer specific-force measurement; yaw from the magnetometer.
The Rapidly-Exploring Random Tree (RRT) algorithm generates a collision-free waypoint sequence in an obstacle-rich 2D occupancy grid. At each iteration a random configuration is sampled, the nearest tree node is identified, and the tree is extended by the maximum connection distance (MCD = 1 m) if the segment is obstacle-free. A Voronoi bias drives exploration toward unvisited regions.
The raw RRT output is post-processed in two stages:
- Path smoothing — iteratively removes intermediate waypoints where a direct collision-free segment exists, reducing the path to five waypoints
- Path management — assigns active waypoints based on closest-approach criterion, converting the discrete list into a time-parameterised reference for the tracking controller
The LQR controller was benchmarked against a PID baseline on both a fixed-altitude square path and the RRT-generated path. Key results:
| Metric | LQR | PID |
|---|---|---|
| Squared error cost (RRT path) | — | baseline |
| Improvement | 66.34% | — |
| Overshoot (square path) | smaller | larger |
| Altitude settling time | faster | slower |
| File | Description |
|---|---|
LQR_Controller.slx |
Full closed-loop simulation with LQR autopilot and RRT path |
PID_Controller.slx |
Equivalent simulation with PID autopilot for comparison |
Six animations demonstrate the bicopter's attitude response to standard reference inputs across all three axes:
| File | Axis | Input |
|---|---|---|
Pitch_ramp.mp4 |
Pitch | Ramp |
Pitch_Sine-.mp4 |
Pitch | Sine |
Roll_Ramp.mp4 |
Roll | Ramp |
Roll_Sine.mp4 |
Roll | Sine |
Yaw_Ramp.mp4 |
Yaw | Ramp |
Yaw_Sine.mp4 |
Yaw | Sine |
- MATLAB R2023b or later
- Control System Toolbox
- Simulink
- Open MATLAB and navigate to the
Codes/directory - Run
K_Mat.mto compute the LQR gain matrix (requireslinsys1.mat,Q.mat,R.mat) - Run
RRT_Code.mto generate the planned path, thenPathSmoothing.mandinsertPoints.mto post-process it - Open
LQR_Controller.slxorPID_Controller.slxin Simulink to run the closed-loop autopilot simulation