Drone modeling, dynamics, and control
Nov 4, 2022
The math formatting can go haywire in some browsers. Try reading this as a PDF instead.
These are some quick notes I took from Dr. Guanya Shi’s aerial mobility lectures at CMU. Learn more about him at gshi.me.
1. Modeling aerial vehicles
Let be our robot’s state and be our control input. We describe our robot’s change in state as a function of its current state and some input:
Modeling concerns , how is found, and how our input influences it.
1.1. The rotor lift model
Let’s consider the motion of a single rotor, where:
- is thrust (in Newtons)
- is torque
- is air density
- is rotation speed
- is diameter
Under the rotor lift model:
In practice, engineers typically use a thrust to torque ratio, , and simplify the above as:
This ratio is typically very small, such that its much harder to control torque than it is to control thrust.
1.2. Modeling a 2D (planar) drone
Let:
- be position in the world frame
- be velocity in the world frame
- be the angle
- be the angular rate
- be the thrust per rotor
- be the gravity vector
- be mass, inertia, and arm length
Any motion model contains a system of four equations: the translational kinematics and dynamics, and the rotational kinematics and dynamics. As a reminder, dynamics refers to physical forces and moments.
We can model a 2D drone as:
Let’s make some simplifications. First, we define total thrust and torque .
Let’s then define an actuation matrix, which combines total thrust and torque into a single equation:
Finally, we define state and input as:
These additional formulas allow us to simplify the earlier equation as:
1.3. Modeling a quadrotor
Our 3D model will operate in two coordinate frames:
- , the right-handed world frame (also called the inertial frame)
- , the right-handed body frame
1.3.1. Orientation
are the axes of w.r.t. the world frame . The the orientation of our quadrotor is given by the rotation matrix . (The appendix briefly explains what means.)
We can also model orientation as a quaternion or in Euler parameterization.
1.3.2. Actuation matrix
Recall that an actuation matrix is a combined representation of the total thrust and torque of a drone, as a function of the individual thrusts of its rotors. In 2D this was a , but in 3D it’s a matrix:
where , the thrust-to-torque ratio specific to each drone.
1.3.3. Kinematics and dynamics
where is a special matrix that maps a vector to its skew-symmetric matrix form:
2. Setpoint and trajectory tracking controllers
2.1. The goal
Recall that modeling concerns the function , the change in our robot’s state given its current state and some input. Specifically, modeling studies how our state responds to some input .
By contrast, control is about designing some feedback controller or policy that leads to some desired trajectory or setpoint .
2.2. The trajectory tracking controller
It’s common for drone controllers to have what we call “double integrator dynamics.” That means that our input . Our tracking controller takes the form:
where is our feedforward term. If our goal is setpoint tracking, then .
What’s the point of the feedforward term, anyway? Well, our tracking error is . Then we can rework the earlier equation as:
The above only works if we add the feedforward term. The intuition is that this term allows us to predict and brace for future error states.
2.3. Cascaded trajectory tracking
In this approach, the nonlinear trajectory tracking task is separated into two linear controllers.
The first calculates a desired force vector that would align the drone with the target trajectory. The second calculates the desired rotor torques that would align the drone with the force vector.
This separation leads to two sets of gains. In the typical case where PD controllers are used, this means a for the force controller and for the torque controller.
Here’s some code for cascaded control:
def cascaded_control(self, p_d, yaw_d):
# Helpful stuff
e3 = np.array([0., 0., 1.])
z = self.R @ e3
# position control
K_P = 35.0
K_D = 6.0
# attitude control
K_Ptau = 200.0
K_Dtau = 40.0
f_d = -np.array([0., 0., -self.g]) - K_P * (self.p - p_d) - K_D * (self.v - v_d) + a_d
T = (f_d.T @ z) * self.m
z_d = f_d/norm(f_d)
# R_d is the combination of z_d and yaw_d
R_d = z_d + yaw_d
n = np.cross(e3, z_d)
rho = np.arcsin(norm(n))
if norm(n) == 0: # Check for divide by zero
R_EB = np.eye(3)
else:
R_EB = Rotation.from_rotvec(rho * (n/norm(n))).as_matrix()
R_AE = Rotation.from_euler('z', yaw_d).as_matrix()
R_d = R_AE @ R_EB
R_e = R_d.T @ self.R
# Skew symetric form
R_ess = R_e-R_e.T
# Vectorized
R_ev = np.array([R_ess[2,1], R_ess[0,2], R_ess[1,0]])
alpha = -K_Ptau * R_ev - K_Dtau * self.omega
# Map alpha to tau
Ji = self.J_inv
J = self.J
A = Ji @ np.cross(J@self.omega, self.omega)
tau = J @ (alpha - A)
Ttau = np.concatenate(([T], tau))
# Map [T, tau] to individual thrusts
# u = [T1, T2, T3, T4], one per rotor
u = self.B_inv @ Ttau
return u
And here are (some of) the equations used.
2.4. Linear systems and LQR
Given some linear state space model , where is the dynamics matrix and is the control matrix, we can design a policy , where is our gain matrix.
Our closed-loop system then becomes:
Our system is exponentially stable if is a Hurwitz matrix: all eigenvalues must have strictly negative real parts.
We can determine an optimal using LQR, pole placement, or related techniques.
3. Trajectory generation and optimization
3.1. Overview
We’ve studied methods by which drones can follow given trajectories. But where do these trajectories come from? How can we generate reasonable trajectories that link a drone’s current pose to some goal?
Let’s divide a drone’s tasks into three sections. First, modeling gives our drone a sense of how its state will change over time, especially given some input . After that, control leverages our model to move the drone toward a goal pose, or along some trajectory. Finally, planning concern how our desired poses or trajectories are generated.
Given two poses, there are an infinite number of trajectories that connect them. How can we narrow our options down? We consider feasibility and optimality (cost).
Let’s express trajectory optimization mathematically, with the assumption that our time window is fixed. We won’t consider time-optimal control here.
3.2. Differential flatness
The goal of differential flatness is to relate to a flat output. This allows us to transform nonlinear systems into linear controllable ones. The idea was expressed in this paper by Fliess, Lévine, Martin, and Rouchon in 1992.
3.2.1. Wheel on flat surface
As an example, consider a wheel of radius on a flat surface, where is the wheel’s position, is its angular velocity, and is the torque applied to it. Then and , and we can express position as a flat output, where:
In this scenario, we can easily generate smooth trajectories .
3.2.2. The 2D case
Recall that in the 2D drone scenario, and . Let’s define the drone’s body axes as:
Let jerk be and let snap be (yes, four dots!).
Our goal: build a 1-1 mapping between and , which would make a flat output:
Steps:
- , ,
This means that, lacking any bounds on our drone’s rotors, we can track any smooth trajectory using only !
3.2.3. Adding differential flatness to cascaded control
Using the equations derived above, our cascaded control equations become:
3.3. Trajectory planning with polynomials
Now that we can track any smooth trajectory within a bounded , let’s use polynomials to link waypoints. For simplicity we’ll consider the case of a 2D drone such that state .
Our goal is to generate a polynomial that links two waypoints within a final time under the following constraints:
Since we have nine constraints, we’ll need to design an 8th-order polynomial of the form:
In this 2D case, we can separate the trajectory into two equations, one for and one for .
As an example, suppose we wish to move the drone from position to . We can write ’s constraints in matrix form as:
’s constraints are identical except that the rightmost matrix is all zeros ().
Once we have both systems in matrix form, then we can take the inverse of the leftmost matrix to find the polynomials’ coefficients.
Appendix
Wait, what’s ?
For the uninitiated, the group of all possible rotations in 3D is called the special orthogonal group, denoted as . This is the set of all real matrices such that:
- and
- .
Similarly, the set of all 2D rotation matrices is called .
shows up a lot in robotics, especially in manipulation (think kinematic) and flight modeling. It’s less common in, say, autonomous driving, where the robot is basically constrained to one axis of rotation.
Recall that in linear algebra, a group is a set of elements, where the product of any two elements is just another element in the group, and the inverse of any element is also in the group.
In other words, given any two matrices , then and .