Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

TEE 451 - Control Systems

Winter 2021

Instructor: Michael McCourt Assignment: Lab 4


Motor Control 2

1 Introduction to Motor Control Lab 2


This is the second part of a two part lab where we control the speed of a motor in RPMs. It is recommended
to keep your circuit connected from Lab 3. We will be controlling the speed of a motor using the Arduino,
a motor driver, and a rotary encoder. In this lab, you will design a PI controller for the motor speed.
Recall that a PI controller is the sum of a proportional controller and an integral controller. The control
signal u(t) (in volts) can be calculated from the error e(t) (in RPMs) according to the following equation.
Z t
u(t) = KP e(t) + KI e(τ )dτ
0
In Simulink, it is straightforward to implement a PI controller using an integral block, two gain blocks
(KP and KI ), and a summing block to add them together. It is not as straightforward to implement the
PI controller in real time for two reasons. The first is that the error signal e(t) is not known in advance
so the integral cannot be determined for future times. In addition, our controller is implemented using
a digital controller where the signal is sampled. While the exact integral cannot be computed, it can be
approximated discretely using the Riemann sum method. This method divides the area under the curve
into small slices that can be calculated as the area of a rectangle.

x(t1)
x(t)

t1 t2 t

For example, when approximating the integral of a function x(t) between two points, the rectangle
has a base that is as wide as the difference in time between the two points and height defined by the value
of the function itself. The area of each slice can be calculated according to the following equation.
Z t2
x(t)dt ≈ x(t1 ) · ∆t ∆t = t2 − t1
t1

page 1 of 4
Control Systems Winter 2021

While there are different Riemann sum approximations based on using the left, right, or center point of
the function, we will only use the left Riemann sum because of our real time constraint. The area of
the function over a longer time span can be calculated by summing these rectangles over the entire time
period. Of course this method is an approximation and it introduces error. However, when the number
of rectangles is very large, the time differences ∆t are small, and this approximation is very accurate.
As a note, our controller is not exactly periodic so the value of ∆t may fluctuate over time. To account
for this, you must recalculate ∆t each iteration through the loop. In our simulation, the integrated error
should be updated each iteration by taking the previous integrated error and adding the new error. If
the loop index is i, the integrated error can be updated using an equation such as the following.
intError(i) = intError(i − 1) + error(i) ∗ ∆t
This will approximate the integrated error which we can use for the PI controller.

2 Lab Safety
This lab has potential safety concerns due to electric current and the rotating motor. When the power
adapter is connected, make sure to not touch any wires or circuit components as there is a risk of electric
shock. Before touching circuit components, make sure to disconnect the power adapter. If you must
leave the room, you can unplug the power adapter which eliminates most risks. Finally, be careful when
handling parts with sharp edges including the pins on integrated circuits.

3 PI Control Design and Simulation


In this part of the lab, you will design and simulate a PI controller in Simulink. You may use any method
to design the PI controller including the PID tuner tool in Matlab.

1. Create a PI controller in Simulink using the following blocks: two gains, an integrator, and a
summing block.
2. Start with the same proportional control gain you used in Lab 3. Test several different integral gains
to find one that gives good performance. You may choose any value for the gain but document your
reason for selecting it.
3. Test reducing the value of the proportional gain now that you have added integral control. If you
change your gain, document your reason for changing it.
4. Simulate the control system with a square wave input that alternates between 40 RPM and 80 RPM.
Adjust the period to make sure the output settles for 2-5 seconds before switching. Run for three
full periods, i.e. three times at each setpoint. Plot both the reference input and system output on
the same set of axes and include in your report.
5. Test with a ramp input that increases the desired RPM from 30 to 90 linearly over about 20 seconds.
When the desired RPMs hits 90, you can stop the test. Plot both the reference input and system
output on the same set of axes and include in your report.

4 PI Control of the Motor


In this section, you will test the PI controller you designed on the physical system. It is recommended
that you start with the script you developed in Lab 3 and add lines of code to add the integral controller.

page 2 of 4
Control Systems Winter 2021

1. Create a new variable to store the integrated error over time. It is recommended to create this as
a vector that tracks the integrated error at each loop iteration.

2. Calculate the time elapsed (∆t) from the previous loop iteration to the current iteration using your
time vector.

3. You will approximate the integral by using the Riemann sum method explained in the introduction.

4. Write a line of code to calculate the control signal as the sum of the proportional control gain times
the error plus the integral control gain times the current integrated error.

5. Test your PI controller on the physical system. At this point, feel free to adjust your gains to
improve the performance of your controller. Make sure to document your reasons for making the
change and explain in your report.

6. Test with a square wave input that alternates between 40 RPM and 80 RPM. Adjust the timing to
allow the output to settle at each setpoint for 2-5 seconds before switching. Allow the simulation
to run for three full periods of the reference input. Collect the reference input and system output,
plot on the same set of axes, and include in your report.

7. Test with a ramp input that increases the desired RPM from 30 to 90 linearly over about 20 seconds.
Plot this data and include in your report.

8. Be sure to compare all test results to your simulation results. Use the language you are learning in
class including performance concepts, steady state error, sensitivity, noise, disturbance, etc. Also,
be sure to compare the performance of the PI controller to the proportional controller from Lab 3.

5 Bidirectional Motor Control


In this section you will modify your code to control the speed of the motor in both directions. You can
configure the motor to spin in the negative direction by switching the two PWM signals to allow current
to flow in the opposite direction. This is similar to previous labs where you configured the thermoelectric
heater for cooling.

1. Modify your code to check whether the control signal is positive or negative. When the signal is
positive, you can use your existing code to spin the motor in the positive direction.

2. When the control signal is negative, you can switch the role of the two PWM signals to allow the
motor to spin the opposite direction.

3. Write code to create a reference signal that is a square wave that alternates between 50 RPMs and
-50 RPMs. Adjust the timing to allow the motor to settle at each setpoint for 2-5 seconds before
switching. Allow the simulation to run for three full periods of the reference input. Collect the
reference input and system output, plot on the same set of axes, and include in your report.

4. At this point, feel free to adjust your gains to improve performance, reduce steady state error,
reduce the noise sensitivity, or any other reason. Make sure to document your reasons for making
the change and explain in your report.

page 3 of 4
Control Systems Winter 2021

6 Lab Report
This lab is the second part of a two part lab. For this lab, you will individually write and turn in a
formal lab report. You should document your progress for Lab 3 and Lab 4. Your lab report should
be organized into sections such as Introduction, Motor System Identification, Proportional Control De-
sign and Simulation, Proportional Control Physical Test, PI Control Design and Simulation, PI Control
Physical Test, and Conclusions. Discuss your results for both simulation and physical experiments. Make
comparisons for all cases when you physically tested the same experiment as you did in simulation. The
physical system behaves differently so you will have some observations to make here. As this is a formal
report, use formal writing and label all figures and tables.

page 4 of 4

You might also like