[Solved] MEAM620-Project 1 phase 1- Modeling and Control of a Quadrotor

$25

File Name: MEAM620-Project_1_phase_1-_Modeling_and_Control_of_a_Quadrotor.zip
File Size: 584.04 KB

SKU: [Solved] MEAM620-Project 1 phase 1- Modeling and Control of a Quadrotor Category: Tag:
5/5 - (1 vote)

Introduction

In this project you will put your knowledge of quadrotor dynamics to work by developing algorithms for control. A good controller is the backbone of any quadrotor autonomy stack and thus it is crucial that you understand the theory and implementation in this project. You will be reusing the code throughout this course; during the lab session you will use it to fly a real, physical quadrotor! All code written in this project will be in Python. Refer to the instructions on Piazza for more information about which version to use and getting set up.

Figure 1: The CrazyFlie 2.0 robot that will be used in the lab and exercises. An Euler Z-X-Y transformation takes the inertial frame A to the body-fixed frame B. First a rotation by around the a3 axis is performed, then a roll by around the (rotated!) a1 axis, and finally a pitch by around the (now twice rotated!) a2 axis. A translation r then produces the coordinate system B, coinciding with the center of mass C of the robot, and aligned along the arms.

Modeling

Coordinate Systems and Reference frames

The coordinate systems and free body diagram for the quadrotor are shown in Fig. 1. The inertial frame, A, is defined by the triad a1, a2, and a3 with a3 pointing upward. The body frame, B, is attached to the center of mass of the quadrotor with b1 coinciding with the preferred forward direction and b3 being perpendicular to the plane of the rotors pointing vertically up during perfect hover (see Fig. 1). These vectors are parallel to the principal axes. More formally, the coordinates of a vector x that is expressed in A as x = Pi Axiai and in B as x = Pi Bxibi are transformed into each other by the rotation matrix ARB and translation vector ATB:

A A B A

x = RB x + TB . (1)

To express the rotational motion of the moving frame B, it is useful to introduce the angular velocity vector that describes how the basis vectors bi move:

d

bi = bi . (2)

dt

Note that this equation is coordinate free, meaning is not yet expressed explicitly in any particular coordinate system. We will denote the components of angular velocity of the robot in the body frame by p, q, and r:

= pb1 + qb2 + rb3. (3)

The heading (yaw) angle of the robot plays a special role since we can choose it freely without directly affecting the robots dynamics. For this reason we use Z X Y Euler angles to describe the transform from A to B: first a yaw rotation by around the a3 axis is performed, then a roll by around the (rotated!) a1 axis, and finally a pitch by around the (now twice rotated!) a2 axis [1] From the Euler angles one can compute the rotation matrix as follows:

The angular velocity and Euler angle velocities are related by:

(5)

2.2 Motor Model

This section describes how we model the motors. Each rotor has an angular speed i and produces a vertical force Fi according to:

Fi = kF i2. (6)

Experimentation with a fixed rotor at steady-state shows that kF 6.11 108 N/rpm2. The rotors also produce a moment according to

Mi = kMi2. (7)

The constant, kM, is determined to be about 1.5 109 Nm/rpm2 by matching the performance of the simulation to the real system.

Data obtain from system identification experiments suggest that the rotor speed is related to the commanded speed by a first-order differential equation i = km(ides i).

This motor gain, km, is found to be about 20s1 by matching the performance of the simulation to the real system. The desired angular velocities, ides, are limited to a minimum and maximum value determined through experimentation.

However, as a first approximation, we can assume the motor controllers to be perfect and the time constant km associated with the motor response to be arbitrarily small. In other words, we can assume the actual motor velocities i are equal to the commanded motor velocities, ides. Notes:

  1. In simulation, you will be able to directly command torque and thrust. The thrust limit is available as a parameter inside the simulator, although you dont need it for this project.
  2. In the lab, we will provide the code to translate torque and thrust to motor commands. You will however encounter saturation of your motors and may have to tweak your gains.

2.3 Rigid Body Dynamics: Newtons Equations of Motion for the Center of Mass

We will describe the motion of the center of mass (CoM) in the inertial (world) coordinate frame A. This makes sense because we will want to specify our waypoints (where the robot should fly), trajectories and controller targets (where the robot should be at this moment) in the inertial frame.

Newtons equation of motion for the robots CoM r is determined by the robots mass m, the gravitational force Fg = mg, and the sum of the motors individual forces Fi:

mr = Fg + XFi .iIn the coordinates of the inertial frame A this reads: (8)

. (9)

where ARB is the rotation matrix used in Eq (1) constructed via Eq (4). If the robot is tilted, the above equation will mix the propeller forces into the x and y plane and so generate horizontal acceleration of the robot. In other words, we can accomplish movement in all three directions by manipulating the attitude of the vehicle and its thrust.

Equation (9) further suggests that rather than using the forces Fi as control inputs, we should define our first input u1 as the sum:

. (10)

2.4 Eulers Equations of Motion for the Attitude

Since from Eq (9) we know that attitude control is necessary to generate horizontal motion, in this section we will examine how the motors affect the orientation of the vehicle.

In the inertial frame, the rate at which the robots angular momentum L = I changes is determined by the total moment M generated by the propellers:

L = M . (11)

While this equation looks clean and simple in the inertial frame, it is actually hard to work with because the inertial tensor I changes with the attitude of the robot, and is thus time dependent and non diagonal! For control purposes, this equation is best expressed in the body frame that is aligned with the principal axis, where the inertia tensor I is constant, and diagonal. However, since now the basis vectors bi are time-dependent, the equation for the time derivative of the angular momentum in the body frame becomes:

L = XBL ibi + XBLib i = XBL ibi + X BLibi = XBL ibi + L .i i i i iCombining (11) and (12), and using the fact that I is constant in B yields Eulers Equation: (12)
IB = BM B IB , (13)

where depending on context I means alternatingly a tensor or a matrix expressed in the body frame.

How do the motors come into play? First, by generating a force Fi that is a distance l away from the CoM, each motor can exert a torque that is in the b1, b2 plane. In addition, each rotor produces a moment Mi perpendicular to the plane of rotation of the blade. Rotors 1 and 3 rotate clockwise in the b3 direction while 2 and 4 rotate counter clockwise in the b3 direction. Since the moment produced on the quadrotor is opposite to the direction of rotation of the blades, M1 and M3 act in the b3 direction while M2 and M4 act in the b3 direction. In contrast to this, the forces Fi are all in the positive b3 direction due to the fact that the pitch is reversed on two of the propellers, see Fig

1.

Using this geometric intuition, and expressing the angular velocity in the body frame by p, q, and r as in Eq (3), the Euler equation (13) becomes:

. (14)

Note that the total net torque along the yaw (b3) axis of the robot is simply the signed sum of the motors torques Mi (why does the distance l to the center of the robot play no role?). We can rewrite this as:

l0 0 l . (15)

where is the relationship between lift and drag given by Equations (6-7). Accordingly, we will define our second set of inputs to be the vector of moments u2 given by:

u . (16)

Dropping the reference frame superscripts for brevity, we can now write the equations of motion for center of mass and orientation in compact form:

(17)

, (18)

where (17) is in inertial coordinates, and (18) is in body coordinates. The inputs u1 and u2 are related to the motor forces Fi via the linear system of equations formed by (10) and (16). We are thus facing a system governed by two coupled second order differential equations which we will exploit in section 3 to design controllers.

Robot Controllers

Trajectory Generation

Our ultimate goal is to make the robot follow a trajectory. For the time lets assume we are given a trajectory generator that for any given time t produces a trajectory target zdes(t) consisting of target position rT (t) and target yaw T (t):

zdes (19)

and its first and second derivatives zdes and zdes. To hover for example, the trajectory generator would produce a constant r(t) = r0 and e.g. a fixed (t) = 0, with all derivatives being zero.

The controllers job will then be to produce the correct torque u2 and thrust u1 to bring the robot to the desired state specified by the trajectory generator.

3.2 Linear Backstepping Controller

For this controller we will make the following assumptions:

  1. The robot is near the hover points, meaning the roll angle and pitch angle are small enough to allow linearization of trigonometric functions, i.e. cos() = 1, sin() = , cos() = 1, sin() = . This will allow us to linearize the rotation matrix in Eq (17).
  2. The robots angular velocity is small enough for the cross product term between angular momentum and velocity in (18) to be negligible. This is usually a good assumption for almost any quadrotor.
  3. The attitude of the quadrotor can be controlled at a much smaller time scale than the position. This backstepping approach to controller design allows a decoupling of position and attitude control loops. In practice this is generally warranted since the attitude controller usually runs almost an order of magnitude faster than the position controller.

Making the backstepping approximation is equivalent to assuming that R in Eq (17) can be commanded instantaneously. This further implies that it is possible to directly command the acceleration rdes. Figure 2 shows how trajectory generator, position, and attitude controller play together.

Figure 2: The position and attitude control loops.

Define the position error in terms of components by:

ei = (ri ri,T ).

In order to guarantee that this error goes exponentially to zero, we require

(rides ri,T ) + kd,i(ri ri,T ) + kp,i(ri ri,T ) = 0 . (20)

In Eq (20), ri,T and its derivatives are given by the trajectory generator, and ri and ri are provided by the state estimation system, allowing for the commanded acceleration rides to be calculated:

rides = ri,T kd,i(ri ri,T ) kp,i(ri ri,T ) . (21)

Now the attitude of the quadrotor must be controlled such that it will generate rdes. For this, the linearized version of (17) is used:

(22a)

(22b)

(22c)

From the third equation we can directly read off the thrust control u1. The first two equations can be solved for des and des, since des = T is given directly by the trajectory generator. Linearizing (18), we get:

, (23)

and by further exploiting that via Eq (5) Euler angle velocities are to linear approximation equal to angular velocities, it becomes evident that we can directly command the acceleration of the Euler angles:

. (24)

Thus the inner loop attitude control can also be done with a simple PD controller:

u , (25)

where the desired roll and pitch velocities pdes and qdes can be computed from the equations of motion and the specified trajectory [1], but in practice can be set to zero. [2]In summary, the controller then works as follows:

  1. Use Eq (21) to compute the commanded acceleration rdes.
  2. Use Eq (22c) to compute u1 and the desired angles des and des from (22a) and (22b).
  3. Use Eq (25) to compute u2.

3.3 A Geometric Nonlinear Controller

Nonlinear controllers are generally built based on geometric intuition, i.e. the quadrotors b3 axis is tilted to point in the desired direction, and thrust is applied. Such controllers are suitable for very aggressive maneuvers and will allow for faster flight and sharper turns, in particular in the simulator. Note that we have considerable freedom to choose a control algorithm so long as it results in a stable system.

The following section is based on the controller developed in [1], which in turn is a simplified version of the controller in [2]. For a thorough treatment and stability analysis please refer to [2].

It turns out that the basic layout of the controller remains as shown in Figure 2, i.e. there is an attitude and a position controller, although we no longer make the backstepping assumption.

We start out from the PD controller in Eq (21), but now write it in more compact vector form:

rdes = rT Kd(r rT ) Kp(r rT ) , (26)

where Kd and Kp are diagonal, positive definite gain matrices.

We are again faced with the question how to compute the inputs u1, u2 to generate rdes. We first determine the input u1. By rearranging Eq (17) one obtains:

. (27)

Note that the lhs of (27) is just the total commanded force Fdes (including gravity):

Fdes = mrdes . (28)

On the right hand side is u1, multiplied with the quadrotors axis b3 = R[0,0,1]T , expressed in the inertial frame. We obtain the input u1 by projecting Fdes onto b3:

Fdes . (29)

To compute u2, we observe that a quadrotor can only produce thrust along its b3 axis. It makes sense to align b3 with Fdes, and align b1 to match the desired yaw T . Please refer to Fig. 3. In the following steps we find a triad

Figure 3: Geometry based attitude control. First b3des is aligned along Fdes. Then b2des is chosen to be perpendicular to the plane spanned by the desired yaw heading vector a and b3des. This ensures that b1des and b3des are in the plane containing a.

Rdes = [b1des,b2des,b3des] that has the proper alignment, then proceed to develop a control input u2 that produces the corresponding torque to drive the attitude towards Rdes.

As indidicated, the b3des axis should be oriented along the desired thrust: Fdes

des

b3 = ||Fdes|| . (30)

Next, we want the b2des axis to be perpendicular to both b1des and the vector a that defines the yaw direction in the plane (a1, a2) plane:

a . (31)

This can be accomplished by forming the cross product between b3des and a:

des 3des a

b2(32)

Rdes = [b2des b3des,b2des,b3des] .Next, we need a measure for the error in orientation RdesT R. The following error vector (see [1]) (33)
R 1 desT RT Rdes)e = (R R (34)

which guarantees that the plane formed by b3des and the axis b1des representing the head of the robot contains the a. Finally, b1des is obtained by cross product and the desired rotation matrix is:

2

is obtained from the matrices by taking the operator that maps elements of so(3) to R3. This error vector is zero when Rdes = R. It is the rotation vector that generates the error in orientation. Consequently, by applying a torque along its direction it can be decreased, suggesting the control input:

u2 = I(KReR Ke) , (35)

where e = des is the error in angular velocities and KR and K are diagonal gains matrices. The desired angular velocities des can be computed from the output of the trajectory generator zT and its derivatives, but setting them to zero will work for the purpose of this project.

To summarize, the steps to implement the controller are:

  1. calculate Fdes from Eq (28), (27), and (26).
  2. compute u1 from Eq (29)
  3. determine Rdes from Eq (33) and the definitions of bides.
  4. find the error orientation error vector eR from Eq (34) and substitute for e.
  5. compute u2 from Eq (35).

4 System Description

4.1 Quadrotor Platform

For this project we will be using the CrazyFlie 2.0 platform made by Bitcraze, shown in Fig. 1. The CrazyFlie has a motor to motor (diagonal) distance of 92mm, and a mass of 30g, including a battery. A microcontroller allows lowlevel control and estimation to be done onboard the robot. An onboard IMU provides feedback of angular velocities and accelerations.

4.2 Software and Integration

Position control and other high level commands are computed in Python and sent to the robot via the CrazyRadio (2.4GHz). Attitude control is performed onboard using the microcontroller, though you will control it in simulation.

4.3 Inertial Properties

Since bi are principal axes, the inertia matrix referenced to the center of mass along the bi reference triad, I, is a diagonal matrix. In practice, the three moments of inertia can be estimated by weighing individual components of the quadrotor and building a physically accurate model in SolidWorks. The key parameters for the rigid body dynamics for the CrazyFlie platform are as follows:

  • mass: m = 0.030kg;
  • the distance from the center of mass to the axis of a motor: l = 0.046m; and (c) the components of the inertia dyadic using bi in kg m2:

Note that these constants have already been incorporated into the provided Python simulator.

5 Project Work

5.1 Code Packet

We have provided you with a project packet that contains all the code you need to complete this assignment. The flightsim directory contains the quadrotor simulator; you will not need to make any changes to the enclosed files but you may want to poke around to see how it works under the hood. Inside the proj11 directory you will find two folders: code contains files with code stubs for you to complete for this assignment and util contains a test suite for judging the performance of your controller offline.

The file code/sandbox.py will run the simulator with your controller on the trajectory specified within and produce plots of the state of the quadrotor over time useful for performance tuning as well as an animation of the result. Additionally, a test script (util/test.py) and a few test cases specified as util/*.json files will help you judge the performance of you implementation offline and gain familiarity with the testing system (more on this later). Additionally, at the root of the packet is an important file called setup.py. This file specifies the additional python packages necessary to run the simulator and can be used to automatically install those dependencies in your python environment. For more of this see the piazza post on Python and Pycharm.

Before implementing your own functions, you should first try running code/sandbox.py. It should produce a number of plots displaying useful information about the state of the quadrotor over time as well as a short animation showing the quadrotor in action. Because you havent implemented your controller yet you will get an error in the console and the animation will show your quadrotor falling out of the sky. This is because the outputs of the update function in se3control.py are all zeros and thus no thrust is generated.

5.2 Tasks

For this project you will complete the implementation of a controller in se3control.py and a waypoint trajectory generator in waypointtraj.py:

  1. waypoint traj.py

You will first implement a waypoint trajectory class. This class holds a set of desired waypoints for the quadrotor to visit and subsequently must prescribe a state for each instant in time that if followed by the quadrotor will ensure it visits each point. In particular, you will populate the dict flatoutput containing position (x), velocity (xdot), acceleration (xddot), jerk (xdddot), snap (xddddot), yaw angle (yaw), and angular rate (yawdot). For more information see the doc strings for each function in waypointtraj.py.

  1. se3 control.py

Next you will implement a controller that drives the quadrotor towards the state specified by the waypoint trajectory class. As mentioned before, this controller will be used throughout project 1. The controller is implemented as a class that holds the physical parameters of the robot and produces motor speed commands (cmdmotorspeeds) given the current time and state of the quadrotor as well as the desired state (flatoutput). For more information see the doc strings for each function in se3control.py.

Although in this phase of the project you will only need to output motor speeds, you should also set the corresponding commanded thrust (cmdthrust), moment (cmdmoment), and attitude (cmdq). Although they will be ignored in the simulator, they can be useful for debugging purposes and will be used when you fly in the lab.

Hints:

  1. py ships with a hover trajectory generator built in; use it to first implement and tune your controller then move on to filling out waypointtraj.py.
  2. Make sure that your controller can also handle arbitrary yaw targets, and test that it works! Beware of yaw angle wrap-around.
  3. Tune attitude and position gains separately. Which ones should you do first?

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] MEAM620-Project 1 phase 1- Modeling and Control of a Quadrotor
$25