■ FIGURE 2.
PenAeroBot
assembly.
1
2
3
4
ITEM QTY
42
31
22
11
Parts List
PART NUMBER
CUT BRACKET
HORIZON TAL LEVER
BRACKET
VER TICAL LEVER
MATERIAL
ALUMINUM
POLYCARBONATE
ALUMINUM
POLYCARBONATE
to hover at an angle of θ = 45° and that the robot is
ref
initially resting at θ = 0°. This will give us an e = 45°, which
the PID controller would use to start the motor. A second
later, the inclination angle will be higher since the motor
is spinning; let’s say, for example, θ = 10°. This will
consequently give an e = 35° which will command the
motor to keep spinning, but not as fast since it is getting
closer to the set point. Eventually, the measured θ will be
equal or close to 45°. At that point, the error will be zero
meaning we achieved the goal.
The way the PID block processes the error signal to
command the motor is described in Equation 2. The
controller takes the error signal and produces the motor's
control effort u:
u =K p ×e(t ) +Ki × ∫e(t )dt +Kd × d dte(t )
In the previous example, the error signal started at a
value of 45°. One cannot give a 45° command to a motor
since the motor only takes 0-12 volt commands. Therefore,
the first thing the PID equation does is to change the units
of the error signal to coherent motor command units. The
PID equation has three controllers or terms: the proportional, the integral, and the derivative. Kp, Ki, and Kd are the
proportional, integral, and derivative gains, respectively. Kp
is a factor which multiplies the raw error signal in order to
54 SERVO 02.2009
■ FIGURE 3. DC motors and the
velocity control circuitry.
scale and change its units. Ki multiplies the integral — or
build-up — of the error signal to perform the same task as
Kp. Finally, Kd scales and conditions the units of the
derivative — or rate of change — of the error signal by
multiplying it. All three terms are added together before
sending out the control effort signal to command the
motor. As a side note, all gains should always remain
positive to avoid instability issues.
Software Architecture
The code for the project was written in C using Texas
Instruments Code Composer Studio 3.1. Figure 6 shows
the flow diagram of the code running on the DSP.
The main function runs only once and initializes the
devices connected to the DSP board, its internal registers,
and its memory. The runAeroPendubotController() function
runs the control algorithm and it is called every 1 ms.
The first step in the algorithm is to read the desired
and current angles from the encoders. We used a
customized library developed in our Control Systems Lab to
access these devices. The next step in the algorithm is to
calculate the error signal between encoders. This quantity is
immediately passed to the acPidController() function. The
resultant control effort — returned by the PID function — is
then added to a bias value. The bias value is intended to
provide an initial command to the motor to overcome
friction. The friction compensation bias, as well as the Kp,
Ki, and Kd, are determined experimentally. The final step in
the algorithm is to send the modified control effort to the
motor using acCtrlEffortMotor1(). This function produces
the necessary PWM signal to command the motor.
Implementing The Controller's Code
As described earlier, the PID controller consists of
three terms. It is implemented in the function u = acPid
Controller(e,θ,Kp,Ki,Kd,T) which takes the error signal, the
current inclination measurement, the controller gains, and
the sampling period T. As we'll see later, the sampling period is essential to integrate and take the derivative of the