Lab Manual For EE380 (Control Lab) : Department of Electrical Engineering, IIT Kanpur
Lab Manual For EE380 (Control Lab) : Department of Electrical Engineering, IIT Kanpur
Lab Manual For EE380 (Control Lab) : Department of Electrical Engineering, IIT Kanpur
ii
Contents
Preface vii
0.1 Skills the control experiments need to impart . . . . . . . . . . . vii
0.2 Past status of Control Systems Laboratory . . . . . . . . . . . . . viii
0.2.1 Logistical challenges . . . . . . . . . . . . . . . . . . . . . viii
0.2.2 Solution to these challenges . . . . . . . . . . . . . . . . . viii
0.3 Planning for the future . . . . . . . . . . . . . . . . . . . . . . . . viii
0.3.1 Models for the experiments . . . . . . . . . . . . . . . . . viii
0.3.2 Suggested new set of experiments . . . . . . . . . . . . . ix
iii
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
2.2.2 To do in lab . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.3 Physics-based model of the DC motor unit . . . . . . . . . . . . 21
2.4 System identification . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.5 Discretized version of the controller . . . . . . . . . . . . . . . . 22
2.5.1 Conversion from transfer function to state-space . . . . . 23
2.5.2 Discretization of the state-space equation . . . . . . . . . 24
2.5.3 Time-domain recursion . . . . . . . . . . . . . . . . . . . 24
2.6 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.7 Program listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.7.1 easysim.m . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
iv
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Software used 79
v
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
vi
Preface
EE380 is a four credit hour laboratory course. Control systems constitutes one-
third of this course. Given that we currently have only one control systems
course active at the UG level at IITK, and that the one-third of EE380 is the
only exposure the students have to a control systems laboratory at IITK, what
do we want the students to learn from this brief exposure to the controls lab?
1. Ability to identify the hardware and software that are needed in a basic
control system.
3. Ability to debug small errors that may appear during practical implementa-
tion.
This knowledge comes only through at least a few weeks of work on problems,
all of which may be related to one or two hardware setups that are not and
do not look complex.
Overall, the lab experiments need to give the student confidence enough to say,
I have practical experience with implementing control systems in addition to
designing and simulating them.
vii
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
1. Six different experiments were done concurrently during each lab session
with support from two TAs per session. Therefore, each TA and tutor
needed to know all the 6 experiments every week, thus putting pressure
on them.
Thus, in any given week, the TAs expended more effort than if they were all
preparing for the same experiment.
2. Also, with increased student intake (with up to 30 students per section),
under that model, we would have had cacophony in the lab with everyone
speaking about a different experiment.
3. With increased student intake, multiplying the then existing set of exper-
iments would have been expensive. It would have been expensive to in-
crease the number of inverted pendulums, or the number of ball and beam
setups, or even the number of DAQ cards from NI. An inverted pendulum
or a ball-beam setup comes for about Rupees Five Lakh each.
The solution is for all the students, TAs, and tutors to do the same experiment in
a given week. This model exists in the ESO210 labs, for example. It has the
following advantages:
1. We will need only 2 3 TAs per section.
2. The students, TAs, and tutors will generate more knowledge than if they
were all working on different experiments.
3. It will be easier for the entire class as everybody is talking about the same
thing in a given week.
viii
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
and inputs the values of the controllers parameters into a convenient in-
terface provided on the control system. The control system itself has been
built by someone else and is almost a black box to the student.
Pro: This way, the student becomes acquainted with the various control ex-
perimental setups that are available in the market, and the real-life system
each of these setups models. But, the student could have learned this from
www.youtube.com too.
Pro: The students may learn that a control system works differently in prac-
tice than on paper.
Pro: This kind of an experiment impresses upon the student the wide appli-
cability of control systems theory.
Con: The student does not see the hardware innards of the control system,
nor does he/she talk to anybody that has actually built this setup and could
share his/her experience building it.
Model 2 The student works with only one or two experimental setups through
the semester.
Pro: The student solves many different problems associated with each setup.
This way, the student can learn how a practical control system is actually
built after the paper-/PC- based design and simulation.
The pros in Model 1 are not significant enough for the student to spend a
semester in the EE380 labs. On the other hand, the pro of Model 2 is. We
recommend Model 2 as it is in consonance with Sections 0.1 and 0.2.2.
1 http://www.quanser.com/english/downloads/products/Mechatronics/
QET%20PIS_031708.pdf
ix
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
x
Contributions to the lab
Late 2008 Dr. Ramprasad Potluri conceptualized the lab as outlined in the
Preface.
Early 2009 Mr. Manavaalan Gunasekaran suggested development of the
dsPIC boards for a 4WD4WS vehicle that we plan to build in the Networked
Control Systems Laboratory.
June July 2009 Ms. R. Sirisha and Mr. Yash Pant, 4th year BTech students,
College of Engineering, Roorkee, designed, built, tested, and documented
the first prototype of the dsPIC board.
Mid-June 2009 Dr. Potluri was asked to teach CS-EE380-Fall2009.
July 2009 Mr. Manavaalan Gunasekaran improved the boards and imple-
mented the first four experiments.
Fall 2009 The dsPIC boards were put to use in CS-EE380-Fall2009.
Dr. Adrish Banerjee gave valuable feedback and encouragement from his
stint as a tutor for this lab.
Funds were announced by IITKs capacity expansion program (CEP) (2009)
to set up the pmdc motor control-based experiments in a new control sys-
tems laboratory.
Summer 2010 Mr. Mohit Gupta, a 4th year BTech student of Manipal Institute
of Technology, helped multiply the dsPIC board. He also helped make a few
ergonomic improvements.
Summer 2009 & summer 2010 The dsPIC boards were fabricated in the PCB
Lab of the EE department under Mr. Koles supervision. Mr. Kole suggested
several ergonomic improvements.
Summer 2010 Mr. Uday Mazumdar, in-charge of the Control Systems Lab had
the mechanical part of the setup built and assembled. He also supervised
setting the lab up in the new room (WL216).
Mr. Sripal of the Basic Electronics Lab populated 21 of the dsPIC boards.
Mr. Harishankar populated the H-bridge boards.
At every stage beginning the CEP, the lab received support from the then
Head of the department, Prof. Ajit Kumar Chaturvedi.
xi
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
xii
Chapter 1
1.1 Introduction
Vs
DB i
pmdc motor
Other components
PWM
H-bridge
board
PC GPIO
PICkit 2
USB
ADC
UART QEI
103 F
Encoder
isens
UART Rs
Figure 1.1: Block diagram of the setup. DB stands for dsPIC board.
1
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
We use Timer-1, one of the five timers of the timer module, to generate an
interrupt at each sampling instant. When the interrupt occurs, dsPIC exe-
cutes the Timer-1s interrupt service routine (ISR). We have written this ISR in
main-prog.c to perform the tasks shown in Figure 1.4 and further elaborated
in the timing diagram of Figure 1.5.
We have set the internal clock frequency FCY to one fourth the oscillator
frequency FOSC , that is, (FCY = FOSC /4). In practice, FCY FOSC /4 in
dsPIC30F4012. We use this FCY in the timer module. For a sampling time Ts in
seconds, the value PR1 in the period register is calculated as follows:
Ts F Ts
PR1 = = FCY Ts = OSC
TCY 4
The PWM module is used to generate a PWM signal with duty ratio computed
from the controller output. We have used PW M1L to drive the H-bridge cir-
cuit. If the controller output is u then the duty ratio is D = u/Vs , where Vs is
the power supply voltage to the motor driver in volts. To generate a PWM with
a frequency FPW M in Hz and duty ratio D, the settings of the PWM module are
It is used to interface the motor speed encoder to calculate the speed. Figure 1.2
explains the working of the quadrature encoder. The signals of the QEI are
2
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Figure 1.2: How the quadrature encoder works. The encoder comprises three
parts: an opaque disc with slots of equal width cut at equals intervals along its
circumference, two sources of light on one side of the disc, and two receivers of
light on the other side of the disc. The sources and receivers are mapped one-to-
one. The signals from the receivers are labeled A and B. Assume that light being
blocked by the disc represents a logical 0, and light being passed by the disc rep-
resents a logical 1. B leads A when the disc rotates clock wise and A leads B when
the disc rotates anti-clockwise.
shown in Figure 1.3. The QEI is configured in x2 mode (QEICON < 10 : 8 > =
101). In this mode both edges rising and falling of the phase-A signal
cause the position counter to change value (increment or decrement). The
phase-B signal is utilized for the determination of the position counters di-
rection (increment or decrement).
The value of the count, which for each period Ts is twice the number of
pulses from the encoder, is accessible through a register POSCNT.
If the encoder has a resolution of CT counts per turn, then the speed in
rad/sec is given by
2 POSCNT
=
Ts 2CT
This is used to communicate with Personal Computer (PC). We use this to send
the data of speed and controller output (which is the voltage we wish the H-
bridge to apply to the motor) to the PC for plotting. UART is configured with
one stop bit and the register U1BRG is used to set the baud rate. Let BR be the
baud rate then the register value is given by
FCY
U1BRG = 1
16BR
In our program, the baud rate is 115200. This is the maximum possible baud
rate for our dsPIC board with 29.492 MHz oscillator and its corresponding
value for the U1BRG register is 0x0003.
3
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Figure 1.3: Signals of the QEI. Figure copied from Maxon Motor.
The GPIO pin D0 is used as a digital output to change the polarity of the volt-
age output by the H-bridge (to change the direction of the rotation of the mo-
tor). The data direction register (TRISx) determines whether the pin is an input
(1) or an output (0). Reading or writing the latch is done by using LATx.
See the section titled pwm_control function in the file setting-prog.h for
further details.
In our case, TRISD = 0 (Port D is configured as output port).
Pins AN(0-2) are configured as analog inputs by using register ADPCFG. Auto
conversion mode is used (SSRC(2:0) = 111). The analog input to be converted
is selected using ADCHS register (CH0SA(3:0) bits e.g. 000 for AN0, 001 for
AN1). In settings program AN0 is alone selected for conversion.
As our microcontroller does not have enough on-chip memory to hold the data
we generate during each control run of the setup, we communicate to the PC
the data as and when it is generated, which means within each sampling in-
terval. In the experiments we do in EE380, this data is that of position, speed,
armature voltage, and current.
If we wish to communicate only two of these variables to the PC, then it seems
that Ts = 0.002 s may be adquate. In our earlier trials, when we tried to com-
municate three variables to the PC, we found that, while a sampling interval of
4
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Timer interrupt NO
occurred?
YES
Reset the timer interrupt enable flag (IFSobits.T1IF=0)
Timer interrupt
0 Ts 2Ts
UART Communication
Controller update
PWM
Figure 1.5: Timing diagram for the tasks that the ISR implements.
0.002 s was not adequate, even a sampling interval of 0.003 s, which seems to
be a reasonable choice, was inadequate occassionally. Here, by inadequate we
mean that the log file created by terminal.exe contained non-numeric data
where it should have contained numeric data. We hypothesize that this inade-
quacy may be due to the non-realtime nature of how MS Windows may handle
UART communication given that we have not made a provision for handshak-
ing signals (see Subsection 1.7.2). However, this hypothesis needs testing.
5
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
?
u ua 1 Vr
VS PWM H-bridge Motor
Figure 1.6: Diagram of the plant for which the controller is designed, used in all
the experiments except the experiment on Ziegler-Nichols tuning. The part en-
closed in the dashed box and labeled ? is inside the dsPIC microcontroller, u a is
the numerical value of voltage applied to motors armature, VS is the source volt-
age applied to the H-bridge board, and is the duty ratio. The dsPIC outputs
a PWM signal of duty ratio to the H-bridge board. The H-bridge outputs a
variable-magnitude DC voltage Vr to the motor. The saturation block implements
the operation 0.8VS u a 0.8VS .
10 0.4
Vm
Vsens
Sensed current in A
5 0.3
Vm and Vsens in V
0 0.2
-5 0.1
-10 0
-10 -5 0 5 10 0 0.05 0.1 0.15
u in V Motor current in A
Figure 1.7: Left-fig: The blue curve is the voltage Vm (same as Vr in Figure 1.6)
output by the H-bridge versus the input voltage u specified by the microcontroller;
the black curve is the voltage across the sensing resistor (Rs = 5 ) versus u. The
supply voltage is 12 V. Right-fig: The current isens through the sensing resistor
versus actual motor current i.
6
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Nominal voltage 24 V
No load speed 8820 rpm
No load current 31.7 mA
Nominal speed 6730 rpm
Nominal torque 17.2 mN m
Nominal current 0.704 A
Stall torque 77.6 mN m
Starting current 3.04 A
Max. efficiency 79 %
Terminal resistance 7.9
Terminal inductance 0.770 mH
Torque constant 25.5 mN m/A
Speed constant 374 rpm/V
Rotor inertia 13.0 g cm2
Gear mass inertia 0.4 g cm2
Gear ratio 62:1
Encoder: Counts per turn 500
Using isens and the drop VH in the H-bridge, we found that the H-bridge has
a resistance R H of about 27.5 ohm. VH and R H were determined as VH =
u Vm Vsens and R H = VH /isens . Vm and Vsens were measured using a digital
multimeter. Isens was found as isens = Vsens /Rs .
The response of the motor to a step u of magnitude 5 V has a steady-state value
o = 150 rad/sec. This response is divided by 5 and plotted in Figure 1.8.
Also plotted in the same figure is the unit step response of the physics-based
TF Km /(m s + 1) of the same motor. This TF was obtained as described in
Section 2.3. The values of the parameters in this TF are directly or indirectly
determined from Table 1.1 and converted into SI units. While KT and J can be
read off the table, and Kb the back EMF constant is the reciprocal of the
speed constant, B and R need a little thought.
Even though we included the H-bridge as a resistor, as described in Section 1.6,
there is a mismatch in Km by 3 units and time constant by 0.01 s. This mismatch
needs investigation.
B is the viscous friction torque in the bearings of the motor, and B is the co-
efficient of viscous friction in the bearings. The literature says that the viscous
7
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Step Response
35
30
Simulation
25
Practical
Speed in rad/sec
20
15
10
0
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
Time in sec (sec)
friction (as opposed to rolling friction, Coulomb friction, etc) is the dominant
component of bearing friction.
When no load is applied to the motor shaft (TL = 0) and the speed is steady
( d
dt = 0), the developed torque Kt i needs to be enough to equal only B.
In the same experiment that helped generate the practical curve of Figure 1.8,
the no-load motor armature current was found to be Imo = 0.0173. Also, we
saw that o = 150 rad/sec. From the data sheet Kt = 25.5 mNm/A. Therefore,
B = Kt Imo /o = 2.9374 106 Nm/(rad/s).
The actual resistance in the motor armature circuit is R = Rm + Rs + R H . The
motor terminal resistance Rm equals 7.9 . Thus, R = 7.9 + 5 + 27.5 = 40.4 .
1.7 Programming
8
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
1.8.1 main-prog.c
// main-prog.c.
#include<p30f4012.h>
#include "settings-prog.h"
_FOSC(CSW_FSCM_OFF & XT); // To use the external crystal
_FWDT(WDT_OFF); // To disable the watchdog timer
9
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
//
// Declare your variables here
//
void main()
{
// Initialise your variables here
// You need to use your own values of ac, bc, cc, dc below
ac = 1-0.2*T; bc = T; cc = 0.29898; dc = 0.0151;
R = 100; Ra = 28.7; Kb = 0.0255;
// I[0] = 0; I[1] = 0; IF[0] = 0; IF[1] = 0;
Is = 0; IF = 0; Ihat = 0;
LATEbits.LATE8 = 1;
uart_tx(9);
10
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
// send_data(West);
// West = (u-Ra*IF)/Kb;
// West = (u-Ra*Ihat)/Kb;
11
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
// Ihat = (2.6)*IF;
// Is = IV/4.7; // Convert voltage to current.
// IF = (1-5.0*T)*IF + 5.0*T*Is; // Low-pass filter.
// error = R - West;
// u = cc*x + dc*error;
// x = ac*x + bc*error;
// u = 5.0*AD_value()/511;
duty = u/V_s;
pwm_con(duty); // Update PWM using new duty ratio
uart_tx(9);
send_data(u*100); // Send 100 times control effort u.
LATEbits.LATE8=0;
} // End of ISR of Timer 1
12
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
int AD_value()
{
int count, *ADC16Ptr, ADCValue = 0; // clear value
ADC16Ptr = &ADCBUF0; // Initialize ADCBUF pointer
ADCON1bits.ADON = 1; // Turn ADC ON
IFS0bits.ADIF = 0; // Clear ADC interrupt flag
ADCON1bits.ASAM = 1; // Auto start sampling
1.8.2 settings-prog.h
/*------------UART settings:---------------
Fcy = Fosc/4 = 29492000/4 = 7373000Hz
U1BRG = {Fcy/(16 * Baud_Rate) } - 1
conf: 1 stop bit, 8 data bit, no parity
------------------------------------------*/
#include<p30f4012.h>
13
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
14
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
PTPER = 7373/F_pwm - 1;// PWM Time Base Period Register (Period of PWM)
// Note: PTPER = {Fcy/(Fpwm*PTMER_prescaler) - 1 }
// Fcy =Fosc/4 = 7373000
PWMCON1 = 0x0011; // PWM I/O pin pair is in complementary output mode
// PWM1L & PWM1H enabled; remaining are in I/O mode
PDC1 = 0; // Initially duty ratio is zero;
OVDCON = 0x0303; // Controlled by PWM module
PTMR = 0x0000; // PWM Time Base Register initialized
}
15
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
1.8.3 readplot.m
16
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
%
% We found that this problem has been reported at
%
% http://octave.1599824.n4.nabble.com/
% Gnuplot-freezes-in-Win7-3-2-4-td2279218.html#a2279218
%
% and a work-around has been suggested there and at
%
% http://old.nabble.com/
% Re:-Octave-3.2.4-mingw32-available-p28053703.html
%
% Using this work-around does remove this problem.
%
% PRECONDITIONS: readplot.m and testdata.txt need to be in the
% same folder. All data in testdata.txt is tab-separated and in a
% single row, and no spaces lead the first item of the data.
%
% Date created on: September 12, 2010.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x = dlmread(terminal.log);
17
1 2 3 4
+12V CN1-PS JP1 JP 4
+12V VR L7805CV VCC
1 RB0-I 1 RE2-I 1
1 2 CN3-MOTOR
2 IN OUT RB0 2 RE2 2
3 GND B0-O 3 E2-O 3 PWM1L-O 1 2 PWM1H-O
C2 SD1 3 4 SD2
-12V JP2 JP 5
3
C1 QEA 5 6 QEB
.22uF
.1uF RB1-I 1 RE3-I 1 QEI 7 8 VCC
U1-MAX706PCPA
RB1 2 RE3 2 9 10
6 2
A WDI VCC VCC B1-O 3 E3-O 3 A
1 8 D1 MCLR U2 dsPIC30F4012-30I/SP JP3 JP 6
MR WDO
4 7 1 2 RE4-I 1 CN5-O/P
PFI RST MCLR EMUD3/AN0/VREF+/CN2/RB0 RB0 RB2-I 1
S1 3 RE4 2
EMUC3/AN1/VREF-/CN3/RB1 RB1 RB2 2 RB0-O 1 2 RB1-O
PB 3 5 1N4148 9 4 E4-O 3
GND PFO OSC1 OSC1/CLKI AN2/SS1/CN4/RB2 RB2 B2-O 3 RB2-O 3 4 RE2-O
5
AN3/INDX/CN5/RB3 QEI-I RE3-O 5 6 RE4-O
1.9
13 6 JP 7
VDD AN4/QEA/IC7/CN6/RB4 QEA-I RE5-O 7 8 RE8-O
20 7 MCLR CN2-PICKIT2
VCC VDD AN5/QEB/IC8/CN7/RB5 QEB-I RE5-I 1 9 10
27pF 28
AVDD 1 RE5 2
C4 11
EMUD1/SOSCI/T2CK/U1ATX/CN1/RC13 U1ATX 2 E5-O 3
8 12
OSC1 VSS EMUC1/SOSCO/T1CK/U1ARX/CN0/RC14 U1ARX 3
19 10 JP 8 CN4-I/P
1
Cap VSS OSC2/CLKO/RC15 OSC2 C1TX 4
27
AVSS C1RX 5 RE8-I 1 RB0-I 1 2 RB1-I
29.492 MHz Y1 15
EMUC2/OC1/IC1/INT1/RD0 RD0 6 RE8 2 RB2-I 3 4 RE2-I
C3 14
2
EMUD2/OC2/IC2/INT2/RD1 RD1 E8-O 3 RE3-I 5 6 RE4-I
OSC2 RE5-I 7 8 RE8-I
26
Cap PWM1L/RE0 PWM1L CAN1 9 10
25 C1TX U3 MCP2551-I/P
27pF PWM1H/RE1 PWM1H R2
24 1 7 R4
September 10, 2013
4
4
4
4
U4A U4B U4D U4C
2 LF347BN 6 LF347BN 13 LF347BN 9 LF347BN DB9
PWM1L 1 PWM1H 7 RDO 14 RD1 8 DB9-UART-A
1 2 4 3
R5 3 R6 5 R7 12 R8 10 1
10K PWM1L-O PWM1H-O 10K SD1 10K SD2 1uF 6
18
10K C5 VCC U8-MAX233A 2 11
11
11
11
11
JP9-U1TX 7 14 7
-12V VCC V+
3 10
C1TX 1
2 T1
5 8
U1TX 2 U1ATX U1A-PC-RX
4
+12V
C 1 18 9 C
4
4
4
4
U1TX T2 U1-PC-RX
U5A U5B U5C U5D 5
2 LF347BN 6 LF347BN 9 LF347BN 13 LF347BN JP10-U1RX 3 4
U1ARX R1 U1A-PC-TX
QEA 1 QEB 7 QEI 8 14
1 R10 2 R11 3 4 C1RX 1
R9 3 5 10 R12 12 20 19
EE380 (Control Lab) IITK
11
11
11
11
13 15
-12V C1- C2+
10 CN6-UART
C2-
16
+12V C2- U1-PC-TX 1
6 12
4
4
4
4
U6A U6B U6C GND V- U1-PC-RX 2
U6D 9 17
LF347BN LF347BN LF347BN GND V- 3
2 6 9 13 LF347BN
B0-O 1 B1-O 7 B2-O 8 E2-O 14 MAX233ACPP Header 3
1 2 3 4
Schematic of the dsPIC30F4012 board
11
11
11
11
-12V
+12V
4
4
4
4
11
11
11
11
Lab Manual
-12V
Date: 7/27/2010 Sheet of
File: C:\Documents and Settings\..\PIC-board.SchDoc
Drawn By:
1 2 3 4
Chapter 2
2.1 Goals
1. Develop a physics-based model for a PMDC motor.
2. For the PMDC motor develop a model based on system identification using
open-loop (OL) step response.
3. Design a speed controller for the physics-based model using Bode plot-
based loop-shaping techniques. Simulate this controller.
4. Redesign the speed controller for the identified model, simulate this con-
troller, and implement it practically. Compare results.
The block diagram of the control system is shown in Figure 1.1.
Section 2.2 lists the steps that help achieve the above-stated goals. Sections 2.3
onwards fill in the technical background needed to execute these steps.
2.2 Exercises
2.2.1 To do at home
Q1 Verify equations (2.2) and (2.3) using Figure 2.2, and determine the numer-
ical values using Table 1.1.
ref + u (s)
Controller Plant
19
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
2.2.2 To do in lab
Q7 Write a code to apply a step voltage to the motor. Run the motor in OL.
Q8 Identify the values of Km and m using the OL step response. See Sec-
tion 2.4.
Q9 For the identified model, redesign your controller using loop-shaping on
the graph paper you used in your homework.
Q10 With the discretized version of the above-redesigned controller, perform a
simulation of digital control of the continuous-time identified plant using the
m-file easysim.m.
Plot your results as two subplots with versus t in the upper subplot and
u versus t in the lower subplot, and show this plot to the instructor.
Q11 Program the lab-designed digital controller and run the setup.
20
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
TL (s)
V (s) + 1 I (s) T (s) + 1 (s)
Kt
sL a + R Js + B
Kb
Figure 2.2: Block diagram of a PMDC motor. R includes the armature resistance
R a and other resistances as explained in Section 1.6.
Plot your results as two subplots with versus t in the upper subplot and
u versus t in the lower subplot, and show this plot to the instructor.
Q12 Compare the performance of the controller designed for the identified
model in simulation and in experiment. Fill the following table:
Simulation
Experiment
Since the inductance L a is very small1 , by neglecting L a , from Figure 2.2, the
transfer function (TF) from the input voltage V (t) to the speed (t) of the mo-
tor shaft is
(s) Km
= (2.1)
V (s) m s + 1
with
KT
Km = , (2.2)
R B + K T Kb
R J
m = (2.3)
R B + K T Kb
Here, Km is the motor gain constant in rad/s/V, m is the motor time constant
in seconds, KT is the torque constant in N m/A, R is the resistance in the
armature path in ohms as explained in Section 1.6, B is the viscous-friction co-
efficient of the motor rotor with attached mechanical load in N m/(rad/sec),
1 When is an inductor considered small? When the time constant due to this inductor is neg-
ligible in comparison to the remaining time constants in the TF of the system, this inductor is
considered neglibly small. It can be verified using the data provided in and near Table 1.1 that for
this setup, J/B L a /R
21
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
J is the moment of inertia of the motor rotor with attached mechanical load
kg m2 , Kb is the back emf constant in V/(rad/sec).
22
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
2. Let
X (s) 1 Y (s)
= 2 and = a1 s + a0
U (s) s + b1 s + b0 X (s)
4. Using this last step, we can construct the following simulation diagram:
a1
+
U (s) s2 X ( s ) 1 sX (s) 1 X (s) Y (s)
s s
a0
+ +
b1
b0
Note that here, the block containing the 1/s represents integration opera-
tion. Books show either of the following two equivalent blocks:
1
R
s =
R
Strictly speaking, the 1/s is used s-domain block diagrams, while the is
used in time-domain block diagrams.
5. In the block diagram, write the time-domain quantities u(t) and y(t) as
shown below, and assign a state variable to the output of each integrator.
a1
+
U (s) s2 X ( s ) 1 sX (s) 1 X (s) Y (s)
s s
a0
u(t) + x2 x2 = x1 x1 + y(t)
b1
b0
23
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
x1 = x2
x2 = b0 x1 b1 x2 + u
y = a0 x1 + a1 x2
For example, Equation (2.5), on discretization, has the following form that is
ready for recursion:
x1 (k + 1) = x1 (k) + Ts x2 (k)
x2 (k + 1) = b0 Ts x1 (k) + (1 b1 Ts ) x2 (k ) + Ts u(k)
2.6 Simulation
The discrete-time controller will work in practice on a continuous-time plant.
However, the continuous-time plant is not available at home. Therefore, we
24
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
START
Simulation of
Update
TIME = kTs for continuous-
control
Y some integer k? time plant
u(t) = uk
dynamics
Run N
STOP complete?
Y
instead test the digital control of the continuous-time plant in simulation. The
simulation scheme is shown in Figure 2.3 and is implemented in the m-file
easysim.m. which runs on MATLAB and GNU Octave.
2.7.1 easysim.m
25
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
% Controller TF is Cs = (Kp*s+Ki)/s
Kp = 0.11; Ki = 1.737;
% State-space model of controller is
%
% xcdot = uc;
% yc = Ki*xc + Kp*uc;
%
% The suffix c represents controller.
%-------------------------------------------------------------
%-- Simulate continuous-time plant discrete-time controller --
t = (0:tcfin/Tc)*Tc;
plot(t,sa); grid(gca,minor);
print -depsc Tc0-0001.eps
26
Chapter 3
Experiment 2: Speed of
PMDC motor tracks reference
sinusoid
3.1 Goals
3.2 Questions
3.2.1 To do at home
27
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
To see the effect of the deadzone, plot the contents of each of the .log files
using readplot.m, and sketch your results below.
vs. t and u vs. t from vs. t and u vs. t from vs. t and u vs. t from
tri4fg5.log tri8fg5.log rect4fg5.log
Then, use the attached file readSID.m that is an amalgam of readplot.m and
sysid.m to populate the following table.
28
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Figure 3.1: Block diagram of the experimental setup as applicable to the task of
least squares estimation. The signal u is generated either by a program or is the
output of the ADC. The motor unit comprises the PMDC motor with gear.
Figure 3.2: how the output of the FG is converted into a u of desired value.
TF from triangle of
4 V amplitude
TF from triangle of
8 V amplitude
TF from rectangle
of 4 V amplitude
3.2.2 To do in lab
29
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
spective of the waveform used. Figure 3.2 shows how this configuration helps
obtain the desired u.
Run the plant in open-loop mode. Record the input-output data (that is,
u, ) into a file named expt2-q9.log. Our FG outputs by default a wave-
form of about 4 V peak-to-peak value, though the display of the FG says 5
V. You will use the data in expt2-q9.log to identify the plant parameters.
Q10 Identify the plant parameters using least squares estimation.
In the line [y3,t3] = step(tf(31.42/0.07,[1,1/0.07])); of readSID.m,
use the plant parameters that you obtained in Q8 of Experiment 1. Then use
readSID.m to populate the following table, and note which step response is
closest to the step response of the TF from Q8 of Experiment 1.
TF from triangle
without filter in
readSID.m
TF from trian-
gle with filter in
readSID.m
Q11 Approximately fit a first order TF to the unit step response of the TF corre-
sponding to the triangle (8 V ampl, with filter in readSID.m) in Q10, similar
to how you did in Q8 of Experiment 1.
Q12 With the first order TF in Q11, redesign your controller using loop-
shaping for the motor to track sinusoids upto 7 Hz with ess 10%. Hint:
You do not need a semilog graph paper here.
Q12a With the discretized version of the controller from Q11, perform a simu-
lation of digital control of the continuous-time plant as you did in Q5.
Q13 Program the discretized version of the controller from Q10 into the dsPIC,
run the setup, if necessary, very slightly adjust the offset knob of the FG so
that there is no net creep of the pulley in any one direction, and populate the
following table.
In main-prog.c, you will need to comment out the part u =
30
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
The dead zone in the Vm versus u characteristic of Figure 1.7 does not matter
when we control the PMDC motor for its speed to track a step as the speed
is needed to be at a large value and u quickly becomes large enough, without
dwelling in the dead zone.
In the position control of the PMDC motor (Chapter 9), however, u becomes
small when the desired position is reached. If u becomes smaller than 2 volts,
then Vm will be zero as shown in Figure 1.7, making the position control system
unresponsive.
Similar to the case of position control, when the speed wishes to track a sinu-
soid, the reference speed, and therefore u, dips to near-zero values before grad-
ually going to larger values. In this case, the dead zone can be experienced by
using small input voltages, for example, u = 3 sin t.
To help the motor to remain responsive when the applied armature voltage
reaches near zero values, we could either
1. use an integral component in the controller, or
2. add the following code in main-prog.c before or after the if condition used
for limiting the duty ratio.
if(u<0&&u>-2) u = u - 2; else if(u>0&&u<2) u = u + 2;
Dead zone compensation is addressed in another experiment (Chapter 5).
The plant TF (Equation 2.1) has two parameters, Km and m , that need to be
identified. We use from [4, pages 503505] a technique to obtain the best esti-
mate of the parameters of a transfer function (TF) in the least squares sense.
31
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
The m-file sysid.m contains sample code for system identification. In sysid.m
the input u(k) is applied to an example plant; the output y(k) is assumed to
contain noise. Identification using these input and output values results in
values of the system parameters that are very close to those of the plant.
3.5.1 sysid.m
32
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
% Initialize
yp(1) = 0; % Initial actual speed.
x1p(1) = 0; x2p(1) = 0; % Initial state of the plant.
% Recursion
for i = 1:tcfin/Tc
x1p(i+1) = x1p(i) + x2p(i)*Tc;
x2p(i+1) = -b*Tc*x1p(i) + (1-a*Tc)*x2p(i) + Tc*uc(i);
33
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
yp(i) = K*x1p(i);
end
% Plot
plot(t,uc,t,yp); grid; legend(Control input,Actual speed);
print -depsc sysid.eps
y = yp; u = uc;
k = 3;
for n =1:Ct-3
Y(n,1) = (2/Tc)^2 * (y(k) - 2*y(k-1) + y(k-2));
P(n,:) = [( u(k) + 2*u(k-1) + u(k-2)) ...
(-2/Tc*( y(k)-y(k-2) ) ) -( y(k)+2*y(k-1)+y(k-2) )];
k = k+1;
end
X = (P * P)^(-1) * P * Y % X = [K a b]
3.5.2 simsine.m
34
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
% Controller TF is
%
% (s/z + 1)
% Kc * ---------
% (s/p + 1)
%---------------------------------------------------------------
% Simulate continuous-time plant discrete-time controller
%---------------------------------------------------------------
% Initial conditions
sa(1) = 0; % Initial actual speed (sa = yp).
xc(1) = 0; % Initial state of controller.
yc(1) = 0; % Intial output of controller.
xp(1) = 0; % Initial state of plant.
% Recursion
35
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
for k = 1:tsfin/Ts
uc(k) = sd(k) - sa(k);
xc(k+1) = (1+ac*Ts)*xc(k) + bc*Ts*uc(k);
yc(k) = cc*xc(k) + dc*uc(k);
% Hold last sample of controller output
up = yc(k);
% Numerically integrate plant equation holding
% the input as last controller output:
for i = 1:Ts/Tp-1
xp = (1+Tp*ap)*xp + Tp*bp*up;
yp = cp*xp + dp*up;
end
sa(k+1) = yp;
end
t = (0:tsfin/Ts)*Ts;
subplot(2,1,1); plot(t,sd, t,sa); grid(gca,minor);
legend(reference,speed);
subplot(2,1,2); plot(t(:,1:size(yc,2)),yc); grid(gca,minor);
legend(controller output);
print -depsc Ts0-0001.eps
3.5.3 readSID.m
x = dlmread(terminal.txt);
36
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
y = w; u = u;
k = 3;
for n =1:cols/2-3
Y(n,1) = (2/Tp)^2 * (y(k) - 2*y(k-1) + y(k-2));
P(n,:) = [( u(k) + 2*u(k-1) + u(k-2)) ...
(-2/Tp*( y(k)-y(k-2) ) ) -( y(k)+2*y(k-1)+y(k-2) )];
k = k+1;
end
X = (P * P)^(-1) * P * Y; % X = [K a b]
[y1,t1] = step(tf(X(1,:),[1,X(2,:),X(3,:)]));
om = 25; x(1) = 0;
for k = 1:cols/2
x(k+1) = (1-om*Tp)*x(k) + om*Tp*w(k);
end
w = x(1:cols/2); % Filtered w.
y = w; u = u;
k = 3;
for n =1:cols/2-3
Y(n,1) = (2/Tp)^2 * (y(k) - 2*y(k-1) + y(k-2));
P(n,:) = [( u(k) + 2*u(k-1) + u(k-2)) ...
(-2/Tp*( y(k)-y(k-2) ) ) -( y(k)+2*y(k-1)+y(k-2) )];
k = k+1;
37
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
end
X = (P * P)^(-1) * P * Y; % X = [K a b]
[y2,t2] = step(tf(X(1,:),[1,X(2,:),X(3,:)]));
[y3,t3] = step(tf(31.42/0.07,[1,1/0.07]));
plot(t1,y1,r,t2,y2,t3,y3,g); grid(gca,minor);
38
Chapter 4
Experiment 3: Ziegler-Nichols
tuning of speed controller of
PMDC motor
4.1 Goals
39
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
r + y
1 T s u
kp 1 + + D Plant
TI s s + 1
Figure 4.1: The CL system. The ZNT methods help tune k p , TI , TD . The time con-
stant has two purposes. Firstly, it makes implementing the derivative controller
possible. Secondly, it helps create a low pass filter for high frequency noise. is
selected to be between 0.1TD and 0.2TD [9, page 161].
40
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Point of inflexion
0 t
L T
Figure 4.2: Unit step response of the plant is needed for the first ZNT method. This
response is also known as the reaction curve of the plant. As the first ZNT method
uses these curves, the first method is also known as reaction curve method. See [9,
page 167] for another way of obtaining the reaction curve.
Table 4.1: ZNT rules for the First ZNT method [5, 7].
Controller kp TI TD
T
P 0
LK
0.9T L
PI 0
LK 0.3
1.2T
PID 2L 0.5L
LK
Step 1: Obtain the unit step response of the plant in open loop (OL); see Fig-
ure 4.2.
Step 2: Determine T and L as shown, by drawing a tangent as shown to the
step response through the point of inflexion. Alternatively draw a tangent
to this curve of maximum slope.
Step 3: The approximate transfer function (TF) of the OL plant is
(s) Ke Ls
=
U (s) Ts + 1
41
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Table 4.2: ZNT rules for the Second ZNT method [5, 7].
Controller kp TI TD
P 0.5k cr 0
PI 0.45k cr (1/1.2) Pcr 0
PID 0.6k cr 0.5Pcr 0.125Pcr
Step 2: Apply a step input to the CL system and observe its response.
Step 3: With the step input on, increase the value of k p from 0 to some value
k cr (called the critical gain or ultimate gain) at which the CL system will
exhibit sustained oscillations.
At the time of preparing this write-up, we determined that the first ZNT
method gave a value of k p that made the CL systems smallest time constant
to be of the same order as the sampling period 0.005 ms, and the CL system
was unstable. Indeed, any CL system, on digitization of the controller, remains
stable only if the sampling period is at most about one-tenth to one-twentieth
of the smallest time constant of the continuous-time CL system.
42
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
H (s) Saturation
H-bridge
Vreq
Motor
u
PWM
unew
29 u u 1
0.8 actual
s2 + 10s + 29 Vs Vs
Figure 4.3: Block diagram of the plant for which we wish to tune a PID controller.
Here, unew is controllers output, and uactual is numerical value of voltage applied
to motors armature. The duty ratio = uactual /Vs is input to the PWM module of
the dsPIC30F4012. The dsPIC outputs a PWM signal to the Solarbotics H-bridge
board. The H-bridge board is fed from a dc power supply at a voltage of Vs . The
H-bridge board outputs a variable-magnitude dc voltage Vreq to the PMDC motor.
The prefilter H (s) is not part of the plant model that we identified in Experiment
1 or 2. We have added H (s) here to make the plant model amenable to ZNT meth-
ods, as described in Section 4.6. Note that the u to path shown in this figure is
more accurate than that shown in Figure 3.1.
4.7 Questions
4.7.1 To do at home
Q3 Determine k cr using rlocus of GNU Octave upto the resolution of the hu-
man eye. Simulate the CL system in GNU Octave and determine k cr and Pcr .
Fill the following table.
From rlocus
Value of k cr
From simulation
From rlocus
Value of Pcr [s]
From simulation
43
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Q6 Based on the values of ts that you have in the above table, and given that
the sampling interval is 2 ms, do you think the CL system under digital
control will be stable?
Q7 Repeat Q5 using easysim.m and Ts = 2 ms. Is the CL system stable?
Q8 From the above table, which controller would you select to control your
plant?
Q9 Is the design specification of QAD satisfied by any of the three controllers?
Q10 Write the Eulers approximation-based descretized versions of each of the
three controllers and H (s) in C code. You will take these codes to the lab.
Q11 Program the discretized version of H (s) in your dsPIC. Use the k cr ob-
tained in Q3. Give a step input and see the CL response. If sustained oscil-
lations of the CL system are not seen, then tune k cr until you hit a value that
provides sustained oscillations. Note this value of k cr and the corresponding
value of Pcr .
Q12 With the value of k cr and Pcr determined in Q11, form a PID controller.
Note 4.3. Note 4.2 applies here too.
Q13 Check using easysim.m that this PID controller works. Note its perfor-
mance in the following table.
Q14 Program the digital controller from Q13 into the dsPIC and run the setup.
Record the results in the following table. Plot the necessary data.
2nd overshoot
Type of experiment ts ess Mp
1st overshoot
[s] [%] [%]
Practical
44
Chapter 5
Experiment 4: Control of
speed using armature current
5.1 Goals
The area of sensorless speed control (SSC) uses the measurements of the voltage
V applied to the armature, and one of either armature current i or back emf E,
to estimate the motor speed :
1. Back emf speed control: V is turned alternatively on and off, as in the case of
our H-bridge circuit. During the on period, the motor gathers speed. During
the off period, a brief period is allowed to elapse until i dies down while the
rotor is coasting, and then the voltage is measured across the armature. This
voltage is the estimate E b of the back emf. Then the estimate b of can be
obtained as E/K
b b . Note that i is not measured in this method.
Commerical controllers, such as [10], exist for SSC of dc motor using feed-
back of back emf. Also, see, for example, [11] for some details.
2. Speed control using armature current: An estimate of the back emf is obtained
by measuring the armature current i and using the expression E = V R i.
Commercial controllers, such as [12], exist for SSC of pmdc motor using IR
compensation. Also, see, for example, [13] for some details.
The advantage of SSC is that V and i can be measured using components that
are fixed in the motor circuit. On the other hand, speed is measured using
devices, such as encoders or tachogenerators. There are several drawbacks in
using these devices such as increased volume of the motor unit and lowered
45
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
reliability as the encoders may go bad earlier than the motors. The latter draw-
back may be particularly significant where repair may not be possible, such as
in space applications.
5.3 Background
The equations that describe a pmdc motor are
di
V=L + Ri + E (5.1)
dt
d
J = B + T TL (5.2)
dt
We see from Figure 2.2 that there are two time constants in the V to transfer
function of the pmdc motor. These are the electrical time constant e = L/R
and the mechanical time constant m = J/B. As a rule of thumb, in a general
pmdc motor, e is about one tenth m . However, in our case, the e is 1.9 105
s, while m is 0.44 s. That is, transients in i settle about 104 times as fast as
transients in , meaning that e can be ignored without any loss of accuracy.
To remove e from discussion, we set L = 0, resulting in V = R i + Kb . This
equation shows that, when e 0, can be calculated as = V KR i . We can
b
use this equation to determine
b and use this estimate for feedback control of
as shown in Figure 5.2.
5.4 Questions
5.4.1 To do at home
Q1 Using the values of Km and m that you determined from the OL step re-
sponse in Experiment 1, determine the values of B and R as follows.
Solve equations (2.2) and (2.3) simultaneously to determine the values of
R = R H + Rm + Rsens and B. Use the values of J, KT , Kb from Table 1.1. Do
not use the value of B calculated in Section 1.6.
If you obtain B < 0, then you will need to find Km and m once again using
the method of Section 2.4. As you cannot do this at home, use the value of B
given in Section 1.6.
46
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Vs Vs
S1 S2 S1 S2
Motor Motor
S3 S4 S3 S4
Rs Rs
Figure 5.1: How the H-bridge is used to switch the direction of rotation of the
motor shaft. With the switches S2 and S3 open, the pulse width modulated joint
opening and closing of switches S1 and S4 make the motor turn in one direction
with varying speed. Similarly, with the switches S1 and S4 open, and S2 and S3
closing jointly by the PWM signal the motor turns in the other direction. In either
direction, the effective resistance R of the motors armature includes the resis-
tance R H of the two closed switches, the resistance Rs of the sensing resistor, and
the resistance Rm of the motor armature, as mentioned in Section 1.6. Also, the
Vreq of Figure 4.3 is actually the time average of the PWM voltage seen between
the terminal labeled Vs and ground in the above diagram, and not the voltage im-
mediately across the motor terminals.
IC voltage
9V 12 V 18.95 V
Equivalent internal resistance () 2.86 2.39 2.00
http://www.solarbotics.com/products/k_cmd/resources/
47
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
ref + u
Controller Motor module
1
+
R
b
Kb
isens
Figure 5.2: Block diagram of control of speed using feedback of armature current.
5.4.2 To do in lab
There are other parts of main-prog.c that you will uncomment at your
discretion.
Q4 Write a code to apply a step input to the motor. Run the setup in OL mode.
Identify the system parameters Km and m by using the OL step response.
Q5 If Km and m are different from those you saw in Experiment 1, calculate
the values of R and B as you did in Q1.
Else, in the following, use the R determined at home.
Q6 Control the motor in the following ways:
Q6.1 Using feedback of speed (as in Experiment 1).
b = (u R isens ) Kb , and
Q6.2 Using feedback of current with
.
Q6.3 Using feedback of current with b = u Rbi Kb , where, bi
1 1
1.8 isens 30 .
See Figure 1.7 and Section 1.5 for an explanation of this relation between
i and isens .
48
FG +12V
+-
12V
1 L298 + GND -
September 10, 2013
1 CN1-PS PC
Is RS232
C
DB9-
Rs = 4.7 10
UART-A
USB
CN4-I/P
M1 M3
M
M2 H-bridge board M4
49
C board
CN2-
CN5-O/P
1
EE380 (Control Lab) IITK
+12V
Encoder
3
5
5-9
DB9-CAN
CN3-Motor
Figure 5.3: Connection diagram of the setup. In Experiment 2, a signal from the FG was input at connector CN4-I/P of the C board. On the other
hand, in the present experiment, the motor current is instead input at this connector. The capacitor C = 1000 F.
Lab Manual
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
You may need to tweak this relation between i and isens for your own
setup to obtain satisfactory results. See Section 5.6 for a systematic and
quick way to determine the relation between i and isens .
.
Q6.4 Using feedback of current with b = u Rbi Kb , where, bi
2.5isens .
In each of the above cases, plot vs. t and
b vs. t as subplots on figure, and
vs. t and u vs. t as subplots on another figure. That is, you will show us
two figures for each of Q6.2 through Q6.4.
In the control of motor speed, is the feedback of armature current an adequate
substitute for the feedback of motor speed?
For whatever reasons, isens in the block diagram of Figure 5.2 is not equal to i,
the armature current. From Figure 1.7 that we obtained through certain trials
before we developed these experiments, we estimated that
1 b( TL )
isens = i
a( TL ) a( TL )
bi = a( TL )isens + b( TL )
50
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
V Rbi
b=
.
Kb
Step 1 Construct
b as shown in Figure 5.4.
I (s)
b 1
(s) = U (s)
b R ,
a as Kb
with
1/R
I (s) = Kt Kb
U (s)
1+ R ( Js+ B)
7 Kt Kb
b ss7 7) = R b , where = 1 +
a ( Kb .
R B
9
b ss9 9) = R b .
a ( Kb
51
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
TL (s)
Kb
1/a
b
1( t ) +
a
+
1/Kb
b
52
Chapter 6
Experiment 5: Control of
armature current
6.1 Goals
To control the armature current of the pmdc motor at the desired value.
The disturbance observer (DOB) that we see in Experiment 6 requires the arma-
ture current of the pmdc motor to be well-regulated. In the present experiment,
we attempt to make the armature current well-regulated.
Apart from the application in the DOB, a current loop, when present, is the
innermost loop in electric drives, the next outer one being the speed control
loop, followed by the position control loop, which is also the outermost loop
as shown in Figure 6.1. This three-loop structure is used also with motors other
than pmdc. This structure is used for tracking a given d while restricting the
speed or current. When only control of speed is needed while constraining the
current, the outer-most loop can be removed. See, for example, [14, page 36].
Figure 6.2 shows the block diagram of the pmdc motor under control of arma-
ture current. Figure 6.3 shows this block diagram redrawn. Figure 6.3 shows
that i cannot track id alone, but only id iex . The current i will be considered
as well-regulated if it tracks id nicely; i will not track id nicely as long as iex
dominates.
53
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
If Ki (s) has poles, then Kb /Ki (s) will contain zeros. Zeros represent derivative
elements. Especially during transients in , these zeros will differentiate
with respect to time, leading to a large value of iex , and consequently to large
errors between id and i. Also, these zeros amplify sensor noise. Therefore,
we prefer a 1/Ki (s) that does not have zeros. However, if we do not have a
choice, then we need to use a filter on isens , which is the sensed version of i.
This filter is meant to remove any noise, which the capacitor that is in parallel
with Rs , may not have blocked. In our trials we found that the software filter
in main-prog.c
IF = (1-5.0*T)*IF + 5.0*T*Is; // Low-pass filter.
seems to be rejecting this noise adequately.
An easy way to ensure that i tracks id is to use for Ki (s) a proportional con-
troller with a large gain. The problem with the proportional controller is that
it provides a high gain in the transient as well as steady state phases of the
signals. This means that when the error between id and i is large, the demand
on u is large, and may exceed the 9 10 V that our H-bridge provides.
Another choice for Ki (s) is a PI controller. The virtue of a PI controller is that, in
the transient phase of the signals, as the frequencies are high, it offers a small
gain, and therefore a small u. In the steady-state phase of the signals, as the
frequencies are small, it provides a high gain to nullify the error between id
and i.
The drawback of the PI controller is that, as 1/Ki (s) is a high-pass filter,
Kb /Ki (s) amplifies noise. However, the software filter shown above helps.
Remark 4. Note that, in the lab, we measure i using a resistor Rs placed in the ar-
mature path as shown in Figure 5.1. However, that location of Rs tells us that i is
non-negative, irrespective of the true sign of i. A scheme that gives the sign of i as well
as its magnitude is shown in Figure 6.4. As our present experiment is designed such
that i does not become negative, the scheme of Figure 5.1 is adequate for now.
6.4 To do at home
Q1 Using the voltage equation (5.1) and the fundamental torque equa-
tion (5.2), and T = Kt i, determine the current at steady-state speed with
V = 9 V and TL = 0. Call this current id1 . See the lecture slides.
The figure id1 is the maximum value that we wish to specify as reference
for the current control at TL = 0. Any greater value of reference current at
TL = 0 will require the H-bridge to apply a voltage V > 9 V, and thereby go
into voltage saturation. We wish to avoid saturation so that we may work
with an approximately linear plant.
Q2 Using the voltage equation (5.1) and the fundamental torque equa-
tion (5.2), and T = Kt i, determine the current at steady-state speed with
V = 9 V and TL = 0.003 N m. Call this current id2 . See the lecture slides.
54
September 10, 2013
TL
d + d + id + u+ 1 i T+ 1 1
K K Ki sL a + R Kt Js+ B s
Kb
55
Figure 6.1: Position control of a pmdc motor. This three-loop structure is used with other types of motors too. This structure is used for tracking a
given d while restricting the speed or current. When only control of speed is needed while constraining the current, the outer-most loop can be
EE380 (Control Lab) IITK
Figure 6.2: Control of current in a pmdc motor. For the design of the controller
Ki (s) of current, use the values of R , B that you determined in Question Q5 of
Section 5.4. Note that Ki (s) does not stand for an integral controller. Instead, it is
the controller of the armature current i.
TL
id + + 1 i T + 1
Ki ( s ) Kt
sL a + R Js + B
Kb
iex Ki ( s )
Figure 6.3: The block diagram of Figure 6.2 redrawn. We can see that i tracks
id iex , and not id alone. i is considered well-regulated if it tracks id nicely. This
nice tracking will not happen while iex dominates. Therefore, we choose Ki (s) to
supress iex . Two choices for Ki (s) are P and PI.
56
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Vs
S1 S2
Motor Rs
IA
+
S3 S4 +
Vref Vsens
Figure 6.4: The correct placement of sensing resistor Rs to measure armature cur-
rent. IA is an instrumentation amplifier. This placement of Rs correctly gives the
sign of the armature current, unlike the placement of Rs in Figure 5.1. In that fig-
ure, irrespective of whether the armature current is flowing from right to left or
from left to right in the armature, the current through Rs is from top to bottom.
That is, that way of measuring the current shows the armature current as positive
always, irrespective of the actual direction of the current.
skills to build the controller through a little bit of reasoning combined with
simulation as follows.
Choice of K P At the first instant after the control system is deployed, the
error e(0) = id i (0) is the largest (assuming a stable control system),
and, consequently, K P e is the largest at this instant. Therefore, K P may
be chosen, for example, as K P e(0) < 9 V. For example, if id2 = 0.15
A, then K P < 9/0.15 = 60 V/A. Any value of K P > 60, will drive the
applied armature voltage into saturation at the initial instant of control.
Choice of K I Based on a quick sketch of the (K P s + K I )/s, we can see that
the larger the K I , the greater the speed of response of the control system.
So, K I may be chosen as large enough for the settling time to be about 0.5
s. A simulation using the m-file provided e5q4.m helps.
Answer the questions in e5q4.m for yourself. We may quiz you on them.
57
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
6.5 To do in lab
Q7 Write the discretized version of the home-designed controller into
main-prog.c. In main-prog.c implement the part of the block diagram of
1
Figure 6.2 that is outside the plant. Either use bi = isens , or bi = 1.8 isens (such
as in Question Q6.3 of Section 5.4.2). The results we showed in the lecture
1 1
slides are using bi = 1.8 isens 1000 , though our later tests seemed to be giving
better results with the PI controller using bi = isens .
Q8 Under the feedback control of Figure 6.2, take the readings of u and i for
Q8.1 id = id1 without any load on the motor. Immediately after the motor
shaft seems to be rotating at constant speed, hold the shaft tightly for
about a second and release.
Q8.2 id = id2 with the load provided by us tied to the pulley. Immediately
after the motor shaft seems to be rotating at constant speed, hold the shaft
tightly for about a second and release.
Q9 Take plots in both cases. Each plot will show i before and after application
of disturbance. With what error does i track the id in the two cases?
Q10 Are you satisfied with the disturbance rejection? Explain.
Q11 Write down the part of the C code that you wrote for this experiment.
You will use this code in the experiment on disturbance observer.
58
Chapter 7
Experiment 6: Disturbance
observer
7.1 Goal
7.2 Background
A conventional forward path controller such as P, PI, PID, lead, lag, etc, which
is a single degree of freedom controller (see Figure 7.1 (a)), can reject disturbances
as well as provide good performance if designed and tuned properly. The
design and tuning becomes much easier with a so-called two-degree of freedom
(2DOF) controller (Figure 7.1 (b)). There are two parts to this controller, each of
which can be designed and tuned independent of the other.
59
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
d + e i T +
C (s) G1 (s) G2 (s)
TL
(a)
d e u + i T +
Ca ( s ) G1 (s) G2 (s)
Cb (s) TL
(b)
Figure 7.1: A single degree-of-freedom controller, (a), and a 2DOF controller, (b).
Ca (s) provides one degree of freedom while Cb (s) provides the other. In the control
system of (b) Cb (s) helps reject TL , while Ca (s) helps track d .
TL
id T + 1
Kt Js+ B
7.3 Questions
7.3.1 To do at home
1.2. Evaluate the two TFs when is small. What is the value of ?
1.3. In which scheme is T
bL closer to TL when of b
J, B,
b Kbt are poor estimates?
2. Run the SIMULINK file named dob.mdl and describe briefly the effect of
each of the following changes.
2.1. K (s) being the controller you designed in Experiment 1 as opposed to
the lag controller shown in dob.mdl.
60
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
id T + 1
Kt Js+ B
TL + Js+ B
+
1 b b
s+1 bt (s+1)
K + n
K
bt
T
bL
(a)
id + T + 1
Kt Js+ B
+ TL
+ +
bi L 1 bJs+ B
b
s+1 bt (s+1)
K + n
K
bt
T
bL
(b)
Figure 7.3: Open-loop DOB to estimate TL , (a), and closed-loop DOB to estimate
TL , (b), [17]. n is sensor noise. b
J, B,
b Kbt are the estimates of J, B, Kt respectively. In
our experiment, we use the values of b J, K
bt taken from Table 1.1, and the value of B b
that is calculated from the unit step response of the OL motor as in Question Q5
of Section 5.4.
7.3.2 To do in lab
5. Take an OL step response of your motor, and calculate R and B. You can
use the latter for B. J = 1.34 106 kg m2 .
b You can use b
6. If necessary, modify the values of B and J, and the relation between bi and i f
in main-prog-exp6.c.
7. Run your setup and take readings on both sides of the instant when the load
steps up in the following cases.
7.1. With bi L fed back. Plot and T
bL versus t
61
Lab Manual
+
Kb
bi L
Inverse inertia
62
Filter
y1 + Js+ B
1 b b
s+1 y2 bt (s+1)
K
Figure 7.4: The full block diagram of the two-degree of freedom control of a pmdc motor. The first degree of freedom is provided by the DOB in
the inner loop. The second degree of freedom is provided by the speed controller K (s) that is in the outer loop. The shaded portion of the block
1
diagram is implmented in dsPIC30F4012. The purpose of the filter 1/(s + 1) is to not just make the inversion of Js+ B practically possible, but also
September 10, 2013
to improve the disturbance rejection performance of the system. See [17] for details.
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
63
Lab Manual
TL
Inertia
d + iref + + u + 1 i T + 1
K ( s ) Ki ( s ) sL+ R Kt Js+ B
+
Kb
(i )
EE380 (Control Lab) IITK
isens
cf
s+cf
bi L if
64
1 ( i )
d f
bi
1
Filter s+1
Inverse inertia
y1 + bJs+ B
b
y2 bt (s+1)
K
September 10, 2013
Figure 7.5: The full block diagram of the two degree of freedom control system as implemented in our lab. The shaded portion of the block
diagram is implemented in main-prog-exp6.c.
Chapter 8
Experiment 7: Disturbance
observer without feedback of
current
8.1 Goal
To build and test a pmdc motor speed control system that uses a disturbance
observer (DOB) but does not use the feedback of armature current.
8.2 Background
65
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
in the Networked Control Systems Lab, we used a capacitor across the sens-
ing resistor to remove this noise, and an instrumentation amplifier to boost the
resultant signal. In the Control Systems Lab, however, we have not yet imple-
mented this filter-amplifier combination. So, measurements of current are not
yet accurate enough for feedback.
8.3 Questions
8.3.1 To do at home
1. Play with the SIMULINK file named dobgm.mdl to acquaint yourselves with
the two-degree of freedom control system with the DOB. Some items of in-
terest are
1.1. What is the effect of K (s) being a PI controller as opposed to a lag
controller?
1.2. What is the effect of K I (s) being a PI controller as opposed to a propor-
tional controller?
1.3. What is the effect of injecting i L with a instead of +?
1.4. What is the effect of break the injection of i L ?
1.5. What is the effect of varying ?
1.6. What is the effect of varying the plant parameters (J, B, R, Kt ) with the
respective estimates ( J, B, Kt ) kept constant at their initial values?
2. Write the equations that describe the overall closed-loop system of Fig-
ure 7.4 (b).
3. Discretize these equations.
4. Check if your discretized equations match what we gave you in the attached
m-file expt6.m.
5. If everything matches, then run the expt6.m in GNU Octave.
6. Write the C code of the controllers that you will implement in the lab.
8.3.2 To do in lab
7. Take an OL step response of your motor, and calculate R and B. You can
use the latter for B. You can use J = 1.34 106 kg m2 .
8. Modify the values in the C code from Question 6, if necessary.
9. Write your C code into the appropriate place in the main-prog.c
10. Run your setup and take readings on both sides of the instant when the
load steps up. Provide the following two plots as subplots one below the
other: u versus t, and versus t.
66
TL
ref + iref + + u + 1 i T + 1
K ( s ) K I (s) Kt
sL + R Js + B
+
Kb
i L
1 y1 + Js + B
b b
s + 1 bt (s + 1)
September 10, 2013
y2 K
(a)
TL
ref + iref + u + 1 i T + 1
67
K ( s ) K I (s) Kt
sL + R Js + B
Kb
Js + B
EE380 (Control Lab) IITK
b b
K
bt (s + 1)
(b)
Figure 8.1: (a) The overall block diagram of the two-degree of freedom control of a PMDC motor, and (b) The block diagram of (a) simplified to
remove the feedback of current. This simplification is done by setting the gain from i to y1 equal to 1 instead of 1/(s + 1). The advantage of
Lab Manual
scheme (b) is that it does not need the measurement of current if we have the measurement of speed. The disadvantage is it does not give us T
bL ;
therefore, this scheme does not really realize a DOB. In applications where we need T
bL , we need to implement scheme (a).
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
11. How did you expect your DOB to work? How did it actually work?
8.4 M-files
%% expt6.m
clc; clear all; close all;
format long
%% Simulation
Ci = 100; % inner controller (current controller)
% Initialization
W = 0; xw = 0; xid = 0; xir = 0;
for k = 1:tend/T+1
% Speed controller
ew(k) = Wr(k) -W(k); % speed error
Iref(k) = (b1-b0*a1)*xir(k) + b0*ew(k);
xir(k+1) = (1-a1*T)*xir(k) + T*ew(k);
68
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
69
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
70
Chapter 9
9.1 Goals
9.2 Introduction
In this experiment we will study the theoretical and practical aspects of the
control of the angular displacement of the shaft of a PM DC motor using a
microcontroller. The block diagram of the setup is as shown in Figure 1.1. A
dsPIC30F4012 micro-controller is used as the platform on which to implement
our digital controller, and H-bridge four-quadrant DC chopper is used to drive
the DC servo motor. Please see the first two chapters of this manual for the
details of the hardware and the software platform. Follows a list of questions
for this experiment.
Since the inductance L a is very small, we may neglect L a . Then the TF between
the motor shaft position (s) and the armature voltage V (s) is
(s) Km
= (9.1)
V (s) s(m s + 1)
71
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
where, Km is the motor gain constant and m is the motor time constant. These
are as in Equation (2.1).
The parameters of the motor, gear, and encoder are provided in Table 1.1.
The dead zone in the Vm versus u charaacteristic of Figure 1.7 did not affect
much in the control of the speed of the DC motor as the speed was needed to
be at a large value and u quickly becomes large.
In the case of control of position of the shaft of the shaft of the DC motor, how-
ever, u may become small when the desired position is reached. If u becomes
smaller than 2 volts when Vs = 12 V, then Vm will be zero, and the position
control system will become unresponsive. To overcome this situation we have
two alternatives:
1. Use an integral component in the controller.
2. Add the following code in main-prog.c before or after the if condition used
for limiting the duty ratio.
if(u<0&&u>-2)
u = u - 2;
else if(u>0&&u<2)
u = u + 2;
9.5 Questions
9.5.1 To do at home
72
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
9.5.2 To do in lab
Q7 Write a code to give a step input to the given motor. Run the setup in OL
mode.
Q8 Identify the system parameters Km and m by using the OL step response.
Q9 For the identified model, redesign your controller using root locus in MAT-
LAB.
Q10 With the discretized version of the above-redesigned controller, perform
a simulation of digital control of the continuous-time plant using the m-file
provided in Experiment 1.
Q10 Program the home-designed digital controller and run the setup. Record
and plot the necessary data.
Q11 Program the lab-designed digital controller and run the setup.
Q12 Compare the following results:
1. those using the controller designed for the physics-based model and ob-
tained on Matlab,
2. those using the controller designed for the physics-based model and ob-
tained from the experimental setup,
3. those using the controller designed for the identified model and obtained
on Matlab,
4. those using the controller designed for identified model and obtained
from the experimental setup.
Q13 Conclusions:
1. Is the physics-based model a good match to the plant? If not, what do
you think we have ignored that has lead to the difference?
2. What are the skills you learned from this experiment?
3. Would you have preferred to learn a different skill set from the control
lab? If yes, which skills?
4. How could we have organized this experiment differently to make it
more meaningful to you?
73
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
74
Chapter 10
Experiment 9: Encoderless
speed control of PMDC motor
using compensation of plant
nonlinearity
10.1 Questions
10.1.1 To do at home
KT R J
Km = , m = .
R B + K T Kb R B + K T Kb
Use the values of J, KT , Kb from Table 1.1. Do not use the value of B calcu-
lated in Section 1.6.
TIP: Write a small (4 6 lines) GNU Octave code for doing this calcula-
tion as you may be required to do the calculation once again in the lab.
Bring the Octave code to the lab
75
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Figure 10.1: A control system that helps automatically measure the input-ouput
characteristic of the H-bridge.
d + uc u 1 H-bridge motor
CON COMP PWM
VS combo
b 1 + isens
R
Kb
Figure 10.2: The encoderless speed control system with compensation of H-bridge
nonlinearity.
Q3.1 Write down the transfer function, with numerical values, of the PI con-
troller used in Figure 10.1. (Note: R = R in the figures in this assign-
ment)
Q3.2 When you modify this C-file to use on your setup, which values in the
block diagram will you modify in the C-file?
Q3.3 Values of which variables in the block diagram are sent to the PC by
this C-file?
Q4.1 Write down the equation that you would use in the Figure 10.2 as the
compensator. (NOTE: You will obtain your own compensator in the lab)
Q4.2 Write the C-code implementation of the part of the block diagram that
is in the dashed box.
Q4.4 For how many seconds was main-prog-exp9.c run to generate the
data in exp9saurav.log?
10.1.2 To do in lab
Verify that in your experimental setup the lead from the sensing resistor Rs
is connected to CN4 input pin 1 as shown in Figure 5.3, in addition to the
usual connections for speed control.
76
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
There are other parts of main-prog.c that you will uncomment at your
discretion.
Q5 Write a code to apply a step input to the motor. Run the setup in OL mode.
Identify the system parameters Km and m by using the OL step response.
[ 10 min]
Q7 Use the controller from Experiment 1. Control the motor using feedback of
speed. Sketch versus t and u vs. t in the table provided. Use ref = 100
rad/s in Q7, Q9, Q12. [ 10 min]
Q8 Use the controller from Experiment 1. Control the motor using feedback
b = uKR i . Sketch vs. t,
of current with b vs. t, and u vs. t in the table
b
provided. [ 15 min]
Q9.1 Why are the steady state values of in Q7 and in Q8 not the same?
Q10 Burn the C-file main-prog-exp9.c into the C. Take care to modify the
value of R. This file implements the block diagram of Figure 10.1 and returns
the data for ud and u. Record this data into a log file using terminal.exe.
[ 10 min]
Q11 Use the m-file readplot_exp9.m to process the data given out by
main-prog-exp9.c. [ 10 min]
Q11.2 Sketch the compensator generated by this m-file in the below space.
77
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
Q Var Plot
Q7
Q7 u
Q8 Q12
Q8
b Q12
b
Q8 u Q12 u
78
Software used
The Controls Lab has the following software on Microsoft Windows XP.
MPLAB_IDE_8_86.zip
mplabc30_v3_30c_windows.exe
http://ww1.microchip.com/downloads/en/DeviceDoc/
MPLAB_IDE_8_86.zip
http://www.microchip.com/stellent/
idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en536656
Microchip also has MPLAB_IDE_8_87.zip on their site. This 8.87 version may
work too. It can be downloaded from
http://www.microchip.com/stellent/
idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=
en019469&part=SW007002
Occassionally, when burning to the dsPIC from MPLAB IDE fails, we use
PICKIT 2 software, which came packaged as PICkit 2 v2.61.00 Setup
A.zip on PICkit 2 programmers CD.
Terminal.exe
The version of Brays terminal.exe used in the lab is version 1.9b 20040204.
79
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
GNU Octave
We have been using versions of GNU Octave >= 3.2.4. GNU Octave can
be downloaded from the website named Octave-Forge that has the URL
http://octave.sourceforge.net/. On this page, there is the following link
to a Windows installer of GNU Octave
https://sourceforge.net/projects/octave/files/
Octave%20Windows%20binaries/
with installation instructions that are easy to implement.
80
Bibliography
[3] Frank L.Lewis and Vassilis L.Syrmos. Optimal Control, pages 6768. Wiley
Interscience, 2 edition, 1995.
[4] Gene F. Franklin, J. David Powell, and Michael L. Workman. Digital Con-
trol of Dynamic Systems. Addison-Wesley, 3 edition, 1998.
[6] Andrzej Banaszuk [People in Control]. Control Systems, IEEE, 32(3):27 31,
June 2012.
[7] Tore Hgglund and Karl J. strm. Automatic tuning of PID controllers.
In William S. Levine, editor, The Control Handbook, pages 817 826. CRC
Press LLC, 1996.
81
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
82
September 10, 2013 EE380 (Control Lab) IITK Lab Manual
83