/ 4 min read
Polynomial Trajectory Optimization for Quadrotors
Our goal is to help drone perform a flight from point A to point B. Whole flight is usually broken into waypoints in order to cover some ground and define corners that we need to take into account. We cannot just connect the dots and call it a day. We need to obey physics and the natural way to go about is to generate a smooth curve called trajectory. Taking corner smoothly is quite important; we cannot just abandon velocity that goes through one waypoint to the other. We need to control velocity since jerk requires an instantaneous change in motors thrust. The problem is the motors canβt actually do that, so the trajectory becomes physically unrealizable.
We need to find a right cost function for quadrotors. Since they donβt care about position, velocity, acceleration or jerk - we need to find a higher derivative. Here comes the snap. As we prove in the next sections minimising snap is minimising motor effort directly - torques the motors need to produce.
Which derivative should you minimise?
All four trajectories connect the same start and goal in the same time but only one of them is physically realizable. Watch the snap bars at the bottom to see why.
Minimising snap means the motors change their torque output as little as physically possible while still completing the trajectory.
Where the polynomial order comes from
The right polynomial order isnβt chosen by intuition β itβs derived. The
Euler-Lagrange equation applied to the cost J = β« (Pβ½Κ³βΎ)Β² dt reduces to a single ODE:
dΒ²Κ³/dtΒ²Κ³ P(t) = 0The general solution is a polynomial of degree N = 2r β 1. For minimum snap (r=4), thatβs a 7th-order polynomial β not 5th, not 6th.
Each segment needs 2r boundary conditions to fully determine it: position, velocity, acceleration, and jerk at both endpoints. Exactly 8 constraints for 8 coefficients. No over or under-determination possible.
Scaling to multiple waypoints and further minimising of cost function
For M waypoints we need to solve one linear system, instead of M - 1 segments. Why? Coupling that is given by constraints causes that, derivatives throughout segments must match at junctions. Break that coupling and youβll get velocity that at the corners is jerky or even physically impossible.
Even given constraints we can optimize further, but we need to get some freedom. Some derivatives need to be free. This way we can move from polynomial coefficients space to endpoint derivative space.
This doesnβt stop us to optimise further. So far time was fixed between the waypoints. We planned the mission beforehand, assumed itβll take some defined time T, but it doesnβt have to be the case. We can use for that good, old gradient descent and calculate trajectories that manifest the trade-off between smoothness and time.
Gradient descent on the time-augmented cost J = J_r + Ξ£ c_k T_k finds the shortest feasible trajectory.
The gap between waypoints and trajectories
Hereβs the part that surprised me but is quite obvious if you think for a bit: obstacle-free waypoints donβt guarantee an obstacle-free trajectory.
A polynomial trajectory is a curve. It passes through infinitely many points between waypoints. The solver only sees boundary conditions (position, velocity, acceleration at endpoints). Everything in between is determined by smoothness alone, which has no concept of walls.
The fix is iterative: detect the first collision, sample a new obstacle-free waypoint from the path planner at that location, insert it, and re-solve.
Press Play to watch the replanning loop. Each iteration adds one waypoint (gold diamond) and recomputes the trajectory. Faint blue lines show earlier failed attempts. The final collision-free path is drawn in green.
This is just toy midpoint heuristic as βpath plannerβ in 2D. In real systems there are many useful algorithms like: RRT* or A*. Usually LiDAR is used for real time updates of the 3D occupancy maps.
The full stack
Here comes the full architectural insight. We combine path planning which is topology that asks: βis there a route?β and trajectory optimization which is part of geometry that asks: βwhatβs the smoothest curve?β. These are two different problems, but our demo iterates between them:
- Path plannerβs job: provide obstacle-free intermediate points
- Trajectory optimizerβs job: just fit the smoothest curve through all of those points