100% found this document useful (1 vote)
456 views100 pages

LEGO EV3 Control Lab Matthew Herdin August 1 2018-FG

Uploaded by

Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
456 views100 pages

LEGO EV3 Control Lab Matthew Herdin August 1 2018-FG

Uploaded by

Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100

LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi

August 1, 2018

LEGO® EV3® Control Lab


Supplemental material for
Farid Golnaraghi and Benjamin Kuo (2017), Automatic Control
Systems, McGraw Hill Education, ISBN 978-1-25-964383-5

Prepared by Matthew Herdin, Co-op Student, Simon Fraser University

End Position (𝟏𝟏𝟏𝟏𝟏𝟏°) Counterweight Start Position (𝟎𝟎°)

Gripper Payload

WiFi Dongle

RJ12 Cables Gripper Servo

DC Motor
EV3 Brick
Robot stand and
LEGO pieces

1
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Contents
1 Introducing LEGO® MINDSTORMS® EV3® Motor: Characterization 10
1.1 Interfacing with Simulink® ........................................................................................... 12
1.2 LEGO® EV3® MATLAB® and Simulink® Library Add-Ons .................................... 17
1.3 Interfacing with WiFi ..................................................................................................... 20
1.4 EV3® Motor .................................................................................................................. 23
1.5 Precursor to Experiments ............................................................................................... 24
1.5.1 DC Motor Parameters ............................................................................................. 24
1.5.2 Linear Regression ................................................................................................... 26
1.5.3 Our Standard Simulink® Model ............................................................................. 28
1.5.4 Obtaining Angular Parameters ................................................................................ 30
1.5.5 Transport Delay ...................................................................................................... 32
1.5.6 Finding Steady-State 𝝎𝝎........................................................................................... 34
1.5.7 The Cable ................................................................................................................ 34
1.5.8 Important: About Soldering Safety ......................................................................... 36
1.5.9 Measuring Armature Voltage, 𝑽𝑽𝑽𝑽 .......................................................................... 36
1.5.10 Measuring Armature Current, 𝒊𝒊𝒊𝒊 ............................................................................ 38
2 Project 1: Obtaining DC Motor Control Parameters ................................. 40
2.1 Electrical Characteristics ................................................................................................ 40
2.1.1 Armature Resistance ............................................................................................... 40
2.1.2 Armature Inductance ............................................................................................... 41
2.1.3 Current-Torque Constant ........................................................................................ 43
2.1.4 Velocity-Torque Graph and Maximum Motor Power ............................................ 49
2.1.5 Back-EMF Constant................................................................................................ 50
2.2 Mechanical Characteristics ............................................................................................ 54
2.2.1 Viscous Friction Coefficient, Motor ....................................................................... 54
2.2.2 Viscous Friction Coefficient, Robot Arm ............................................................... 56
2.2.3 Encoder Resolution ................................................................................................. 59
2.2.4 A Method for Finding 𝝉𝝉 .......................................................................................... 61
2.2.5 Mechanical Time Constant, Motor ......................................................................... 64
2.2.6 Mechanical Time Constant, Robot Arm ................................................................. 66
2.3 Parameter Results ........................................................................................................... 68

2
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

3 Project 2: Model Verification from Speed and Position Responses 70


3.1 Update to “Angular Parameters” MATLAB® Code ..................................................... 70
3.2 Speed Response Model and Model Parameter Code ..................................................... 71
3.3 Comparing Speed Responses, Motor ............................................................................. 72
3.4 Position Response Model ............................................................................................... 73
3.5 Comparing Position Responses, Motor .......................................................................... 76
3.6 Comparing Speed and Position Responses, Robot Arm ................................................ 76
3.7 Fine-Tuning Robot Arm Parameters .............................................................................. 78
3.7.1 Position Control Transfer Function ........................................................................ 78
3.7.2 Method for Fine-tuning Parameters and Subsequent Results ................................. 79
3.7.3 Updated Parameters, Robot Arm ............................................................................ 81
4 Project 3: Robot Arm Position Control............................................................. 82
4.1 Updated Robot Arm Simulink® Model ......................................................................... 82
4.1.1 When to tighten and release the gripper Subsystem ............................................... 83
4.1.2 When to turn on the system input Subsystem ......................................................... 83
4.2 First Attempt .................................................................................................................. 84
4.3 Subsequent Attempts ...................................................................................................... 85
4.4 Conclusions .................................................................................................................... 88
4.5 Future Projects................................................................................................................ 88
4.6 Summary ........................................................................................................................ 89
5 References...................................................................................................................... 90
6 Appendix I: A Method for Finding 𝑱𝑱 .................................................................... 91
6.1 Current versus Power % ................................................................................................. 92
6.2 Velocity versus Power % ............................................................................................... 94
6.3 Equation for Finding 𝑱𝑱 Experimentally .......................................................................... 98
6.4 Moment of Inertia Simulink® Model ............................................................................ 98
6.5 Moment of Inertia Typical MATLAB® Graph ............................................................. 99
6.6 Moment of Inertia, Motor............................................................................................... 99
6.7 Moment of Inertia, Robot Arm .................................................................................... 100

3
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Tables
Table 1. Common Simulink® blocks and their functions ............................................................ 16
Table 2. Important Simulink® EV3® blocks – motor and encoder ............................................. 19
Table 3. Gear Ratio Calculations .................................................................................................. 23
Table 4. Armature Resistance Results .......................................................................................... 40
Table 5. Armature Inductance Results .......................................................................................... 42
Table 6. Torque-Current Constant Results ................................................................................... 47
Table 7. Velocity-Torque Results ................................................................................................. 49
Table 8. Back-EMF Constant Results........................................................................................... 52
Table 9. Viscous Friction Coefficient Results, Motor .................................................................. 54
Table 10. Operational Viscous Friction Coefficient value, Motor ............................................... 56
Table 11. Viscous Friction Coefficient Results, Robot Arm ........................................................ 57
Table 12. Operational Viscous Friction Coefficient value, Robot Arm ....................................... 59
Table 13. Encoder Time Resolution Results................................................................................. 60
Table 14. Rising Time Constant, Motor ....................................................................................... 64
Table 15. Falling Time Constant, Motor ...................................................................................... 65
Table 16. Time Constant values, Motor........................................................................................ 65
Table 17. Rising Time Constant, Robot Arm ............................................................................... 66
Table 18. Falling Time Constant, Robot Arm .............................................................................. 67
Table 19. Control Parameters, Motor ........................................................................................... 69
Table 20. Control Parameters, Robot Arm ................................................................................... 69
Table 21. Control Parameters, Motor ........................................................................................... 72
Table 22. Effect of Control Parameters on ω(t) ............................................................................ 73
Table 23. Updated Robot Arm parameters ................................................................................... 81
Table 24. First Attempt: 𝑃𝑃 = 1 ..................................................................................................... 85
Table 25. First Attempt Results .................................................................................................... 85
Table 26. Second Attempt: 𝑃𝑃 = 2 ................................................................................................ 85
Table 27. Second Attempt Results ................................................................................................ 86
Table 28. Third Attempt: 𝑃𝑃 = 5 ................................................................................................... 86
Table 29. Third Attempt Results................................................................................................... 86
Table 30. Fourth Attempt: 𝑃𝑃 = 1.5 .............................................................................................. 86
Table 31. Fourth Attempt Results ................................................................................................. 87

4
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Table 32. Fifth Attempt: 𝑃𝑃 = 1.8 ................................................................................................. 87
Table 33. Fifth Attempt Results .................................................................................................... 87

Appendix Table 1. Current versus Power %, Motor..................................................................... 92


Appendix Table 2. Current versus Power %, Robot Arm............................................................. 93
Appendix Table 3. Velocity versus Power %, Motor ................................................................... 94
Appendix Table 4. Velocity versus Power %, Robot Arm ........................................................... 96
Appendix Table 5. Moment of Inertia Experimental Results, Motor ........................................... 99
Appendix Table 6. Moment of Inertia Experimental Results, Robot Arm ................................. 100

5
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figures
Figure 1. Position Control Robot Arm Setup................................................................................ 11
Figure 2. Computer (left) connected to WiFi router (right) .......................................................... 12
Figure 3. Simulink® icon in MATLAB® toolbar ........................................................................ 13
Figure 4. Simulink® start page ..................................................................................................... 13
Figure 5. Blank Simulink® model ................................................................................................ 14
Figure 6. Library Browser icon in Simulink® .............................................................................. 14
Figure 7. Library Browser window............................................................................................... 15
Figure 8. Sample model for controlling a DC Motor.................................................................... 17
Figure 9. Simulink® Hardware Support Packages ....................................................................... 18
Figure 10. Add-On Explorer with MATLAB® (top-right) and Simulink® (bottom-left) support
packages ........................................................................................................................................ 18
Figure 11. EV3® Support Package blocks ................................................................................... 19
Figure 12. EV3® Brick after successful WiFi connection. 'Settings' tab is displayed. The
working WiFi connection is represented by the WiFi symbol with the double arrow in the top-
left corner. ..................................................................................................................................... 20
Figure 13. Set the model's mode to 'External' ............................................................................... 21
Figure 14. 'Configuration Parameters' window, with 'Build options' set to 'Build, load, and run' 21
Figure 15. 'Connection Type' is 'WiFi'. Enter 'Device ID' and 'IP address' as found on Brick
screen ............................................................................................................................................ 22
Figure 16. 'External mode' has the 'TCP/IP' communication interface, and IP address is repeated
here ................................................................................................................................................ 22
Figure 17. Motor, gear-train, and circuitry ................................................................................... 23
Figure 18. We enter the datasets with the nth entries matching, then run the curve-fitting app .. 27
Figure 19. The linear best-fit of V vs I data; the slope is R. ......................................................... 28
Figure 20. The standard Simulink® model. Power is applied to the motor, and the encoder output
is converted to radians by a gain block, then output ..................................................................... 29
Figure 21. ‘To Workspace’ block parameters window. Output is saved into MATLAB®
workspace as a structure with accessible time and signal value properties. ................................. 29
Figure 22. "Block Parameters" window for the motor Encoder. .................................................. 30
Figure 23. Angular parameters as a function of time.................................................................... 32
Figure 24. The 'Transport Delay' block delays the input signal.................................................... 33
Figure 25. The transport delay's "Block Parameters" window, where the time delay is specified33
Figure 26. Front view of RJ12 cable............................................................................................. 35

6
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Figure 27. Rear view of RJ12 cable .............................................................................................. 35
Figure 28. The 6 wires of the RJ12 cable and their functions ...................................................... 35
Figure 29. The different parts of the RJ12 cable .......................................................................... 36
Figure 30. Measuring Armature Voltage while the motor is running........................................... 37
Figure 31. A close up of the voltage measurement ....................................................................... 38
Figure 32. Measuring Armature Current while the motor is running ........................................... 39
Figure 33. A close-up of the current measurement ....................................................................... 39
Figure 34. Armature Voltage vs Current ...................................................................................... 41
Figure 35. Measuring Inductance ................................................................................................. 42
Figure 36. Measuring current while the motor generates torque on a payload............................. 44
Figure 37. The spool pulls up the fishing line-clasp-pencil weight variable-payload
configuration. The larger tire in the background is used as a counterweight to decrease the
downward bending of the spool axle. ........................................................................................... 45
Figure 38. Measuring payload masses with a scale ...................................................................... 45
Figure 39. Torque vs Current at Stall, all data .............................................................................. 48
Figure 40. Torque vs Current at Stall, Low-power ....................................................................... 48
Figure 41. Angular velocity vs Motor Torque .............................................................................. 50
Figure 42. Measuring current and voltage using 2 multimeters at no-load .................................. 51
Figure 43. A close-up of simultaneous voltage and current measurements using 2 multimeters . 51
Figure 44. Back-EMF vs Angular velocity (𝐾𝐾𝐾𝐾 experiment) ....................................................... 53
Figure 45. Viscous Friction Coefficient vs % Power, Motor ....................................................... 55
Figure 46. Current measurement while robot arm is moving. Hold down the stand for steady
readings. ........................................................................................................................................ 57
Figure 47. Viscous Friction Coefficient vs % Power, Robot Arm ............................................... 58
Figure 48. Simulink® model for turning power on and off to measure time constant ................. 61
Figure 49. Angular velocity as a function of time, tau experiment .............................................. 63
Figure 50. Average of Tau vs Power %, Motor ............................................................................ 66
Figure 51. Average of Rising Tau vs Power %, Robot Arm ........................................................ 67
Figure 52. Falling Tau vs Power %, Robot Arm .......................................................................... 68
Figure 53. DC Motor Speed Response model .............................................................................. 71
Figure 54. Simulated and Actual Speed Responses, Motor .......................................................... 72
Figure 55. DC Motor Position Response model ........................................................................... 73
Figure 56. Simulink® model that controls the motor in real life.................................................. 74

7
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Figure 57. Simulink® PID Controller Block Parameters Window .............................................. 75
Figure 58. Simulated and Actual Position Responses, Motor ...................................................... 76
Figure 59. Simulated and Actual Speed Responses, Robot Arm .................................................. 77
Figure 60. Simulated and Actual Position Responses, Robot Arm .............................................. 78
Figure 61. Simulated and Actual Speed Responses after Fine-tuning, Robot Arm ...................... 80
Figure 62. Simulated and Actual Position Responses after Fine-tuning, Robot Arm .................. 81
Figure 63. Simulink® Model for Robot Arm, updated to include gripper functionality.............. 82
Figure 64. Simulink® Subsystem which determines when to tighten and release the gripper .... 83
Figure 65. Simulink® Subsystem which waits until payload is fully gripped, and then always
applies the degree step input ......................................................................................................... 84
Figure 66. Robot Arm Project, First Attempt ............................................................................... 84
Figure 67. Successful Runs, Theta(t), Robot Arm Project ........................................................... 88

Appendix Figure 1. Current vs % Power, Motor .......................................................................... 93


Appendix Figure 2. Current vs % Power, Robot Arm .................................................................. 94
Appendix Figure 3. Angular Velocity vs % Power, Motor .......................................................... 95
Appendix Figure 4. Angular Velocity vs % Power, Robot Arm .................................................. 97
Appendix Figure 5. Simulink® Model with constant and ramp inputs for J experiment ............. 98
Appendix Figure 6. Angular velocity as a function of time, J experiment ................................... 99

8
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Most undergraduate control courses have labs dealing with time
Learning Outcomes: response and control of DC motors—namely, speed response, position
response, speed control, and position control. In many cases, because of the
After successful
high cost of control lab equipment, student exposure to test equipment is
completion of this
chapter, you will be able limited, and as a result, many students do not gain a practical insight into the
to: subject. In this chapter, recognizing these limitations, we introduce the
1. Simulate speed and concept of the Control Lab, which includes three classes of experiments:
position time finding the physical values of the control parameters, verifying the model
responses of DC using speed and position responses, and finally, using the developed model
motors and simple
control systems using
for a position control project. These experiments are intended to supplement,
MATLAB® &
or replace, the experimental exposure of the students in a traditional
Simulink®. undergraduate control course.
2. Learn how to identify
the parameters of a
In this chapter, we have created a series of inexpensive control
system based on experiments for the LEGO® 1MINDSTORMS®2 EV3®3 DC motor that
system time response. would allow students to work on the subject within the MATLAB®4 and
3. Gain a practical sense Simulink®5 environment – even at home. This cost-effective approach may
of real life control allow educational institutions to equip their labs with some LEGO® test beds
problems, through the and maximize student access to the equipment at a fraction of the cost of
use of LEGO® currently available control system experiments on the market. Alternatively,
MINDSTORMS®, as a supplemental learning tool, students can take the equipment home after
MATLAB® & leaving a security deposit and learn the subject at their own pace. This concept
Simulink® tools. has proven to be extremely successful at Simon Fraser University – author’s
university in Vancouver Canada.
Two other projects also appear in this reference 6. The specific goals in this
chapter are:
• To provide an in-depth practical discussion of DC motor speed response, position
response, and position control concepts.
• To provide examples of how to identify the parameters of a physical system,
experimentally.
• To give a better feel for controller design through realistic examples.

Before starting the lab, you must have completed the relevant background preparation 7.

1
LEGO is a registered trademark of the LEGO group; this applies to all references hereafter in this document
2
MINDSTORMS is a registered trademark of the LEGO group; this applies to all references hereafter in this
document
3
EV3 is a registered trademark of the LEGO group; this applies to all references hereafter in this document
4
MATLAB is a registered trademark of MathWorks; this applies to all references hereafter in this document
5
Simulink is a registered trademark of MathWorks; this applies to all references hereafter in this document
6
F. Golnaraghi and B. Kuo [3]
7
F. Golnaraghi and B. Kuo [3]

9
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

____________________________________
1 INTRODUCING LEGO®
MINDSTORMS® EV3® MOTOR:
CHARACTERIZATION
This section provides a simple yet practical project for you to appreciate better the
theoretical concepts that have been discussed so far. The primary objective of this project
is to provide you with a series of experiments for measuring a DC motor's electrical and
mechanical characteristics, and ultimately, to create a mathematical model for the motor.
The goal of this project is further to build a one degree-of-freedom robot using the LEGO®
MINDSTORMS® EV3® motor, with the setup, shown in Figure 1 and Figure 2, and to
develop a position control system for the robot using MATLAB® & Simulink®. The LEGO
MINDSTORMS and MATLAB & Simulink would allow you to study control systems
without the need for highly equipped and expensive laboratories. Most importantly, you
can learn the subject while having fun! If you do not have access to the LEGO
MINDSTORMS, you can still follow the example provided to gain a practical
understanding of the subject.

Required components include an EV3 brick, an EV3 motor, an Edimac EW-


The first
objective of this 7811Un USB WiFi adapter and several LEGO pieces found in the basic LEGO
project is to help MINDSTORMS kit, which are used to construct a one degree-of-freedom arm. Also
you better required is an installed copy of MATLAB & Simulink 2014 or newer (version 2017B
understand how
to measure a DC
was used here), which is used to provide communication between the host computer
motor's and the EV3 device via a WiFi connection. Also, a copy of LEGO Mindstorms EV3
electrical and Home Edition Software 8 will need to be installed to change the firmware of the EV3
mechanical
characteristics
Brick. All the necessary components are illustrated in Figure 1 and Figure 2. The
and ultimately arm is to pick up a payload and drop it into the cup, which is located at a specified
create a model angle while data is sampled in Simulink. Programming is done on the host computer
for the motor. using Simulink and is uploaded on to the EV3 brick via WiFi connection. The brick
then provides both power and control to the arm via the EV3 cables. Additionally,
there is an optical encoder located behind the motor which measures the rotational
position of the output shaft with 1° resolution. The host computer samples encoder
data from the EV3 brick via a WiFi connection. The WiFi connection should be setup such

8
Download the Home edition software from: https://www.lego.com/en-us/mindstorms/downloads/download-
software

10
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
that the EV3 Brick and the host computer are connected to the same network. Furthermore,
the firmware that is on the EV3 brick only supports a certain WiFi adapter which proves
to be relatively big and inconvenient. Therefore, we choose an adapter which integrates
seamlessly with the EV3 Brick. However, a custom firmware needs to be installed for the
EV3 Brick to communicate with the Edimax EW-7811Un. To install this firmware, you
must first download it via the link provided in this footnote 9. After the download
completes open the Lego Mindstorms EV3 Home Edition software. Click on ‘Tools ->
Firmware Update’. You will have the option to browse for the firmware you want to install.
Select browse and find the firmware you just downloaded. Now, turn on the EV3 brick and
connect it to the host computer via USB. After the EV3 software has detected the EV3
brick, click download, and the firmware will be installed.

Counterweight Start Position (𝟎𝟎°) Gripper


End Position (𝟏𝟏𝟏𝟏𝟏𝟏°)

Payload

WiFi Dongle

Gripper Servo
RJ12 Cables

EV3 Brick DC Motor

Robot stand and


LEGO pieces
Figure 1. Position Control Robot Arm Setup

9
Edimax EV3 firmware download from: http://tinyurl.com/ev3edimax

11
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 2. Computer (left) connected to WiFi router (right)

To develop position control in the system shown above, it is necessary first to


characterize and model the motor 10.

1.1 Interfacing with Simulink®

Interfacing between the EV3 11 motor and the host computer is of importance
because the user should be able to both control the motor as well as sample positional
data from the motor encoder or any other sensors connected to the EV3 brick (2-way
connection required to send and receive data). Interfacing will be performed using
MATLAB & Simulink via a WiFi connection.

Simulink 12 is an environment used for a multi-domain simulation where the user


can create models for dynamic and embedded systems. It includes a customizable set of
graphical block libraries, which the user can drag and drop to design and simulate a variety
of time-varying systems. In this Chapter, we are particularly interested in utilizing
Simulink to simulate the model of the EV3 motor and implementing a position control
system. We also use Simulink to run the EV3 motor experiments.

10
It is important to note that the measured values provided here, will vary from motor to motor, and for better
accuracy, you are advised to conduct your own experiments to determine your system’s parameter values
11
Lego Mindstorms EV3 is the newer model of LEGO Mindstorms NXT
12
For a more in-depth introduction to Simulink please refer to https://www.mathworks.com/, for example:
https://www.mathworks.com/products/simulink/getting-started.html
https://www.mathworks.com/examples/simulink

12
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
To start the Simulink software, enter "simulink" in the MATLAB command window
or click on the Simulink icon on the MATLAB toolbar, as shown in Figure 3.

Figure 3. Simulink® icon in MATLAB® toolbar

This will take you to the Simulink Start Page, as seen in Figure 4.

Figure 4. Simulink® start page

Click on ‘Blank Model.’ An example of an empty Simulink model is shown in


Figure 5.

13
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 5. Blank Simulink® model

To add blocks to the model, click the Library Browser icon in the top left, as seen
in Figure 6.

Figure 6. Library Browser icon in Simulink®

The Library browser window is seen in Figure 7.

14
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 7. Library Browser window

These blocks can be dragged and dropped into a Simulink model to design
The Simulink your very own system. Common Simulink blocks used along with their functions
model is are shown in Table 1. Utilizing the blocks shown in Table 1, one can create a
essentially the
same as a block Simulink model for a DC motor – a position control example is illustrated in Figure
diagram of a 8 (more examples appear later in the section). This model can be used to simulate
control system. the behavior of a specific motor for known motor parameters. Every block can be
Note: the motor customized by double clicking on them and setting the desired parameters. Note
model includes, that the two Saturation blocks were purposely added to simulate real life scenarios.
implicitly, the You may elect not to include them in your simulations.
gear-train model
as well.

15
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Table 1. Common Simulink® blocks and their functions

𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺 𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭


Inputs a constant signal

Multiplies the input by a constant

Limits the input to within a range of values, then


outputs it

Delays the input by a specified length of time

Outputs the sum of multiple signals, can also be


used as a comparator (to take the difference of
signals)

Outputs the product of multiple signals

Outputs the input signal to the MATLAB


Workspace

Displays the input signals graphically

Inputs a step (constant) signal

Inputs a ramp (linear) signal

Integrates the input signal then outputs it

Models a linear system by its transfer function

16
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Applies a PID controller to the input signal, the
result of which is the output signal

The logic block which compares the signal to a


constant then outputs a ‘1’ if the comparison is
true, and a ‘0’ if it is false.
Allows a Simulink model to be broken up into
functions. Each subsystem is usually a function
with at least one input, and at least one output.

Subsystem input block

Subsystem output block

Figure 8. Sample model for controlling a DC Motor

1.2 LEGO® EV3® MATLAB® and Simulink® Library Add-Ons

In addition to creating simulations, Simulink is also able to interface with


Instructional hardware in real time. In particular, it can interface with the EV3 brick via the
Video available
LEGO MINDSTORMS EV3 Simulink Library. The LEGO EV3 Simulink library
has been specifically developed to interface with the EV3 brick through MATLAB
& Simulink. Again, you will require MATLAB & Simulink 2014 or newer to
install the library. The attached links 13 will help you with the interfacing
details.

To begin installation, select Add-Ons -> Get Hardware Support Packages,


shown in Figure 9, which will take you to the Add-On Explorer, shown in Figure
10. Select the LEGO EV3 MATLAB and Simulink libraries for installation and

13
See author’s introductory videos at: http://www.mechworkssys.com/FaridGolnaraghi/textbooks/

17
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
follow further on-screen instructions to finish installing the add-on. After the library has
been successfully installed, the new library will appear in the Simulink Library Browser
menu. The library blocks are shown in Figure 11. In particular, we are most interested in
the motor and encoder blocks shown in Table 2.

Figure 9. Simulink® Hardware Support Packages

Figure 10. Add-On Explorer with MATLAB® (top-right) and Simulink® (bottom-left) support packages

18
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 11. EV3® Support Package blocks

Table 2. Important Simulink® EV3® blocks – motor and encoder

𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺 𝑬𝑬𝑬𝑬𝑬𝑬 𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭𝑭


Outputs the (incremental) angular displacement
in degrees; specify which port the motor is
connected to

Takes as an input a power percentage to apply to


the motor, from -100 to 100. Specify which port
the motor is connected to

The EV3 Simulink library will be used throughout this section to determine the
mechanical and electrical characteristics of the EV3 motor.

19
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

1.3 Interfacing with WiFi

The attached links will help you with the interfacing details 14. Turn on
Instructional the router. Hold down the router’s reset button for 10-20 seconds. Connect the
Video available Router (which must support WPA2 encryption) to the computer’s Ethernet port but
do not connect it to a Modem (have one closed network, no internet connection).
This will open a setup screen on your web browser. Select ‘Manual Setting.’ Follow
the remaining prompts on-screen to setup the router and its username and password
credentials. You will then be able to set the network credentials – the SSID and
encryption key. Ensure that the security is ‘WPA2’. Assuming you have
downloaded the Edimax firmware, insert the WiFi adapter into the USB port. The
EV3 home screen after successful WiFi connection is shown below in Figure 12.

Figure 12. EV3® Brick after successful WiFi connection. 'Settings' tab is displayed. The working WiFi
connection is represented by the WiFi symbol with the double arrow in the top-left corner.

On the EV3 home screen, go to ‘Settings -> WiFi,’ and turn WiFi on. Then select
‘Connections,’ and select the network you want to connect to. Select ‘Connect’ and
encryption type ‘WPA2’. Enter the password for the network and select the checkmark.
Return to the blank Home screen. On the Simulink side, set the Mode to ‘External,’ as seen
in Figure 13.

14
See author’s video at: http://www.mechworkssys.com/FaridGolnaraghi/textbooks/

20
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 13. Set the model's mode to 'External.'

Then go to Tools -> Run on Target Hardware -> Options/Prepare to Run. Finally,
ensure that the ‘Configuration Parameters’ window matches what is shown below in Figure
14, Figure 15, and Figure 16, with the ‘Device ID’ and ‘IP Address’ matching what is
shown on the EV3 screen under ‘Settings -> Brick Info’:

Figure 14. 'Configuration Parameters' window, with 'Build options' set to 'Build, load, and run.'

21
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 15. 'Connection Type' is 'WiFi'. Enter 'Device ID' and 'IP address' as found on the Brick screen

Figure 16. 'External mode' has the 'TCP/IP' communication interface, and IP address is repeated here

Note that the easiest way to run Simulink on the EV3 is to ensure that the LEGO
software is not running and that all MATLAB EV3 objects are cleared. Before running
Simulink, we tested the connection by running MATLAB code where we created the EV3
and its motors as objects. After confirming the connection, we cleared the objects. This
code is shown below.

%testing EV3-Simulink connection through WiFi

ev3 = legoev3('wifi','192.168.1.210','00165344c8ff');
%declare EV3 object with: WiFi connection, IP address, Device ID

motor = motor(ev3,'A');
%declare motor object as being motor connected to 'ev3' on port 'A'

motor.Speed = 50;
%set motor speed

%run the motor briefly; 10 iterations = 1 second here


for i=1:1:10
start(motor)
end

stop(motor) %stop the motor


clear all
%clear all objects, since EV3 objects can only be declared once
%if motor runs then the connection is successful

22
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

1.4 EV3® Motor

The gear ratio


The EV3 motor used in this project is a 9V DC motor specific to the LEGO
and its model MINDSTORMS EV3 set. As shown below in Figure 17, the motor contains a gear-
may be absorbed train from the motor to the output shaft to provide greater torque. The idealized
into the motor schematic of this motor was shown earlier in this reference 15.
model. Note: all
parameters
obtained
hereafter will be Motor shaft gear, 𝑮𝑮𝒎𝒎 H-bridge and circuitry;
for the motor- connects to RJ-12 cable
gear-train Output shaft gear, 𝑮𝑮𝒐𝒐𝒐𝒐𝒐𝒐
combination.

𝑮𝑮𝟑𝟑
𝑮𝑮𝟓𝟓

𝑮𝑮𝟏𝟏

𝑮𝑮𝟐𝟐 Encoder shaft gear, 𝑮𝑮𝒆𝒆

𝑮𝑮𝟒𝟒

Figure 17. Motor, gear-train, and circuitry

The overall gear ratio calculation from the motor to output shaft uses Equation 1,
and the gear-train teeth values are shown below in Table 3.

𝑁𝑁𝑖𝑖𝑖𝑖
𝐺𝐺𝑥𝑥 = (1)
𝑁𝑁𝑜𝑜(𝑥𝑥−1)

Table 3. Gear Ratio Calculations

𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮 𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰 𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 #, 𝑵𝑵𝒊𝒊𝒊𝒊 𝑶𝑶𝑶𝑶𝑶𝑶𝑶𝑶𝑶𝑶𝑶𝑶 𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 #, 𝑵𝑵𝒐𝒐𝒐𝒐 𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮 𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹, 𝑮𝑮𝒙𝒙
Motor 10 10 1
1 30 30 3
2 32 10 1.067
3 33 10 3.3
4 25 11 2.5
5 13 13 1.182

15
F. Golnaraghi and B. Kuo [3]

23
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Output 20 20 1.538
Final Gear Ratio 48.0

Because the encoder measures the rotational position of the output shaft, and not
that of the motor shaft, the gear ratio and its model may be absorbed into the motor model
– see this reference 16 for details. As a result, from this point forward, any reference to the
motor implicitly refers to the motor-gear-train system. Further, all parameters obtained will
be for the motor-gear-train combination.

To fully model the motor, both the electrical and mechanical characteristics of the
motor are obtained experimentally. As mentioned earlier, an installed copy of MATLAB
& Simulink 2014 or newer is required to carry out the experiments. MATLAB & Simulink
2014 contains a new library that has been developed to interface with LEGO hardware.

1.5 Precursor to Experiments


1.5.1 DC Motor Parameters 17

Recall the model of a DC Motor. The control system parameters of a DC Motor are
resistance of armature, 𝑅𝑅𝑎𝑎 ; inductance of armature, 𝐿𝐿𝑎𝑎 ; torque-current constant, 𝐾𝐾𝑖𝑖 ; back-
emf constant, 𝐾𝐾𝑏𝑏 ; viscous frictionthe coefficient, 𝐵𝐵𝑚𝑚 ; mechanical time constant, 𝜏𝜏𝑚𝑚 ; and
moment of inertia, 𝐽𝐽𝑚𝑚 .

The primary electrical equations are:

𝑑𝑑𝑖𝑖𝑎𝑎
−𝑉𝑉𝑎𝑎 + 𝑅𝑅𝑎𝑎 ∗ 𝑖𝑖𝑎𝑎 + 𝐿𝐿𝑎𝑎 ∗ + 𝑒𝑒𝑏𝑏 = 0 (2)
𝑑𝑑𝑑𝑑

𝑉𝑉𝑎𝑎 = 0.5 ∗ (𝑉𝑉𝑤𝑤 − 𝑉𝑉𝑏𝑏 ) (3)

𝑒𝑒𝑏𝑏 = 𝐾𝐾𝑏𝑏 ∗ 𝜔𝜔 (4)

𝑇𝑇𝑚𝑚 = 𝐾𝐾𝑖𝑖 ∗ 𝑖𝑖𝑎𝑎 (5)

16
F. Golnaraghi and B. Kuo [3]
17
The information in Section 1.5.1 is from F. Golnaraghi and B. Kuo [3]

24
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

𝐿𝐿𝑎𝑎
𝜏𝜏𝑒𝑒 = (6)
𝑅𝑅𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡

The primary mechanical equations are:

𝐽𝐽𝑚𝑚 ∗ 𝛼𝛼 + 𝐵𝐵𝑚𝑚 ∗ 𝜔𝜔 + 𝑇𝑇𝑊𝑊 = 𝑇𝑇𝑚𝑚 (7)

𝐾𝐾𝑖𝑖 ∗ 𝐾𝐾𝑏𝑏
𝐽𝐽𝑚𝑚 = 𝜏𝜏𝑚𝑚 ∗ �𝐵𝐵𝑚𝑚 + � (8)
𝑅𝑅𝑎𝑎

The primary power equations are:

𝑃𝑃𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 𝑡𝑡𝑡𝑡 𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 = 𝑉𝑉𝑎𝑎 ∗ 𝑖𝑖𝑎𝑎 (9)

𝑃𝑃𝑢𝑢𝑢𝑢𝑢𝑢𝑢𝑢 𝑏𝑏𝑏𝑏 𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 = 𝑇𝑇𝑚𝑚 ∗ 𝜔𝜔 ≈ 𝑒𝑒𝑏𝑏 ∗ 𝑖𝑖𝑎𝑎 (10)

Where 𝑉𝑉𝑎𝑎 is armature voltage, 𝑉𝑉𝑤𝑤 is the voltage of the white wire, 𝑉𝑉𝑏𝑏 is the voltage
of the black wire, 𝑇𝑇𝑚𝑚 is the torque of the motor, 𝜏𝜏𝑒𝑒 is the electrical time constant, 𝛼𝛼 is the
angular acceleration of the motor, 𝜔𝜔 is the angular velocity of the motor, and 𝑇𝑇𝑊𝑊 is the
torque exerted on the motor by the payload it carries. To find all parameters, 9 different
experiments are conducted here: 1 for 𝑅𝑅𝑎𝑎 , 1 for 𝐿𝐿𝑎𝑎 , 1 for 𝐾𝐾𝑖𝑖 , 1 for 𝐾𝐾𝑏𝑏 and 𝐵𝐵𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 , 1 for
𝐵𝐵𝑎𝑎𝑎𝑎𝑎𝑎 , 1 for 𝐽𝐽𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 , 1 for 𝜏𝜏𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 , 1 for 𝐽𝐽𝑎𝑎𝑎𝑎𝑎𝑎 , and 1 for 𝜏𝜏𝑎𝑎𝑎𝑎𝑎𝑎 . The mechanical parameters are
expected to be different for the motor-only versus the motor-arm combination. Thus, these
parameters are found for each case separately. For the most accurate results, each
experiment should be conducted in 3 separate instances, with 6 trials per instance, a
different input power level for each trial, and at a similar battery level for each trial (as
battery level affects voltage supplied).

25
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

1.5.2 Linear Regression

For some of the datasets, we must take the average, in which case we use MATLAB
to find the standard deviation of the vector of data entries as shown below.

L = [4.44
4.46
4.18
4.13
4.16
4.33]; %vector of data entries

format long %display variables with 15 decimal


% places when typed in the command window

L_avg = mean(L); %find average of the data

L_Sdev = std(L); %find standard deviation of the data

However, most of the experiments consist of obtaining and plotting two sets of data
points and finding the best-fit linear relation between the sets. MATLAB has a linear curve-
fitting app that can be used. Take as an example the armature resistance experiment, which
compares stall voltages, 𝑉𝑉, to stall currents, 𝐼𝐼. The app can find the best-fit relation of: 𝑉𝑉 =
𝑚𝑚𝑚𝑚 + 𝑏𝑏, where 𝑚𝑚 is the best-fit resistance. The procedure is to create and run a program
with each dataset created as an ordered vector (in this case, 𝑉𝑉 �⃗ and 𝐼𝐼⃗). Note that the 𝑛𝑛𝑛𝑛ℎ
entry of 𝑉𝑉�⃗ and the 𝑛𝑛𝑛𝑛ℎ entry of 𝐼𝐼⃗ must correspond to 𝑉𝑉 and 𝐼𝐼 measurements taken in the
same trial. After the program is run, select ‘Apps -> Curve Fitting’. A sample program is
shown below in Figure 18.

26
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 18. We enter the datasets with the nth entries matching, then run the curve-fitting app

Then, select 𝑉𝑉 as the Y-data and 𝐼𝐼 as the X-data. The curve fit can be named and
saved. The best-fit curve will be produced as in Figure 19.

27
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 19. The linear best-fit of V vs. I data; the slope is R.

The slope of the graph is the value on the left-hand side denoted ‘p1’. Shown below
it is the accuracy of the fit, known as ‘R-square,’ which has a maximum accuracy value of
1. As is seen from the R-square value of 0.9998 above, this data has a very good linear fit.

1.5.3 Our Standard Simulink® Model

The standard Simulink model for all experiments, unless specified otherwise, is
shown below in Figure 20.

28
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 20. The standard Simulink® model. Power is applied to the motor, and the encoder output is
converted to radians by a gain block, then output

A constant power level is an input to the motor, and the encoder readings, after being
converted from degrees to radians, is output to the MATLAB workspace. The output save
format is “structure with time,” so that a timestamp accompanies every reading, as seen
below in Figure 21. The encoder’s “Block Parameters” window is shown in Figure 22.

Figure 21. ‘To Workspace’ block parameters window. The output is saved into MATLAB® workspace as
a structure with accessible time and signal value properties.

29
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 22. "Block Parameters" window for the motor Encoder.

1.5.4 Obtaining Angular Parameters

Several experiments will require obtaining angular velocity (𝜔𝜔) or acceleration (𝛼𝛼)
values. To find these parameters, we must read the angular displacement in radians (𝜃𝜃)
from the encoder, output it to the workspace, and differentiate it twice with respect to time.
Note that the output velocity and acceleration data will be very noisy. To rectify this, we
took a moving average algorithm, which decreases the number of samples, but smoothens
the data. The code, including the algorithm, is broken up into 5 parts (including comments
in green), as seen below. Note that you must set the “numsamples” variable to be equal
to the number of samples taken by the encoder over the duration of the trial.

% 1: Declarations

omegaoddwindowsize=13; %the larger the value, the smoother the output,


alphaoddwindowsize=95; % but also less nonzero samples

omegawindowboundary = floor(omegaoddwindowsize/2);
alphawindowboundary = floor(alphaoddwindowsize/2);

omegasteadystate = 0; %declare omegasteadystate


numsamples=-1; %set this number to match the # of timestamps
steadystatestart=1; %set this to be the first sample of steady omega
steadystateend=2; %set this to be the last sample of steady omega

hold on

30
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
%posn_out is encoder output from real motor position response
%posn_sim is simulated motor position response
%output is encoder output from real motor speed response
%speed_sim is simulated motor speed response

%position responses

%velocity responses
realtheta_vel = double(output.signals.values);
realtime_vel = double(output.time);

% 2: Obtain raw/rough omega and alpha values

%discrete differentiation of theta to get roughomega, 1 sample less


for i=1:1:(numsamples-1)
smoothomega(i)=0;
smoothalpha(i)=0;
roughomega(i) = (realtheta_vel(i+1)-
realtheta_vel(i))/(realtime_vel(i+1)-realtime_vel(i));
timeofroughomega(i) = realtime_vel(i);
end

%discrete differentiation of roughomega to get roughalpha, 1 sample


less
for i=1:1:(numsamples-2)
roughalpha(i) = (roughomega(i+1)-roughomega(i))/(realtime_vel(i+1)-
realtime_vel(i));
end

% 3: Obtain smoothened omega and alpha values


% by applying a moving average algorithm with windowsizes from (1)

%moving average algorithm to get a smoothened omega from the rough


omega
for i=(omegawindowboundary+1):1:(numsamples-1-omegawindowboundary)
for j=(i-omegawindowboundary):1:(i+omegawindowboundary)
smoothomega(i) =
smoothomega(i)+roughomega(j)/omegaoddwindowsize;
end
end

%moving average algorithm to get a smoother alpha from the rough alpha
for i=(alphawindowboundary+2):1:(numsamples-2-alphawindowboundary)
for j=(i-alphawindowboundary):1:(i+alphawindowboundary)
smoothalpha(i) =
smoothalpha(i)+roughalpha(j)/alphaoddwindowsize;
end
end

% 4: Find average omega during steady-state

for i=steadystatestart:1:steadystateend
omegasteadystate =
omegasteadystate+(smoothomega(i))/(steadystateend-steadystatestart+1);
end

% 5: Show the results

31
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

%position responses

%velocity responses
plot(timeofroughomega,roughomega,'-','color','blue')

Shown in Figure 23 is a simultaneous plot of the angular displacement, velocity,


and acceleration graphs as functions of time.

Figure 23. Angular parameters as a function of time

Here, 𝜔𝜔 is the red graph. As can be seen above, 𝜔𝜔(𝑡𝑡) requires some time to reach
full-speed, and then maintains this constant value, called the “steady-state”. The 𝜃𝜃, 𝜔𝜔, 𝛼𝛼,
and ‘timestep’ (timestamp) vectors can be seen in the workspace by double-clicking them.
Note that there is an equation used to find steady-state speed 18.

1.5.5 Transport Delay

𝑡𝑡
𝐴𝐴𝐾𝐾𝑖𝑖
18
𝜔𝜔𝑚𝑚 (𝑡𝑡) = ∗ (1 − 𝑒𝑒 −𝜏𝜏 ), F. Golnaraghi and B. Kuo [3]
𝐾𝐾𝑖𝑖 𝐾𝐾𝑏𝑏 +𝑅𝑅𝑎𝑎 𝐵𝐵

32
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
In the previous run, we had instructed the encoder to read the angular displacement
once every 0.1 seconds for the duration of the trial, 4.0 seconds. Including the sample at
𝑡𝑡 = 0, there are 41 samples taken. It is important to note that if too small of a sample time
is chosen, for example 0.001 seconds, then the encoder would not sample at every interval,
but instead, at random ones. Then, the first encoder sample would be taken anywhere from
between 0 and 1 seconds. To overcome this problem, the (nonzero) input power to the
motor would need to be delayed at the beginning by 1 second. To do this, the ‘Transport
Delay’ block would need to be added, as seen below in Figure 24 and Figure 25, and all
measurements would need to be taken from 1 second onwards.

Figure 24. The 'Transport Delay' block delays the input signal

Figure 25. The transport delay's "Block Parameters" window, where the time delay is specified

33
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
However, with sample times smaller than 0.1 seconds, it was observed that there
was a large amount of noise in the velocity data, even when using a moving average
algorithm to smooth the data. Therefore, sticking with a sample time of 0.1 seconds is
recommended for all experiments, except for the ones used to find 𝐽𝐽 and 𝜏𝜏, where this
section applies.

1.5.6 Finding Steady-State 𝝎𝝎

As seen in the workspace tables and the plot of angular parameters, omega at steady-
state is not one single value. Rather, it fluctuates slightly. The approach used here is to take
the average value at steady-state.

1.5.7 The Cable 19

The EV3 motor is controlled by the EV3 Brick using an RJ12 cable. Each cable has
six wires that connect to an H-Bridge controlling the motor, allowing for bidirectional
rotation. The bridge needs four wires: a 4.5V supply for logic, two motor power wires
(white and black), and ground. When the voltage is greater in the white wire than the black
wire, the motor spins in one direction; when the greater voltage is in the black wire, the
motor spins in the other direction. The encoder also has two wires, since it is an optical
quadrature encoder. The encoder consists of a beam of light and two circular plates with
360 slots (1 slot per degree). With every new degree of angular displacement reached, light
passes through a slot and is sensed for a short time. Each encoder wire carries a digital step
signal, with a nonzero value when the presence of light is sensed, and equal to zero
elsewhere. Either signal can represent the angular displacement of the motor. However the
direction of this displacement is found by comparing which signal rises first in each period.

To measure the parameters of this motor, we had to cut the cable and perform
measurements using a multimeter. This step will damage the cable, and you may wish to
do this on a demo unit or with your instructor’s permission – or simply rely on the
resulting values obtained in this section. It is important to highlight that every unit is
slightly different due to manufacturing imperfections. So in the very end, you will have
to fine tune the motor parameters using the speed and position time responses – as we have
done at the end of this section. If you decide to cut the cable, cut it in half and remove a
good section of the black plastic covering on each side. Then strip about ½ to 1 inch of the
insulating plastic off the exposed leads of all 12 wires (since all six wires were split in half).
For these measurements, only the red and black wires are needed. The rest can be either
spliced or soldered together and covered with electrical tape (as done in this case). In this
case, each white wire had all its threads soldered together, the two black wires were

19
The information in Section 1.5.7 is from A. Marzouk [2]

34
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
soldered together, with a section exposed for voltage measurement. See Figure 26, Figure
27, Figure 28, and Figure 29 below.

Figure 26. Front view of the RJ12 cable

Figure 27. Rear view of the RJ12 cable

White Wire: Motor Power 1


Black Wire: Motor Power 2

Red Wire: Ground

Green Wire: Logic +4.5 V

Yellow Wire: Encoder Signal 1

Blue Wire: Encoder Signal 2

Figure 28. The six wires of the RJ12 cable and their functions

35
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

RJ12 Cable

Plastic covering

Insulating plastic

Wire Threads

Figure 29. The different parts of the RJ12 cable

1.5.8 Important: About Soldering Safety

For ease of measurement, the author soldered several wires and parts of wires
together. However, it is important to note that when soldering, one must know what they
are doing, and follow the strictest safety practices. If one is not completely assured of
their safety while soldering, then they should not attempt it, and should simply splice
the wires instead.

1.5.9 Measuring Armature Voltage, 𝑽𝑽𝒂𝒂

The motor voltage can be measured by using a multimeter on the DC voltage setting.
Ensure that the two white wires are connected and that the two black wires are connected.
Keep the red, positive meter lead in contact with the exposed section of the white wire, and
do the same with the black, negative lead and the exposed section of the black wire. The
multimeter is in parallel with the motor. Thus, we measure (𝑉𝑉𝑤𝑤ℎ𝑖𝑖𝑖𝑖𝑖𝑖 − 𝑉𝑉𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏 ). The setup is
shown in Figure 30 and Figure 31.

36
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 30. Measuring Armature Voltage while the motor is running

37
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 31. A close up of the voltage measurement

1.5.10 Measuring Armature Current, 𝒊𝒊𝒂𝒂

The motor current can be measured by using a multimeter on the DC current setting.
Ensure that the two black wires are connected. Ensure also that the two white wires are
connected, not directly, but through the multimeter. Each wire is wrapped around the
corresponding lead. One white wire will contact the red meter lead; the other white wire
will contact the black lead. The multimeter is in series with the motor. The setup is shown
in Figure 32 and Figure 33.

38
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 32. Measuring Armature Current while the motor is running

Figure 33. A close-up of the current measurement

39
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

____________________________________
2 PROJECT 1: OBTAINING DC
MOTOR CONTROL PARAMETERS
2.1 Electrical Characteristics

2.1.1 Armature Resistance

The motor input power is varied from -100% to +100% in increments of 10%. For
each trial, the motor is stalled by hand or by a LEGO piece, and first 𝑖𝑖𝑎𝑎 is measured as
described in ‘measuring current’, then (𝑉𝑉𝑤𝑤ℎ𝑖𝑖𝑖𝑖𝑖𝑖 − 𝑉𝑉𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏 ) is measured as described in
‘measuring voltage’. 𝑉𝑉𝑎𝑎 is half this value to approximate voltage division between the
motor and the encoder. Note that since the motor is stalled, 𝑒𝑒𝑏𝑏 = 0, and note that the
inductance is small, therefore its effects are negligible in Equation 2, which becomes:

𝑉𝑉𝑎𝑎
𝑅𝑅𝑎𝑎 = (2 − 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 1)
𝑖𝑖𝑎𝑎

The 𝑉𝑉 − 𝐼𝐼 graph which was shown under ‘Linear Regression’, is shown again in
Figure 34. The table of results, with the best-fit 𝑅𝑅𝑎𝑎 value cathe lculated as in ‘Linear
Regression’, is also shown below in Table 4:

Table 4. Armature Resistance Results

𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 (%) 𝑽𝑽𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘 − 𝑽𝑽𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 (𝑽𝑽) 𝑽𝑽𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂,𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔 (𝑽𝑽) 𝒊𝒊𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂,𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔 (𝑨𝑨)
-100 -3.26 -1.63 -0.75
-90 -3.17 -1.59 -0.73
-80 -3.15 -1.58 -0.72
-70 -3.03 -1.52 -0.72
-60 -2.85 -1.43 -0.68
-50 -2.51 -1.26 -0.59
-40 -2.07 -1.04 -0.49
-30 -1.64 -0.82 -0.39
-20 -1.23 -0.62 -0.29
-10 -0.82 -0.41 -0.19
10 0.85 0.43 0.19

40
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
20 1.22 0.61 0.28
30 1.65 0.83 0.38
40 2.07 1.04 0.48
50 2.49 1.25 0.58
60 2.82 1.41 0.67
70 3.02 1.51 0.71
80 3.06 1.53 0.71
90 3.08 1.54 0.72
100 3.14 1.57 0.73
𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 − 𝒇𝒇𝒇𝒇𝒇𝒇 𝑹𝑹𝒂𝒂 = 𝟐𝟐. 𝟏𝟏𝟏𝟏𝟏𝟏 𝛀𝛀 𝑹𝑹𝟐𝟐 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

Figure 34. Armature Voltage vs Current

Thus, we have 𝑹𝑹𝒂𝒂 = 𝟐𝟐. 𝟏𝟏𝟏𝟏𝟏𝟏 𝛀𝛀 .

2.1.2 Armature Inductance

There are some ways to measure motor inductance. One way commonly practiced
in most undergraduate control labs is to connect a known resistor 𝑅𝑅 (select a value close to
𝑅𝑅𝑎𝑎 ) in series with the motor, stall the motor as in the previous section, provide the system
a constant input voltage 𝑉𝑉, turn off the input (with the motor still stalled) and measure the
𝐿𝐿
electric time constant ( 𝑎𝑎 ) . An oscilloscope (or voltmeter, timer, and camera for video)
𝑅𝑅+𝑅𝑅𝑎𝑎

41
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

can be used to measure the voltage across 𝑅𝑅, 𝑉𝑉𝑅𝑅 , as a function of time after the input is
turned off, and the function will be:

−𝐿𝐿𝑎𝑎
∗𝑡𝑡
𝑉𝑉𝑅𝑅 (𝑡𝑡) = 𝑉𝑉𝑅𝑅𝑅𝑅𝑅𝑅𝑅𝑅 ∗ 𝑒𝑒 𝑅𝑅+𝑅𝑅𝑎𝑎 (11)

Knowing the time constant and resistance values, you can calculate 𝐿𝐿𝑎𝑎 . We took
the easy way out by using a multimeter that is able to measure inductance. Simply connect
the multimeter to the motor terminals, and set the multimeter to measure inductance, as
shown below in Figure 35. Note that initially the inductance reading fluctuates, so we
waited to take the reading until the reading settled on a single value for more than 5
seconds. The results are shown below in Table 5.

Figure 35. Measuring Inductance

Table 5. Armature Inductance Results

𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 # 𝑳𝑳𝒂𝒂 (𝒎𝒎𝒎𝒎)


1 4.44
2 4.46
3 4.18
4 4.13

42
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
5 4.16
6 4.33
Average Inductance = 4.283 mH
Standard Deviation = 0.147 mH

The experimentally measured armature inductance of the motor was found to be


𝑳𝑳𝒂𝒂 = 𝟒𝟒. 𝟐𝟐𝟐𝟐𝟐𝟐 𝒎𝒎𝒎𝒎 .

2.1.3 Current-Torque Constant

The motor’s current-torque constant is obtained from Equation 5: 𝑇𝑇𝑚𝑚 = 𝐾𝐾𝑖𝑖 ∗ 𝑖𝑖𝑎𝑎 .
Determining the torque constant experimentally requires you to measure both the current
supplied to the motor and the torque provided by the motor.

Recall that Equation 7 is: 𝐽𝐽𝑚𝑚 ∗ 𝛼𝛼 + 𝐵𝐵𝑚𝑚 ∗ 𝜔𝜔 + 𝑇𝑇𝑊𝑊 = 𝑇𝑇𝑚𝑚 .


Thus, if the correct mass is chosen to stall the motor such that a trial’s steady-state values
are 𝛼𝛼𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠−𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 0 and 𝜔𝜔𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠−𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 0, then 𝑇𝑇𝑊𝑊 = 𝐾𝐾𝑖𝑖 ∗ 𝑖𝑖𝑎𝑎 , and 𝐾𝐾𝑖𝑖 is found as the
slope of the 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝑣𝑣𝑣𝑣 𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶 curve, where the motor is stalled at a different input
power level for each trial. It should be noted that 𝐾𝐾𝑖𝑖 is independent of the input voltage
value.

To apply a payload torque to the motor, connect a spool to the motor, and tie a
payload around the spool. The payload torque is then the payload mass (found using a
scale) multiplied by the gravitational field constant multiplied by the spool radius, or:
𝑇𝑇𝑊𝑊 = 𝑚𝑚𝑃𝑃 ∗ 𝑔𝑔 ∗ 𝑅𝑅𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 .

Thus we have:

𝑚𝑚𝑃𝑃 ∗ 𝑔𝑔 ∗ 𝑅𝑅𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 𝐾𝐾𝑖𝑖 ∗ 𝑖𝑖𝑎𝑎 (7 − 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 1)

The setup for this experiment is shown in Figure 36, Figure 37, and Figure 38 below.

43
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 36. Measuring current while the motor generates torque on a payload

44
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 37. The spool pulls up the fishing line-clasp-pencil weight variable-payload configuration. The
larger tire in the background is used as a counterweight to decrease the downward bending of the spool
axle.

Figure 38. Measuring payload masses with a scale

45
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

2.1.3.1 Tips for the 𝑲𝑲𝒊𝒊 measurements

To ensure the accuracy of this experiment, the following tips are helpful:

- Current and Voltage measurements can vary from their true values due to random
fluctuations of temperature, battery life, etc.
- Therefore, conduct each instance of the experiment in one sitting. Do not include
new trials as part of a previous experiment.
- Motors will take as much torque as they need, even if they cannot handle the
current for long. This also means that there will be a weight range that causes the
motor to stall. Thus, the correct choice of payload to cause stall will be the lightest
payload that does so.
- Take the maximum stall current reading, which usually occurs near the start of the
trial, as motor stalling increases motor temperature, which changes the current
reading.
- Use fishing line rated for at least twice your maximum payload weight. In this
case, the maximum payload was around 2lb, so 4lb line was required. The 20lb line
was used.
- Use the wheel with the tire as the spool. The friction between the tire and line is so
great that there will be no slippage of the line on the spool during the trial, which
would cause motor current reading fluctuation.
- Start the trial with the object already suspended, and held in your hand, and let go
of the object just as the motor starts running, minimizing the ‘inrush current’ (larger
current than at its natural operation) that occurs when lifting the object off the
ground.
- For large payloads, use a counterweight across from the spool to decrease the
dipping and bending of the spool axle, which could damage the motor.
- Ensure that motor stall, and thus the trial duration, does not occur for too long
(i.e., more than 4 seconds) at a time, as it will burn out the coils.
- Ensure that neither the motor nor its stand gets pulled over the desk by the payload,
by holding down the motor and stand with one hand, when dealing with large
payloads.
- At 100% power, the stall current is around 730mA. Thus, always connect a
multimeter with at least a 1A fuse for current measurements.
- Use a fishing line clasp to allow for easy removal or addition of weights, and use
fishing line pencil weights as larger payloads for larger power inputs.
- Note that the uncertainty in the payload measurement is that of 1 weight, so when
small payloads are needed, you may want to use Lego pieces as payloads instead.
- To be sure that the motor is stalled, you may want to confirm that both 𝛼𝛼 and 𝜔𝜔
reach and stay at zero at some point during the trial.

The results, with best-fit 𝐾𝐾𝑖𝑖 value, are shown in Table 6 below.

46
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Table 6. Torque-Current Constant Results
𝑁𝑁
9.81
𝑔𝑔 = 𝑘𝑘𝑘𝑘 𝑅𝑅𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 0.028 𝑚𝑚 0.0283495 𝑘𝑘𝑘𝑘 = 1 𝑜𝑜𝑜𝑜
Power 𝝎𝝎 𝜶𝜶
Level # of Mass (rad/ 𝒓𝒓𝒓𝒓𝒓𝒓
(%) Weights (oz) Mass (kg) Torque (N*m) Current (A) sec) ( )
𝒔𝒔𝒔𝒔𝒄𝒄𝟐𝟐
100 25 23.6 0.66904820 0.183774160 0.725 0 0
90 23 21.6 0.61234920 0.168200078 0.716 0 0
80 22 20.7 0.58683465 0.161191742 0.689 0 0
70 21 19.8 0.56132010 0.154183405 0.684 0 0
60 20 18.8 0.53297060 0.146396364 0.627 0 0
50 18 17.0 0.48194150 0.132379691 0.608 0 0
40 14 13.3 0.37704835 0.103567641 0.508 0 0
30 10 9.6 0.27215520 0.074755590 0.371 0 0
20 7 6.8 0.19277660 0.052951876 0.277 0 0
10 4 3.9 0.11056305 0.030369459 0.178 0 0
-10 4 3.9 0.11056305 -0.030369459 -0.173 0 0
-20 8 7.7 0.21829115 -0.059960213 -0.274 0 0
-30 11 10.5 0.29766975 -0.081763927 -0.378 0 0
-40 14 13.3 0.37704835 -0.103567641 -0.467 0 0
-50 19 17.9 0.50745605 -0.139388028 -0.603 0 0
-60 22 20.7 0.58683465 -0.161191742 -0.67 0 0
-70 23 21.6 0.61234920 -0.168200078 -0.686 0 0
-80 24 22.6 0.64069870 -0.175987119 -0.701 0 0
-90 25 23.6 0.66904820 -0.183774160 -0.707 0 0
-100 26 24.5 0.69456275 -0.190782496 -0.719 0 0
𝑓𝑓𝑓𝑓𝑓𝑓 𝑎𝑎𝑎𝑎𝑎𝑎 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 𝐾𝐾𝑖𝑖 = 0.2370 Nm/A 2
𝑅𝑅 = 0.9951
𝒇𝒇𝒇𝒇𝒇𝒇 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷
≤ 𝟓𝟓𝟓𝟓% 𝑲𝑲𝒊𝒊 = 𝟎𝟎. 𝟐𝟐𝟐𝟐𝟐𝟐𝟐𝟐 𝑵𝑵𝑵𝑵/𝑨𝑨 𝑹𝑹𝟐𝟐 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

Note that the value of 𝐾𝐾𝑖𝑖 is chosen for trials where the absolute value of the input
power is less than or equal to 50%. To see why this was done, consider the graphs below
for all data points in Figure 39, and only the low-power data points in Figure 40.

47
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 39. Torque vs. Current at Stall, all data

Figure 40. Torque vs. Current at Stall, Low-power

48
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
It is clear that for high input powers, there is a slewing effect. That is, the current
ceases to be linear with the torque, because as previously stated the motor will take as much
torque as it needs. However, the motor cannot draw much more than a maximum allowable
current of about 670-730mA. Thus, for the relationship to be approximated as linear, only
the ten low-power data points were considered. This subset of the data also exhibited the
highest R-squared value.

Thus, 𝑲𝑲𝒊𝒊 = 𝟎𝟎. 𝟐𝟐𝟐𝟐𝟐𝟐𝟐𝟐 𝑵𝑵𝑵𝑵/𝑨𝑨 .

2.1.4 Velocity-Torque Graph and Maximum Motor Power

An important motor characteristic is its angular velocity-torque graph, from which


we can get the maximum-power operating state. Using the same procedure as that for 𝐾𝐾𝑖𝑖 ,
as well as Equation 5, at 100% power, we obtain the following dataset in Table 7, and
grapthe h in Figure 41.

Table 7. Velocity-Torque Results

𝑲𝑲𝒊𝒊 = 𝟎𝟎. 𝟐𝟐𝟐𝟐𝟐𝟐𝟐𝟐 𝑵𝑵𝑵𝑵/𝑨𝑨 𝑷𝑷 = 𝟏𝟏𝟏𝟏𝟏𝟏%


𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 𝒓𝒓𝒓𝒓𝒓𝒓
# 𝒐𝒐𝒐𝒐 𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘 𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪 (𝑨𝑨) (𝑵𝑵 ∗ 𝒎𝒎) 𝝎𝝎( )
𝒔𝒔𝒔𝒔𝒔𝒔
0 0.061 0.01371 15.710
3 0.149 0.03348 14.557
6 0.222 0.04988 13.297
9 0.304 0.06831 12.156
12 0.369 0.08291 10.832
15 0.462 0.10381 9.8170
18 0.529 0.11887 8.8151
21 0.615 0.13819 7.4667
24 0.726 0.16313 2.7706
27 0.748 0.16808 0.0000
𝝎𝝎 = −𝟗𝟗𝟗𝟗. 𝟑𝟑 ∗ 𝑻𝑻 + 𝟏𝟏𝟏𝟏. 𝟎𝟎 𝑹𝑹𝟐𝟐 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

49
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 41. Angular velocity vs. Motor Torque

Using simple optimization, we find the maximum power state at 𝑻𝑻𝒎𝒎 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝑵𝑵𝑵𝑵
and 𝝎𝝎 = 𝟗𝟗 𝒓𝒓𝒓𝒓𝒓𝒓/𝒔𝒔𝒔𝒔𝒔𝒔 with 𝑷𝑷𝒎𝒎𝒎𝒎𝒎𝒎 = 𝟎𝟎. 𝟖𝟖𝟖𝟖𝟖𝟖 𝑾𝑾.

2.1.5 Back-EMF Constant

The motor’s back-EMF constant is obtained from Equation 4: 𝑒𝑒𝑏𝑏 = 𝐾𝐾𝑏𝑏 ∗ 𝜔𝜔 . To


measure the motor back-emf constant, you will be required to test the motor's no-load open
loop speed response using Simulink. You will also need to measure the armature voltage
and armature current. Finally, you will need to find the angular velocity values. Note that
these values will allow you to also find 𝐵𝐵𝑚𝑚 in this experiment, as will be explained later.
Clearly, 𝐾𝐾𝑏𝑏 will be the slope of the 𝑒𝑒𝑏𝑏 𝑣𝑣𝑣𝑣 𝜔𝜔 graph. Each value of 𝑒𝑒𝑏𝑏 will be obtained using
Equation 2 while ignoring the small voltage contribution of the inductance, or:

𝑒𝑒𝑏𝑏 = 𝑉𝑉𝑎𝑎 − 𝑅𝑅𝑎𝑎 ∗ 𝑖𝑖𝑎𝑎 (2 − 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 2)

The setup for measuring both current and voltage, using two multimeters, is shown
below in Figure 42 and Figure 43. The current and voltage measurements can also be taken
separately by one multimeter if desired.

50
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 42. Measuring current and voltage using two multimeters at no-load

Red lead of Voltage-


measuring multimeter
to white wire

Red lead of Current-


measuring multimeter
to lead 1 of white wire

Black lead of Voltage-


measuring multimeter
to black wire

Black lead of Current-


measuring multimeter
to lead 2 of white wire

Figure 43. A close-up of simultaneous voltage and current measurements using two multimeters

51
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

The results are shown in Table 8, and the MATLAB graph with the best-fit 𝐾𝐾𝑏𝑏 value
is shown in Figure 44.

Table 8. Back-EMF Constant Results

𝑅𝑅𝑎𝑎 = 2.146 Ω
𝒓𝒓𝒓𝒓𝒓𝒓
𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷(%) 𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪 (𝑨𝑨) 𝝎𝝎( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝑽𝑽𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘 − 𝑽𝑽𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 (𝑽𝑽) 𝑽𝑽𝒂𝒂 (𝑽𝑽) 𝒆𝒆𝒃𝒃 (𝑽𝑽)
-100 -0.060 -14.661 -7.01 -3.505 -3.376
-90 -0.056 -12.915 -6.34 -3.170 -3.050
-80 -0.053 -11.519 -5.67 -2.835 -2.721
-70 -0.050 -10.123 -4.99 -2.495 -2.388
-60 -0.048 -8.7266 -4.31 -2.155 -2.052
-50 -0.043 -7.3304 -3.63 -1.815 -1.723
-40 -0.039 -5.9341 -2.96 -1.480 -1.396
-30 -0.034 -4.5379 -2.28 -1.140 -1.067
-20 -0.031 -3.1416 -1.60 -0.800 -0.733
-10 -0.027 -1.7453 -0.92 -0.460 -0.402
10 0.028 1.7453 0.93 0.465 0.405
20 0.031 3.1416 1.60 0.800 0.733
30 0.034 4.5379 2.28 1.140 1.067
40 0.039 5.9341 2.95 1.475 1.391
50 0.042 7.3304 3.63 1.815 1.725
60 0.046 8.7270 4.29 2.145 2.046
70 0.049 10.123 4.96 2.480 2.375
80 0.052 11.519 5.62 2.810 2.698
90 0.056 12.915 6.28 3.140 3.020
100 0.057 14.486 7.07 3.535 3.413
𝟐𝟐
𝑹𝑹 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗 𝑲𝑲𝒃𝒃 = 𝟎𝟎. 𝟐𝟐𝟐𝟐𝟐𝟐𝟐𝟐 𝑽𝑽 ∗ 𝒔𝒔

52
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 44. Back-EMF vs. Angular velocity (𝐾𝐾𝑏𝑏 experiment)

Note that the electrical power of the motor, 𝑃𝑃1 = 𝑒𝑒𝑏𝑏 ∗ 𝑖𝑖𝑎𝑎 is the same as the
mechanical power of the motor, 𝑃𝑃2 = 𝑇𝑇𝑚𝑚 ∗ 𝜔𝜔 . Thus, in theory,

𝑒𝑒𝑏𝑏 𝑇𝑇𝑚𝑚
= → 𝐾𝐾𝑏𝑏 = 𝐾𝐾𝑖𝑖 (12)
𝜔𝜔 𝑖𝑖𝑎𝑎

However, in practice, as is seen here, the two constants are slightly different. Here,
as should be the case, 𝐾𝐾𝑏𝑏 has the higher R-squared value, because there is more uncertainty
at play in a load experiment (where we found 𝐾𝐾𝑖𝑖 ) than in a no-load experiment.

Thus, 𝑲𝑲𝒃𝒃 = 𝟎𝟎. 𝟐𝟐𝟐𝟐𝟐𝟐𝟐𝟐 𝑽𝑽 ∗ 𝒔𝒔 .

For the sake of simplicity, we will take the average of 𝐾𝐾𝑖𝑖 and 𝐾𝐾𝑏𝑏 . Thus,

𝑲𝑲𝒊𝒊 ≈ 𝑲𝑲𝒃𝒃 ≈ 𝑲𝑲 = 𝟎𝟎. 𝟐𝟐𝟐𝟐𝟐𝟐𝟐𝟐.

53
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

2.2 Mechanical Characteristics

2.2.1 Viscous Friction Coefficient, Motor

The viscous-friction coefficient describes the amount of friction that exists in the
system. In reality, the friction may not be viscous 20. However, this is an assumption that
we make to arrive at an approximate linear model for the motor-gear-train combination –
again any reference to motor implicitly refers to the motor-gear-train combination.
Important note: because of various nonlinear affects such as friction and gear backlash,
it is not expected that this parameter can be estimated with great accuracy. Important
note: 𝐵𝐵𝑚𝑚 varies with the percent power supplied to the motor. Using the results from the
𝐾𝐾𝑏𝑏 experiment, 𝐵𝐵𝑚𝑚 is calculated using the following equation:

𝑖𝑖𝑎𝑎
𝐵𝐵𝑚𝑚 = 𝐾𝐾𝑖𝑖 ∗ (7 − 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 2)
𝜔𝜔

Thus, the results are shown in Table 9, and the graph of 𝐵𝐵𝑚𝑚 𝑣𝑣𝑣𝑣 𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎 % 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃
is shown in Figure 45.

Table 9. Viscous Friction Coefficient Results, Motor

𝐾𝐾𝑖𝑖 = 0.2149 𝑁𝑁𝑁𝑁/𝐴𝐴


𝒓𝒓𝒓𝒓𝒓𝒓 𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂
𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 (%) 𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪 (𝑨𝑨) 𝝎𝝎( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 % 𝑩𝑩(𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔)
-100 -0.060 -14.661 100 0.0008795
-90 -0.056 -12.915 90 0.0009318
-80 -0.053 -11.519 80 0.0009888
-70 -0.050 -10.123 70 0.0010614
-60 -0.048 -8.7266 60 0.0011820
-50 -0.043 -7.3304 50 0.0012606
-40 -0.039 -5.9341 40 0.0014124
-30 -0.034 -4.5379 30 0.0016101
-20 -0.031 -3.1416 20 0.0021205
-10 -0.027 -1.7453 10 0.0033245
10 0.028 1.7453 10 0.0034477
20 0.031 3.1416 20 0.0021205
30 0.034 4.5379 30 0.0016101
40 0.039 5.9341 40 0.0014124
50 0.042 7.3304 50 0.0012313

20
The viscous friction assumption is discussed by F. Golnaraghi and B. Kuo [3]

54
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
60 0.046 8.7270 60 0.0011328
70 0.049 10.123 70 0.0010402
80 0.052 11.519 80 0.0009701
90 0.056 12.915 90 0.0009318
100 0.057 14.486 100 0.0008456
Best-fit 𝑩𝑩𝑵𝑵∗𝒎𝒎∗𝒔𝒔 (𝑷𝑷) = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎
𝐵𝐵 = 𝑓𝑓(𝑃𝑃) ∗ 𝑷𝑷−𝟎𝟎.𝟔𝟔𝟔𝟔𝟔𝟔𝟔𝟔
is: + 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝑹𝑹𝟐𝟐 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

Figure 45. Viscous Friction Coefficient vs % Power, Motor

For a non-linear empirical relationship, an R-squared value of 0.9949 can be


considered quite good. Thus, if 𝑃𝑃 represents power percentage, then for the motor:

𝐵𝐵𝑚𝑚 (𝑃𝑃) = 0.01359 ∗ 𝑃𝑃−0.6203 + 0.00006 (13)

To obtain a single 𝐵𝐵𝑚𝑚 value, one can assume that the motor will only operate at
around 50% to 100% input power, thus the average of these values is taken, as seen in
Table 10.

55
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Table 10. Operational Viscous Friction Coefficient value, Motor

𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 % 𝑩𝑩(𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔)


-100 0.0008795
-90 0.0009318
-80 0.0009888
-70 0.0010614
-60 0.0011820
-50 0.0012606
50 0.0012313
60 0.0011328
70 0.0010402
80 0.0009701
90 0.0009318
100 0.0008456
Average 𝑩𝑩𝒎𝒎 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔
Standard Deviation = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔

Thus the operational 𝐵𝐵𝑚𝑚 value for motor only is: 𝑩𝑩𝒎𝒎 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔 .

2.2.2 Viscous Friction Coefficient, Robot Arm

The value of 𝐵𝐵𝑎𝑎𝑎𝑎𝑎𝑎 for the motor-arm combination will be higher than 𝐵𝐵𝑚𝑚 for each
power level. Therefore, the 𝐾𝐾𝑏𝑏 experiment is cothe nducted again for the full robot arm,
except this time only the current and angular velocity need to be measured. During the
experiment, ensure that the wires, multimeter leads, and robot body do not impede the path
of the arm, and that the arm is at a greater height than each of them. The setup is as
shown in Figure 46.

56
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 46. Current measurement while the robot arm is moving. Hold down the stand for steady readings.

The results of 𝐵𝐵𝑎𝑎𝑎𝑎𝑎𝑎 𝑣𝑣𝑣𝑣 𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎 % 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃 for the motor-arm combination are
shown below in Table 11. The graph is shown in Figure 47.

Table 11. Viscous Friction Coefficient Results, Robot Arm

𝐾𝐾𝑖𝑖 = 0.2149 𝑁𝑁𝑁𝑁/𝐴𝐴


𝒓𝒓𝒓𝒓𝒓𝒓 𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂
𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 (%) 𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪 (𝑨𝑨) 𝝎𝝎( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 % 𝑩𝑩(𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔)
-100 -0.076 -13.090 100 0.0012477
-90 -0.072 -11.694 90 0.0013231
-80 -0.066 -10.559 80 0.0013433
-70 -0.062 -9.3375 70 0.0014269
-60 -0.059 -8.0285 60 0.0015793
-50 -0.055 -6.8068 50 0.0017364
-40 -0.045 -5.4105 40 0.0017874
-30 -0.046 -4.1888 30 0.0023600

57
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
-20 -0.042 -2.8798 20 0.0031342
-10 -0.038 -1.5708 10 0.0051988
10 0.044 1.4836 10 0.0063734
20 0.049 2.7925 20 0.0037709
30 0.05 4.1888 30 0.0025652
40 0.056 5.5850 40 0.0021548
50 0.055 6.8068 50 0.0017364
60 0.059 8.2030 60 0.0015457
70 0.065 9.4248 70 0.0014821
80 0.069 10.821 80 0.0013703
90 0.075 12.043 90 0.0013383
100 0.078 13.439 100 0.0012473
Best-fit 𝑩𝑩𝑵𝑵∗𝒎𝒎∗𝒔𝒔 (𝑷𝑷) =
𝐵𝐵 = 𝑓𝑓(𝑃𝑃) is: 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 ∗ 𝑷𝑷−𝟎𝟎.𝟕𝟕𝟕𝟕𝟕𝟕𝟕𝟕 𝑹𝑹𝟐𝟐 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

Figure 47. Viscous Friction Coefficient vs. % Power, Robot Arm

For a non-linear empirical relationship, an R-squared value of 0.9680 is still good.


Thus, if 𝑃𝑃 represents power percentage, then for the motor-arm combination:

𝐵𝐵𝑎𝑎𝑎𝑎𝑎𝑎 (𝑃𝑃) = 0.03055 ∗ 𝑃𝑃−0.7256 (14)

58
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
However, when the arm moves the payload, it will use high power except for very
brief stints at the end points. Thus, the operational 𝐵𝐵𝑎𝑎𝑎𝑎𝑎𝑎 value of the arm is the average
𝐵𝐵𝑎𝑎𝑎𝑎𝑎𝑎 value for 50 to 100 percent power. The operational 𝐵𝐵𝑎𝑎𝑎𝑎𝑎𝑎 value is shown in Table 12.

Table 12. Operational Viscous Friction Coefficient value, Robot Arm

𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂𝒂 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 % 𝑩𝑩(𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔)


100 0.0012477
90 0.0013231
80 0.0013433
70 0.0014269
60 0.0015793
50 0.0017364
50 0.0017364
60 0.0015457
70 0.0014821
80 0.0013703
90 0.0013383
100 0.0012473
Average 𝑩𝑩𝒂𝒂𝒂𝒂𝒂𝒂 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔
Standard Deviation = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔

Therefore, 𝑩𝑩𝒂𝒂𝒂𝒂𝒂𝒂 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝑵𝑵 ∗ 𝒎𝒎 ∗ 𝒔𝒔 .

2.2.3 Encoder Resolution

Previously an encoder sample time of 0.1 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 was used. However, based on
past iterations of this experiment, the time constant is expected to be slightly less than this
value. Having a sample time greater than the parameter we are trying to find will prevent
us from finding that parameter. Therefore, the sample time must be decreased. However,
as mentioned previously, once the Simulink encoder sampling time is small enough, in fact
smaller than ,the real-time resolution of the encoder, it does not sample at every interval.
This will also negatively impact the certainty of the measurement. Thus, before finding the
time constant we must find ,the time resolution of the encoder. For this experiment, a
constant input power (50%) without delay is input to the motor for a trial duration of
10.0 𝑠𝑠𝑒𝑒𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐. The Simulink encoder sample time is varied. If the sample time is at least
as large as the encoder resolution, then no readings are skipped, and the number of samples,
𝑁𝑁, is found from the duration of the trial, 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 , and the sampling time, 𝑡𝑡𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 , as seen
below:

59
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡
𝑁𝑁 = 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 � � + 1 (15)
𝑡𝑡𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠

Where the floor function accounts for when the trial time is not divisible by the
sample time, and where the added sample is due to the sample at 𝑡𝑡 = 0.

However, if a sample time is chosen that is smaller than the resolution of the
encoder, then some readings will be skipped, such that:

𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡
𝑁𝑁 < 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 � � + 1 (16)
𝑡𝑡𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠

Therefore when Equation 15 is true, we must decrease the sample time, and when
Equation 16 is true, we must increase the sample time. This procedure is done iteratively
until we have ‘settled’ on the correct sample time resolution. To find how many readings
of timestamps and angular displacement values are taken, code is run in MATLAB after
running the Simulink model, as seen below.
theta = double(output.signals.values);
timestamp = double(output.time);

The size of these vectors is the number of samples. The results are shown below in
Table 13.

Table 13. Encoder Time Resolution Results

Time
Duration Max # of Actual # of
Encoder Sample time (seconds) (seconds) Samples Samples
0.01000 10.0 1001 974
0.01100 10.0 910 864
0.02000 10.0 501 501
0.01600 10.0 626 626
0.01400 10.0 715 712
0.01450 10.0 690 689
0.01460 10.0 685 683
0.01500 10.0 667 667
0.01490 10.0 672 671
0.01495 10.0 669 666
𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬 𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹 ≈ 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔

60
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Therefore, 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆 𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕 𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔. This is the


sampling time we will use for the experiment to find 𝜏𝜏𝑚𝑚 .

2.2.4 A Method for Finding 𝝉𝝉

2.2.4.1 Explanation

As explained in the previous section, the encoder sampling time used for this
experiment is the same as the experimentally-found encoder resolution or 0.015 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠.
The total trial duration is 5.0 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠. Using Equation 15, there must be
334 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡. The experiment is conducted as follows. At 1.0 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠, a constant,
positive power % is input (50% shown below). At 4.0 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠, the power is set to zero
(as shown below, -50% percent is added). The Simulink model is shown below in Figure
48.

Figure 48. Simulink® model for turning power on and off to measure time constant

Thus, 𝜔𝜔(𝑡𝑡) will rise, reach steady-state, and then fall to zero. The mechanical time
constant should be the same whether the motor is rising (𝜏𝜏𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 ) or falling (𝜏𝜏𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 ). When
𝜔𝜔(𝑡𝑡) rises, it follows the equation:
𝑡𝑡
𝜔𝜔(𝑡𝑡 ) = 𝜔𝜔𝑠𝑠𝑠𝑠 ∗ �1 − 𝑒𝑒 −𝜏𝜏 � ∗ 𝑢𝑢(𝑡𝑡 ) (17)

Where 𝑡𝑡 starts when the input power first becomes nonzero.

When 𝑡𝑡 = 𝜏𝜏, 𝜔𝜔(𝑡𝑡 ) = 𝜔𝜔𝑠𝑠𝑠𝑠 ∗ (1 − 𝑒𝑒 −1 ) = 0.632 ∗ 𝜔𝜔𝑠𝑠𝑠𝑠 . Thus, 𝜏𝜏 is the time that 𝜔𝜔(𝑡𝑡 )
rises to 63.2% of its steady-state value, or:

61
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

𝜔𝜔(𝜏𝜏) ≡ 𝜔𝜔𝜏𝜏 = 0.632 ∗ 𝜔𝜔𝑠𝑠𝑠𝑠 (18)

When 𝜔𝜔(𝑡𝑡) falls, it follows the equation:


𝑡𝑡
𝜔𝜔(𝑡𝑡 ) = 𝜔𝜔𝑠𝑠𝑠𝑠 ∗ 𝑒𝑒 −𝜏𝜏 ∗ 𝑢𝑢(𝑡𝑡 ) (19)

Where 𝑡𝑡 starts when the input power first becomes zero.

When 𝑡𝑡 = 𝜏𝜏, 𝜔𝜔(𝑡𝑡 ) = 𝜔𝜔𝑠𝑠𝑠𝑠 ∗ (𝑒𝑒 −1 ) = 0.368 ∗ 𝜔𝜔𝑠𝑠𝑠𝑠 . Thus, 𝜏𝜏 is the time that 𝜔𝜔(𝑡𝑡 ) takes
to fall to 36.8% of its steady-state value, or:

𝜔𝜔(𝜏𝜏) ≡ 𝜔𝜔𝜏𝜏 = 0.368 ∗ 𝜔𝜔𝑠𝑠𝑠𝑠 (20)

A typical 𝜔𝜔(𝑡𝑡 ) grapthe h for this experiment is shown in section 2.2.4.3.

2.2.4.2 Linearizing

It is important to note that there usually will not be a data point 𝑡𝑡𝜏𝜏 where 𝜔𝜔𝜏𝜏 =
0.632 ∗ 𝜔𝜔𝑠𝑠𝑠𝑠 . Usually there will be, a point ′𝑎𝑎′ before (𝑡𝑡𝑎𝑎 , 𝜔𝜔𝑎𝑎 ), and a point ′𝑏𝑏′ after (𝑡𝑡𝑏𝑏 , 𝜔𝜔𝑏𝑏 ),
such that:

𝑡𝑡𝑏𝑏 > 𝑡𝑡𝜏𝜏 > 𝑡𝑡𝑎𝑎 (21)

𝜔𝜔𝑏𝑏 > 𝜔𝜔𝜏𝜏 > 𝜔𝜔𝑎𝑎 (22)

To rectify this, we assume that since 𝑡𝑡𝑏𝑏 − 𝑡𝑡𝑎𝑎 is small, the graph behaves nearly
linearly between points 𝑎𝑎 and 𝑏𝑏. Thus we are assuming a constant slope, 𝑚𝑚, which satisfies
the equations:

𝜔𝜔𝑏𝑏 − 𝜔𝜔𝑎𝑎
𝑚𝑚 = (23)
𝑡𝑡𝑏𝑏 − 𝑡𝑡𝑎𝑎

𝜔𝜔𝜏𝜏 − 𝜔𝜔𝑎𝑎
𝑚𝑚 = (24)
𝑡𝑡𝜏𝜏 − 𝑡𝑡𝑎𝑎

Which, after equating and rearranging, we have:

62
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

(𝜔𝜔𝜏𝜏 − 𝜔𝜔𝑎𝑎 )
𝑡𝑡𝜏𝜏 = 𝑡𝑡𝑎𝑎 + (𝑡𝑡𝑏𝑏 − 𝑡𝑡𝑎𝑎 ) ∗ (25)
(𝜔𝜔𝑏𝑏 − 𝜔𝜔𝑎𝑎 )

2.2.4.3 A Linearization Example

As an example to find 𝜏𝜏𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 , take the following data points from the same graph,
shown below in Figure 49.

Figure 49. Angular velocity as a function of time, tau experiment

Thus, 𝜔𝜔𝑠𝑠𝑠𝑠 ≈ 7.608 and 𝜔𝜔𝜏𝜏1 ≈ 4.808. However, the closest data points we have are
𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃 𝐴𝐴 (1.080, 4.654) and 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃 𝐵𝐵 (1.095, 5.191). Thus,

(𝑡𝑡𝑎𝑎 , 𝜔𝜔𝑎𝑎 ) = (1.080, 4.654) (26)

(𝑡𝑡𝑏𝑏 , 𝜔𝜔𝑏𝑏 ) = (1.095, 5.191) (27)

63
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Then, using Equation 25:

(4.808−4.654)
𝑡𝑡𝜏𝜏 = 1.080 + (1.095 − 1.080) ∗ (5.191−4.654) = 1.084 (28)

Since the graph becomes non-zero at 𝑡𝑡0 = 0.915 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠, we have:

𝜏𝜏 = 𝑡𝑡𝜏𝜏 − 𝑡𝑡0 = 1.084 − 0.915 = 0.169 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 (29)

Note that the same equation and procedure can be used to find 𝜏𝜏𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 , except that 𝑡𝑡0
starts at around 4.0 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠. Now that we have a method for finding 𝜏𝜏, we show the
results.

2.2.5 Mechanical Time Constant, Motor

The results for 𝜏𝜏𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 , for the motor only, are shown in Table 14 below.

Table 14. Rising Time Constant, Motor

𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓


(%) 𝝎𝝎 𝒔𝒔𝒔𝒔 ( ) 𝝎𝝎 𝝉𝝉 ( ) 𝝎𝝎 𝒂𝒂 ( ) 𝝎𝝎𝒃𝒃 (𝒓𝒓𝒓𝒓𝒓𝒓) 𝒕𝒕 (𝒔𝒔𝒔𝒔𝒔𝒔) 𝒕𝒕 (𝒔𝒔𝒔𝒔𝒔𝒔) 𝒕𝒕 (𝒔𝒔𝒔𝒔𝒔𝒔) 𝝉𝝉(𝒔𝒔𝒔𝒔𝒔𝒔)
𝒔𝒔𝒔𝒔𝒔𝒔 𝒔𝒔𝒔𝒔𝒔𝒔 𝒔𝒔𝒔𝒔𝒔𝒔 𝒔𝒔𝒔𝒔𝒔𝒔 𝒂𝒂 𝒃𝒃 𝝉𝝉
100 16.202 10.24 9.308 11.25 1.065 1.080 1.072 0.0722
90 14.394 9.097 8.533 10.08 1.065 1.080 1.070 0.0705
80 12.829 8.108 6.593 8.145 1.050 1.065 1.065 0.0646
70 11.246 7.107 5.818 7.369 1.050 1.065 1.062 0.0625
60 9.6984 6.129 5.818 6.981 1.065 1.080 1.069 0.0690
50 8.1342 5.141 4.654 5.430 1.050 1.065 1.059 0.0594
40 6.5615 4.147 3.491 4.266 1.050 1.065 1.063 0.0627
30 5.0058 3.164 2.715 3.491 1.050 1.065 1.059 0.0587
20 3.4460 2.178 1.551 2.327 1.035 1.050 1.047 0.0471
10 1.9013 1.202 1.164 1.551 1.065 1.080 1.066 0.0665

The results for 𝜏𝜏𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 , for the motor only, are shown in Table 15 below.

64
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Table 15. Falling Time Constant, Motor

𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓


(%) 𝝎𝝎𝒔𝒔𝒔𝒔 ( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝝎𝝎𝝉𝝉 ( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝝎𝝎𝒂𝒂 ( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝝎𝝎𝒃𝒃 ( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝒕𝒕𝒂𝒂 (𝒔𝒔𝒔𝒔𝒔𝒔) 𝒕𝒕𝒃𝒃 (𝒔𝒔𝒔𝒔𝒔𝒔) 𝒕𝒕𝝉𝝉 (𝒔𝒔𝒔𝒔𝒔𝒔) 𝝉𝝉(𝒔𝒔𝒔𝒔𝒔𝒔)
100 16.202 5.962 6.206 5.042 4.065 4.080 4.068 0.0681
90 14.394 5.297 5.818 4.266 4.065 4.080 4.070 0.0700
80 12.829 4.721 5.818 4.654 4.050 4.065 4.064 0.0641
70 11.246 4.139 5.430 3.879 4.050 4.065 4.062 0.0625
60 9.6984 3.569 4.654 3.491 4.050 4.065 4.064 0.0640
50 8.1342 2.993 3.491 2.715 4.050 4.065 4.060 0.0596
40 6.5615 2.415 3.103 2.327 4.050 4.065 4.063 0.0633
30 5.0058 1.842 1.939 1.551 4.050 4.065 4.054 0.0537
20 3.4460 1.268 1.939 1.164 4.035 4.050 4.048 0.0480
10 1.9013 0.700 0.776 0.388 4.050 4.065 4.053 0.0529

The time constant values for rising and falling are shown together in Table 16 below.

Table 16. Time Constant values, Motor

𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 (%) 𝝉𝝉𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓 (𝒔𝒔𝒔𝒔𝒔𝒔) 𝝉𝝉𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇 (𝒔𝒔𝒔𝒔𝒔𝒔)


100 0.0722 0.0681
90 0.0705 0.0700
80 0.0646 0.0641
70 0.0625 0.0625
60 0.0690 0.0640
50 0.0594 0.0596
40 0.0627 0.0633
30 0.0587 0.0537
20 0.0471 0.0480
10 0.0665 0.0529
Average 𝝉𝝉 = 0.06198 seconds
Standard Deviation = 0.00710 seconds

It may not have been clear whether the time constant should vary experimentally
with the input power, as 𝐵𝐵𝑚𝑚 did. However, the table above shows that it does not vary
significantly, as the graph of 𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣 𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃 %, in Figure 50, proves.

65
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 50. Average of Tau vs. Power %, Motor

Thus, for the motor only, 𝝉𝝉𝒎𝒎 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔.

2.2.6 Mechanical Time Constant, Robot Arm

The results for 𝜏𝜏𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 , for the robot arm, are shown in Table 17 below.

Table 17. Rising Time Constant, Robot Arm

𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 𝝎𝝎𝒔𝒔𝒔𝒔 (𝒓𝒓𝒓𝒓𝒓𝒓) 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓


𝝎𝝎𝝉𝝉 ( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝝎𝝎𝒂𝒂 ( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝝎𝝎𝒃𝒃 ( 𝒔𝒔𝒔𝒔𝒔𝒔 ) 𝒕𝒕𝒂𝒂 𝒕𝒕𝒃𝒃 𝒕𝒕𝝉𝝉 𝝉𝝉
𝒔𝒔𝒔𝒔𝒔𝒔
(%) (𝒔𝒔𝒔𝒔𝒔𝒔) (𝒔𝒔𝒔𝒔𝒔𝒔) (𝒔𝒔𝒔𝒔𝒔𝒔) (𝒔𝒔𝒔𝒔𝒔𝒔)
100 15.002 9.481 9.308 10.08 1.125 1.140 1.128 0.1284
90 13.356 8.441 7.369 8.533 1.110 1.125 1.124 0.1238
80 12.051 7.616 7.369 8.145 1.110 1.125 1.115 0.1148
70 10.615 6.709 6.593 7.757 1.125 1.140 1.126 0.1265
60 9.1676 5.794 5.430 6.593 1.125 1.140 1.130 0.1297
50 7.7155 4.876 4.654 5.042 1.110 1.125 1.119 0.1186
40 6.2610 3.957 3.879 4.266 1.125 1.140 1.128 0.1280
30 4.7512 3.003 2.715 3.103 1.110 1.125 1.121 0.1211
20 3.2275 2.040 1.939 2.327 1.110 1.125 1.114 0.1139
10 1.7130 1.083 1.034 1.164 1.095 1.110 1.101 0.1006
Average 𝝉𝝉 = 0.1205 seconds
Standard Deviation = 0.0090 seconds

66
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

The graph of 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣 𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃 % is shown in Figure 51 below.

Figure 51. Average of Rising Tau vs. Power %, Robot Arm

The results for 𝜏𝜏𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 , for the robot arm, are shown below in Table 18.

Table 18. Falling Time Constant, Robot Arm

𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓 𝒓𝒓𝒓𝒓𝒓𝒓 𝒕𝒕𝒂𝒂 𝒕𝒕𝒃𝒃 𝒕𝒕𝝉𝝉 𝝉𝝉


𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷(%) 𝝎𝝎 𝒔𝒔𝒔𝒔 ( ) 𝝎𝝎 𝝉𝝉 ( ) 𝝎𝝎 𝒂𝒂 ( ) 𝝎𝝎 𝒃𝒃 ( ) (𝒔𝒔𝒔𝒔𝒔𝒔) (𝒔𝒔𝒔𝒔𝒔𝒔) (𝒔𝒔𝒔𝒔𝒔𝒔) (𝒔𝒔𝒔𝒔𝒔𝒔)
𝒔𝒔𝒔𝒔𝒔𝒔 𝒔𝒔𝒔𝒔𝒔𝒔 𝒔𝒔𝒔𝒔𝒔𝒔 𝒔𝒔𝒔𝒔𝒔𝒔
100 15.002 5.521 5.818 5.042 4.110 4.125 4.116 0.1157
90 13.356 4.915 5.430 4.654 4.095 4.110 4.105 0.1050
80 12.051 4.435 4.654 4.266 4.095 4.110 4.103 0.1035
70 10.615 3.906 4.072 3.491 4.095 4.110 4.099 0.0993
60 9.1676 3.374 3.491 3.103 4.080 4.095 4.085 0.0845
50 7.7155 2.839 3.103 2.715 4.065 4.080 4.075 0.0752
40 6.2610 2.304 2.327 1.551 4.065 4.080 4.065 0.0654
30 4.7512 1.748 1.939 1.551 4.050 4.065 4.057 0.0574
20 3.2275 1.188 1.551 1.164 4.035 4.050 4.049 0.0491
10 1.7130 0.630 0.776 0.517 4.035 4.050 4.043 0.0434

The graph of 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣 𝑎𝑎𝑎𝑎𝑎𝑎(𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃%) is shown below in Figure 52.

67
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 52. Falling Tau vs. Power %, Robot Arm

It is clear from the graphs that while 𝜏𝜏𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 is relatively constant with input power,
𝜏𝜏𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 is linear with the input power.

During the motion, it was observed that the arm would wobble while stopping. This
may be the reason for the falling time constant being linear with the input power. In any
case, we assume that the falling time constant measurements are not accurate because of
the wobble, and take the time constant of the arm to be the average of the 𝜏𝜏𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 dataset only.
Note that this will not significantly affect the accuracy of the model, since the arm will
mostly be operating at high input powers, where 𝜏𝜏𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 and 𝜏𝜏𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 are nearly equal. Therefore,
𝝉𝝉𝒂𝒂𝒂𝒂𝒂𝒂 = 𝟎𝟎. 𝟏𝟏𝟏𝟏𝟏𝟏𝟏𝟏 𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔𝒔.

2.3 Parameter Results

We now have six of the seven parameters for both the motor and the robot arm. To
find the final parameter, 𝐽𝐽, we use Equation 8, copied below.

𝐾𝐾𝑖𝑖 𝐾𝐾𝑏𝑏
𝐽𝐽 = 𝜏𝜏 ∗ �𝐵𝐵 + � (8)
𝑅𝑅𝑎𝑎

68
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Note that this is the best method. If you want to check how well your experimental
values correlate, then you can implement an experiment to find 𝐽𝐽 for both the motor and
the robot arm, and then compare both sides of Equation 8 for each case. We conducted
such an experiment in Appendix I: A Method for Finding J and obtained values of 𝑱𝑱𝒎𝒎 =
𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝒌𝒌𝒌𝒌 ∗ 𝒎𝒎𝟐𝟐 and 𝑱𝑱𝒂𝒂𝒂𝒂𝒂𝒂 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝒌𝒌𝒌𝒌 ∗ 𝒎𝒎𝟐𝟐 . The experimental 𝐽𝐽𝑚𝑚 was 20%
higher than the theoretical value seen below, while the experimental 𝐽𝐽𝑎𝑎𝑎𝑎𝑎𝑎 was 22% lower
that the theoretical value seen below. When considering experimental uncertainty, this is
percent error is okay. However, using Equation 8 is clearly the more accurate and time-
effective method.

The results for the motor are seen in Table 19 below.

Table 19. Control Parameters, Motor

Parameter Value Unit


𝑅𝑅𝑎𝑎 2.146 Ω
𝐿𝐿𝑎𝑎 4.283 mH
𝐾𝐾𝑖𝑖 0.2247 N ∗ m/A
𝐾𝐾𝑏𝑏 0.2247 V∗s
𝐵𝐵 0.001038 N∗m∗s
𝜏𝜏 0.06198 seconds
𝐽𝐽 0.001523 kg ∗ m2

The results for the robot arm are seen in Table 20 below.

Table 20. Control Parameters, Robot Arm

Parameter Value Unit


𝑅𝑅𝑎𝑎 2.146 Ω
𝐿𝐿𝑎𝑎 4.283 mH
𝐾𝐾𝑖𝑖 0.2247 N ∗ m/A
𝐾𝐾𝑏𝑏 0.2247 V∗s
𝐵𝐵 0.001448 N∗m∗s
𝜏𝜏 0.1205 seconds
𝐽𝐽 0.003010 kg ∗ m2

69
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

_________________________________
3 PROJECT 2: MODEL
VERIFICATION FROM SPEED
AND POSITION RESPONSES
3.1 Update to “Angular Parameters” MATLAB® Code

In order to plot simulated and actual speed and position responses on the same
graph, Sections 1 and 5 of the “Angular Parameters” MATLAB code must now be
changed to what is shown below (note that once again “numsamples” must be set
equal to the number of encoder samples in the trial of the actual speed response),

%1: Declarations
hold on
omegaoddwindowsize=13; %the larger the value, the smoother the output,
alphaoddwindowsize=95; % but also less nonzero samples

omegawindowboundary = floor(omegaoddwindowsize/2);
alphawindowboundary = floor(alphaoddwindowsize/2);

omegasteadystate = 0; %declare omegasteadystate


numsamples=-1; %set this number to match the # of timestamps
steadystatestart=1; %set this to be the first sample of steady omega
steadystateend=2; %set this to be the last sample of steady omega

%posn_out is encoder output from real motor position response


%posn_sim is simulated motor position response
%output is encoder output from real motor speed response
%speed_sim is simulated motor speed response

%position responses
realtheta_posn = double(posn_out.signals.values);
simtheta = double(posn_sim.signals.values);
realtime_posn = double(posn_out.time);
posnsimtime = double(posn_sim.time);

%velocity responses
realtheta_vel = double(output.signals.values);
simomega = double(speed_sim.signals.values);
realtime_vel = double(output.time);
speedsimtime = double(speed_sim.time);

70
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
And shown below,
%5: Show the results

%position responses
plot(posnsimtime,simtheta,'.','color','blue')
plot(realtime_posn,realtheta_posn,'-','color','blue')

%velocity responses
plot(speedsimtime,simomega,'.','color','blue')
plot(timeofroughomega,roughomega,'-','color','blue')

3.2 Speed Response Model21 and Model Parameter Code

Using Equations 2, 4, 5, and 7, the Simulink model to simulate the speed response
of the motor is shown below in Figure 53.

Figure 53. DC Motor Speed Response model

It is a first-order system when the inductance is assumed small. Before running this
model, run a MATLAB program declaring all the variables and setting them to the values
you found previously (the mechanical parameters will be different from the motor to the
robot arm). This is shown below.

format long
R = 2.150;
L = 0.004283;
Ki = 0.2500;
Kb = 0.2400;
B = 0.001100;
J = 0.002500;
KS = 0.95; %this is sensor gain, will be used for position model

21
Speed Response model taken from F. Golnaraghi and B. Kuo [3]

71
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Recall the values for the motor only, shown below in Table 21.

Table 21. Control Parameters, Motor

Parameter Value Unit


𝑅𝑅𝑎𝑎 2.146 Ω
𝐿𝐿𝑎𝑎 4.283 mH
𝐾𝐾𝑖𝑖 0.2247 N ∗ m/A
𝐾𝐾𝑏𝑏 0.2247 V∗s
𝐵𝐵 0.001038 N∗m∗s
𝜏𝜏 0.06198 seconds
𝐽𝐽 0.001523 kg ∗ m2

3.3 Comparing Speed Responses, Motor

We run the motor in real life, using the standard constant-power Simulink model, at
100% power for 5 seconds, starting at the 0.5 second mark. We measure (𝑉𝑉𝑤𝑤 − 𝑉𝑉𝑏𝑏 ) =
7.95𝑉𝑉, thus we set the simulation voltage step function to be 3.975𝑉𝑉 starting at 0.5 seconds
for a duration of 5 seconds. The real and simulated 𝜔𝜔(𝑡𝑡) graphs are shown in red and blue
respectively in Figure 54 below. Note that the black graph is a step function starting at 𝑡𝑡 =
0.5 with a final value of 𝜔𝜔𝑠𝑠𝑠𝑠 , for visual comparison only.

Figure 54. Simulated and Actual Speed Responses, Motor

72
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
A summary of how changing each parameter (found by trial and error as well as
considering Equations 2, 4, 5, 7, and 8) will affect22 the simulated 𝜔𝜔(𝑡𝑡) graph is shown in
Table 22 below.

Table 22. Effect of Control Parameters on ω(t)

𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊𝒊 𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬 𝒐𝒐𝒐𝒐 𝝎𝝎𝒔𝒔𝒔𝒔 𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬 𝒐𝒐𝒐𝒐 𝝉𝝉


𝑹𝑹 decreases slowly increases rapidly
𝑳𝑳 no effect no effect
𝑲𝑲𝒊𝒊 increases slowly decreases rapidly
𝑲𝑲𝒃𝒃 decreases rapidly decreases rapidly
𝑩𝑩 decreases slowly decreases slowly
𝑱𝑱 no effect increases rapidly

3.4 Position Response Model 23

The Simulink model used to simulate the position response of the motor is shown
below in Figure 55.

Figure 55. DC Motor Position Response model

For the robot arm project, we have chosen a desired final position of 160°, thus
“Degree Step” is set to be 160°, and starting at 0.5 seconds. The trial duration is 5 seconds.
This model is similar to the speed response simulation, except that the Step input is 𝜃𝜃 in
degrees and not voltage, and that the output is 𝜃𝜃 in degrees and not angular velocity. Thus,
degrees are converted to radians, which are converted to a voltage by simulating the
presence of a sensor with a gain of 𝐾𝐾𝑠𝑠 = 1𝑉𝑉/𝑟𝑟𝑟𝑟𝑟𝑟. Also, the angular velocity is integrated

𝑡𝑡
𝐴𝐴𝐾𝐾𝑖𝑖
22
Recall: 𝜔𝜔𝑚𝑚 (𝑡𝑡) = ∗ (1 − 𝑒𝑒 −𝜏𝜏 ), from F. Golnaraghi and B. Kuo [3]
𝐾𝐾𝑖𝑖 𝐾𝐾𝑏𝑏 +𝑅𝑅𝑎𝑎 𝐵𝐵
23
Position Response Model taken from F. Golnaraghi and B. Kuo [3]

73
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
with an initial condition of zero, to obtain angular displacement, which is then converted
to degrees as an output. Note that ‘KS’, the Sensor Gain, must be initialized in MATLAB,
as in the MATLAB code from above. The Simulink model used to control the actual motor
with the same final degree value is shown below in Figure 56.

Figure 56. Simulink® model that controls the motor in real life

Note that the sensor gain value here must match that of the simulation. The ‘Volt to
Power%’ block is a gain that maps voltage 𝑉𝑉𝑎𝑎 , with a range of −4.5𝑉𝑉 𝑡𝑡𝑡𝑡 + 4.5𝑉𝑉, to power
percentage, with a range of −100% 𝑡𝑡𝑡𝑡 + 100%. You may want to review the results of
the 𝐾𝐾𝑏𝑏 experiments to confirm that these 2 values have a linetwor relationship. The
saturation block is used to keep the input power between the range of −100% 𝑡𝑡𝑡𝑡 + 100%.

The PID block represents the PID position controller that we will be using. For now,
to ignore its effects, we will set the proportional coefficient, 𝑃𝑃, to be 1, and the coefficients
𝐼𝐼 𝑎𝑎𝑎𝑎𝑎𝑎 𝐷𝐷 to zero. The PID window is shown below in Figure 57.

74
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 57. Simulink® PID Controller Block Parameters Window

75
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

3.5 Comparing Position Responses, Motor

Using the model, we obtain the graph shown below in Figure 58, with the actual
𝜃𝜃(𝑡𝑡) in red and the simulated 𝜃𝜃(𝑡𝑡) in blue.

Figure 58. Simulated and Actual Position Responses, Motor

We notice that the simulated 𝜃𝜃 (𝑡𝑡 ) and 𝜔𝜔(𝑡𝑡) graphs closely match those of the actual
motor, and thus we do not need to alter any parameters here.

3.6 Comparing Speed and Position Responses, Robot Arm

The same experiment is conducted for the full robot arm. We run the motor and
measure (𝑉𝑉𝑤𝑤 − 𝑉𝑉𝑏𝑏 ) = 7.98𝑉𝑉, thus we set the simulation voltage step function amplitude to
be 3.99𝑉𝑉. Figure 59 shows the real and simulated 𝜔𝜔(𝑡𝑡) graphs in red and blue respectively
below.

76
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 59. Simulated and Actual Speed Responses, Robot Arm

Figure 60 shows the real and simulated 𝜃𝜃(𝑡𝑡) graphs below, in red and blue
respectively.

77
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 60. Simulated and Actual Position Responses, Robot Arm

Clearly, the robot arm needs some fine tuning. We need to decrease the steady-state
velocity as well as the position percent overshoot.

3.7 Fine-Tuning Robot Arm Parameters

3.7.1 Position Control Transfer Function 24

It is important to note that the simulated 𝜃𝜃(𝑡𝑡) is a second-order system, with the
small inductance assumption. We apply the step input 𝜃𝜃𝑖𝑖𝑖𝑖 (𝑡𝑡), and obtain the output 𝜃𝜃𝑜𝑜𝑜𝑜𝑜𝑜 (𝑡𝑡).
The transfer function for the simulation is:

𝐾𝐾𝑖𝑖 𝐾𝐾𝑃𝑃 𝐾𝐾𝑆𝑆


𝛩𝛩𝑜𝑜𝑜𝑜𝑜𝑜 (𝑠𝑠) 𝑅𝑅𝑎𝑎 𝐽𝐽 𝜔𝜔𝑛𝑛2
= = 2 (30)
𝛩𝛩𝑖𝑖𝑖𝑖 (𝑠𝑠) 𝑅𝑅 𝐵𝐵 + 𝐾𝐾𝑖𝑖 𝐾𝐾𝑏𝑏 𝐾𝐾 𝐾𝐾 𝐾𝐾 2
𝑠𝑠 2 + 𝑎𝑎 𝑠𝑠 + 𝑖𝑖 𝑃𝑃 𝑆𝑆 𝑠𝑠 + 2𝜉𝜉𝜔𝜔𝑛𝑛 𝑠𝑠 + 𝜔𝜔𝑛𝑛
𝑅𝑅𝑎𝑎 𝐽𝐽 𝑅𝑅𝑎𝑎 𝐽𝐽

With poles of:

24
The information in Section 3.7.1 comes from F. Golnaraghi and B. Kuo [3]

78
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

𝑠𝑠1,2 = −𝜉𝜉𝜔𝜔𝑛𝑛 ± 𝑗𝑗𝑗𝑗𝑛𝑛 �1 − 𝜉𝜉 2 (31)

Where:

𝐾𝐾𝑖𝑖 𝐾𝐾𝑃𝑃 𝐾𝐾𝑆𝑆


𝜔𝜔𝑛𝑛 = � (32)
𝑅𝑅𝑎𝑎 𝐽𝐽

And:

𝑅𝑅𝑎𝑎 𝐵𝐵 + 𝐾𝐾𝑖𝑖 𝐾𝐾𝑏𝑏


𝜉𝜉 = (33)
2�𝐽𝐽𝑅𝑅𝑎𝑎 𝐾𝐾𝑖𝑖 𝐾𝐾𝑃𝑃 𝐾𝐾𝑆𝑆

For such a second-order system, the important control theory metrics are: final value
(𝜃𝜃𝑠𝑠𝑠𝑠 ), percent overshoot (PO), rise time (𝑡𝑡𝑟𝑟 ), and 5% settling time (𝑡𝑡𝑠𝑠 ). Recall that the
following formulae are used to find these for underdamped systems:

𝜋𝜋𝜋𝜋

𝑃𝑃𝑃𝑃 = 100𝑒𝑒 �1−𝜉𝜉 2 (34)

1 − 0.4167𝜉𝜉 + 2.917𝜉𝜉 2
𝑡𝑡𝑟𝑟 = (35)
𝜔𝜔𝑛𝑛

4.0
𝑡𝑡𝑠𝑠 = , 𝜉𝜉 < 0.9 (36)
𝜉𝜉𝜔𝜔𝑛𝑛

3.7.2 Method for Fine-tuning Parameters and Subsequent Results

To fine-tune the robot arm model, we must increase 𝜉𝜉. Furthermore, ‘KS’ affects
the damping of the position response, but has no effect on the speed response. Based on
this, as well as the results from Table 22, we altered the motor parameters until the speed
responses matched, and the position responses had similar rise and settling times, with the
only difference being their overshoot levels (since they have the same shape, we considered
the real-life gear backlash and dead-zone effect as a type of overshoot correction, though
the graph did not actually cross the step input level). We then altered the ‘KS’ value until
the position response overshoot levels also matched. By this method, we obtained the

79
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

following graph of 𝜔𝜔(𝑡𝑡), with real and simulated results in red and blue respectively, below
in Figure 61.

Figure 61. Simulated and Actual Speed Responses after Fine-tuning, Robot Arm

And the following graph of 𝜃𝜃(𝑡𝑡), with real and simulated results in red and blue
respectively, below in Figure 62.

80
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 62. Simulated and Actual Position Responses after Fine-tuning, Robot Arm

3.7.3 Updated Parameters, Robot Arm

The updated arm parameters, with changes in bold, are shown below in Table 23.
Note that if these new values for the electrical characteristics are used for just the motor,
the motor-only responses still match closely with their models.

Table 23. Updated Robot Arm parameters

Parameter Value Unit


𝑹𝑹𝒂𝒂 2.150 Ω
𝑳𝑳𝒂𝒂 4.283 mH
𝑲𝑲𝒊𝒊 0.2500 𝐍𝐍 ∗ 𝐦𝐦/𝐀𝐀
𝑲𝑲𝒃𝒃 0.2400 𝐕𝐕 ∗ 𝐬𝐬
𝑩𝑩 0.001100 𝐍𝐍 ∗ 𝐦𝐦 ∗ 𝐬𝐬
𝝉𝝉 𝒐𝒐𝒐𝒐 𝝎𝝎(𝒕𝒕) 0.0862 𝐬𝐬𝐬𝐬𝐬𝐬𝐬𝐬𝐬𝐬𝐬𝐬𝐬𝐬
𝑱𝑱 0.002500 𝐤𝐤𝐤𝐤 ∗ 𝐦𝐦𝟐𝟐
𝑲𝑲𝑺𝑺 0.9500 𝑽𝑽/𝒓𝒓𝒓𝒓𝒓𝒓

81
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

____________________________________
4 PROJECT 3: ROBOT ARM
POSITION CONTROL
4.1 Updated Robot Arm Simulink® Model

We are now ready for the final project, the pick-and-place position control robot
arm. For this, we must also incorporate the gripper. We elect to release the payload when
the arm is within 2 percent of the end position. In this case, the end position is 𝟏𝟏𝟔𝟔𝟔𝟔°, so
the payload is released within 3 degrees of this position. Thus, our primary objective is a
percent overshoot of less than 2. A fast 2 percent settling time is a secondary objective.

To account for the closing and opening of the gripper, the Simulink model in Figure
56 must be updated. The robot arm Simulink model is shown below in Figure 63.

Figure 63. Simulink® Model for Robot Arm, updated to include gripper functionality

The only additions are the ‘Servo Encoder,’ ‘Servo Motor,’ ‘gripperPowerInput,’
and ‘Turn on system Input?’ blocks. The purpose of these additions is to tighten and release
the gripper when desired and to stop the arm from moving quickly at the same time that
the gripper is moving.

82
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

4.1.1 When to tighten and release the gripper Subsystem

The block titled ‘gripperPowerInput’ determines when to tighten the gripper, and
when to release it. The subsystem is shown in Figure 64 below with comments.

Figure 64. Simulink® Subsystem which determines when to tighten and release the gripper

This subsystem essentially tightens the gripper by a specific and sufficient amount
at the start point, waits until the arm is within 𝑡𝑡ℎ𝑟𝑟𝑟𝑟𝑟𝑟 𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑑𝑠𝑠 (2.0%) of the end point,
then releases the gripper by the same amount, to deliver the payload. It is desired that the
payload is dropped, as opposed to entering projectile motion due to superimposed rapid
arm motion.

4.1.2 When to turn on the system input Subsystem

The block titled “Turn on system Input?” sends out a value of either ‘1’ or ‘0’, which
is multiplied with the step degree input. This effectively determines when to turn on the
step degree input, and when to suppress it. The subsystem is shown below in Figure 65
with comments.

83
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 65. Simulink® Subsystem which waits until payload is fully gripped, and then always applies the
degree step input

This subsystem applies the step degree input as soon as the gripper has tightened,
and does not turn the input off after this point. The input must stay on if we want to have
feedback position control.

4.2 First Attempt

With the robot arm assembled, we apply a step input of 160° to it. We obtain the
following 𝜃𝜃(𝑡𝑡) graph, with simulation in blue and actual in red, in Figure 66 below.

Figure 66. Robot Arm Project, First Attempt

84
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

As we can see, the actual movement is very overdamped. The controller’s 𝑃𝑃, 𝐼𝐼, 𝐷𝐷,
and 𝑁𝑁 values are shown below in Table 24.

Table 24. First Attempt: 𝑃𝑃 = 1

P I D N
1 0 0 0

The results, which are calculated with reference to the graph, are as follows in Table
25.

Table 25. First Attempt Results

𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴 𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺 𝜽𝜽(𝒕𝒕) 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨 𝜽𝜽(𝒕𝒕)


𝜽𝜽𝒔𝒔𝒔𝒔 (°) 160 149
𝑷𝑷𝑷𝑷(%) 0.36 n/a
𝒕𝒕𝒓𝒓 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.43 0.61
𝟐𝟐% 𝒕𝒕𝒔𝒔 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.69 n/a
𝝃𝝃 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 0.8728 n/a
𝝎𝝎𝒏𝒏 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 6.6473 n/a
Payload Y N
delivered?

Our first attempt was not good enough, as the payload was not delivered. We will
now incorporate the PID control block shown in Figure 56.

4.3 Subsequent Attempts

We attempt the following configurations, and by calculating the control metrics


using the position graphs, obtain the following results.

Our second attempt PID controller values are shown in Table 26.

Table 26. Second Attempt: 𝑃𝑃 = 2

P I D N
2 0 0 0

The second attempt results are found experimentally in Table 27 (note that the
simulation results do not change).

85
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Table 27. Second Attempt Results

𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨 𝜽𝜽(𝒕𝒕)


𝜽𝜽𝒔𝒔𝒔𝒔 (°) 159
𝑷𝑷𝑷𝑷(%) 3.1
𝒕𝒕𝒓𝒓 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.27
𝟐𝟐% 𝒕𝒕𝒔𝒔 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.65
𝝃𝝃 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 0.6171
𝝎𝝎𝒏𝒏 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 9.4006
Payload Y
delivered?

Our third attempt PID controller values are shown in Table 28.

Table 28. Third Attempt: 𝑃𝑃 = 5

P I D N
5 0 0 0

The third attempt results are found experimentally in Table 29.

Table 29. Third Attempt Results

𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨 𝜽𝜽(𝒕𝒕)


𝜽𝜽𝒔𝒔𝒔𝒔 (°) 159
𝑷𝑷𝑷𝑷(%) 15
𝒕𝒕𝒓𝒓 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.21
𝟐𝟐% 𝒕𝒕𝒔𝒔 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.72
𝝃𝝃 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 0.3903
𝝎𝝎𝒏𝒏 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 14.864
Payload N
delivered?

Our fourth attempt PID controller values are shown in Table 30.

Table 30. Fourth Attempt: 𝑃𝑃 = 1.5

P I D N
1.5 0 0 0

The fourth attempt results are found experimentally in Table 31.

86
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Table 31. Fourth Attempt Results

𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨 𝜽𝜽(𝒕𝒕)


𝜽𝜽𝒔𝒔𝒔𝒔 (°) 158
𝑷𝑷𝑷𝑷(%) n/a
𝒕𝒕𝒓𝒓 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.34
𝟐𝟐% 𝒕𝒕𝒔𝒔 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.59
𝝃𝝃 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 0.7126
𝝎𝝎𝒏𝒏 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 8.1412
Payload Y
delivered?

Our fifth and final attempt PID controller values are shown in Table 32.

Table 32. Fifth Attempt: 𝑃𝑃 = 1.8

P I D N
1.8 0 0 0

The fifth and final attempt results are found experimentally in Table 33.

Table 33. Fifth Attempt Results

𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨 𝜽𝜽(𝒕𝒕)


𝜽𝜽𝒔𝒔𝒔𝒔 (°) 158
𝑷𝑷𝑷𝑷(%) 2.5
𝒕𝒕𝒓𝒓 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.30
𝟐𝟐% 𝒕𝒕𝒔𝒔 (𝒔𝒔𝒔𝒔𝒔𝒔) 0.60
𝝃𝝃 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 0.6505
𝝎𝝎𝒏𝒏 (𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕) 8.9182
Payload Y
delivered?

We show the arm’s position graph for the successful trials only in Figure 67 below.

87
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Figure 67. Successful Runs, Theta(t), Robot Arm Project

4.4 Conclusions

When considering percent overshoot, it is clear that we obtain the best results for a
𝑃𝑃 value of about 1.5~1.8. Since our goal is a percent overshoot (or error) of 2 percent or
less, and the steady-state error of the underdamped response is less than 2 percent, the best
position control is said to be obtained for 𝑷𝑷 = 𝟏𝟏. 𝟓𝟓.

4.5 Future Projects25

There are many additional experiments you can explore from here on. You can
attempt the robot arm once more using a variety of controllers, and select the best one based
on your design criteria, for example choosing 𝑃𝑃𝑃𝑃, 𝑃𝑃𝑃𝑃, 𝑃𝑃𝑃𝑃𝑃𝑃, or phase-lead controllers. You
can also design a motorized elevator system using pieces, a large motor, and push buttons,
all from the LEGO MINDSTORMS kit. A wide variety of controller designs, and control
system projects, can be conducted using a similar approach to that outlined in this Control
Lab. Also, note that in this lab we undertook a time response study of the system. You can
also conduct a root locus analysis, or a frequency response study of the system. Finally, in

25
For more on the different methods of analysis of control systems mentioned in Section 4.5, refer to F. Golnaraghi
and B. Kuo [3]

88
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
this lab we studied th,e system in the Laplace domain. You can also use the state-space
approach.

4.6 Summary

In this chapter, we discussed that, in a realistic system including an actuator (e.g., a


DC motor) and mechanical (gears) and electrical components (amplifiers), issues such as
saturation of the amplifier, friction in the motor, or backlash in gears would seriously affect
the controller design. This chapter focused on problems involving DC motors including
modeling, system identification, and controller design. We presented experiments on speed
and position response and control of DC motors, followed by a controller design project.
In design projects such as these, aside from the speed and position control topics, other
controllers such as PID may also be utilized. You may wish to become more acquainted
with these topics, by referring to this reference 26.

26
F. Golnaraghi and B. Kuo [3]

89
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

____________________________________
5 REFERENCES
1. F. Golnaraghi, “MSE 381 Laboratory Experiment,” Simon Fraser University,
Mechatronic Systems Engineering Program, British Columbia, Canada, Lab
Manual, 2018.

2. A. Marzouk, “MSE 110 LEGO® Lectures,” Simon Fraser University, School of


Mechatronic Systems Engineering, British Columbia, Canada, Class Lectures,
2018.

3. F. Golnaraghi and B. Kuo, Automatic Control Systems, 10th Edition, McGraw-Hill


Education, New York, United States of America, 2017, ISBN: 978-1-25-964383-5.

90
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

____________________________________
6 APPENDIX I: A METHOD FOR
FINDING 𝑱𝑱
Note that since we have six of the seven parameters, we can use Equation 8 to find
𝐽𝐽. You will find this approach more time-efficient and you may find it more accurate.
However, the experiment in this section for 𝐽𝐽 can be conducted, and then the result
compared to the value found from the equation, if you want to check how well your
parameters match with each other. For this experiment, first consider the motor’s
mechanical equation with no-load:

𝐽𝐽𝑚𝑚 ∗ 𝛼𝛼 + 𝐵𝐵𝑚𝑚 ∗ 𝜔𝜔 = 𝐾𝐾𝑖𝑖 ∗ 𝑖𝑖𝑎𝑎 (7 − 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 3)

When considering this equation for all time, we have the equation:

𝐽𝐽𝑚𝑚 ∗ 𝛼𝛼 (𝑡𝑡 ) + 𝐵𝐵𝑚𝑚 ∗ 𝜔𝜔(𝑡𝑡 ) = 𝐾𝐾𝑖𝑖 ∗ 𝑖𝑖𝑎𝑎 (𝑡𝑡) (7 − 𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟 4)

Where:

𝑑𝑑𝑑𝑑
𝛼𝛼 (𝑡𝑡 ) = (𝐴𝐴)
𝑑𝑑𝑑𝑑

Note that for all previous experiments, 𝜔𝜔 settled on a steady-state value, and for
most of the experiment, 𝛼𝛼 was zero, preventing us from using this equation to find 𝐽𝐽. Thus,
if we can make 𝛼𝛼(𝑡𝑡) a known non-zero function, where the functions 𝜔𝜔(𝑡𝑡) and 𝑖𝑖𝑎𝑎 (𝑡𝑡) are
also known, then we can use this equation to find 𝐽𝐽. We can use MATLAB to obtain 𝛼𝛼(𝑡𝑡)
and 𝜔𝜔(𝑡𝑡), however 𝑖𝑖𝑎𝑎 (𝑡𝑡) is difficult to find with the tools we have, with the only exceptions
being constant (where 𝛼𝛼(𝑡𝑡 ) = 0) or linear functions. To find 𝛼𝛼(𝑡𝑡) we must make 𝑖𝑖𝑎𝑎 (𝑡𝑡) a
linear function, wh,ereby we can take the initial (𝑖𝑖0 ) and final (𝑖𝑖𝑓𝑓 ) current values, and then:

𝑖𝑖𝑓𝑓 − 𝑖𝑖0
𝑖𝑖𝑎𝑎 (𝑡𝑡 ) = 𝑖𝑖0 + ∗ 𝑡𝑡 (𝐵𝐵)
𝑡𝑡𝑓𝑓 − 𝑡𝑡0

91
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

6.1 Current versus Power %

Since we deal with input power percentage and not input current, we must return to
the no-load experiments conducted for 𝐵𝐵, to find how 𝑖𝑖𝑎𝑎 (𝑡𝑡) relates to input power
percentage. The data is recalled for the motor only below in Appendix Table 1.

Appendix Table 1. Current versus Power %, Motor

Power (%) Current (A)


-100 -0.060
-90 -0.056
-80 -0.053
-70 -0.050
-60 -0.048
-50 -0.043
-40 -0.039
-30 -0.034
-20 -0.031
-10 -0.027
10 0.028
20 0.031
30 0.034
40 0.039
50 0.042
60 0.046
70 0.049
80 0.052
90 0.056
100 0.057
𝑹𝑹𝟐𝟐 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

With the graph shown in Appendix Figure 1 (where absolute values are taken).

92
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Appendix Figure 1. Current vs. % Power, Motor

The data is recalled for the robot arm in Appendix Table 2.

Appendix Table 2. Current versus Power %, Robot Arm

Power(%) Current(A)
-100 -0.076
-90 -0.072
-80 -0.066
-70 -0.062
-60 -0.059
-50 -0.055
-40 -0.045
-30 -0.046
-20 -0.042
-10 -0.038
10 0.044
20 0.049
30 0.050
40 0.056
50 0.055
60 0.059
70 0.065
80 0.069

93
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
90 0.075
100 0.078
𝟐𝟐
𝑹𝑹 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

With the graph shown in Appendix Figure 2 (where absolute values are taken).

Appendix Figure 2. Current vs % Power, Robot Arm

Thus, for both the motor only case and the robot arm case, the current is proportional
to the input power percentage. Thus, to input current as a linear function, we must input
power percentage as a linear function.

6.2 Velocity versus Power %

We must also understand what 𝜔𝜔(𝑡𝑡) will be if in the put power percentage is a ramp
function. We return to the experiments used to find 𝐵𝐵, to find how 𝜔𝜔(𝑡𝑡) relates to input
power percentage. The data is recalled for the motor only in Appendix Table 3 below.

Appendix Table 3. Velocity versus Power %, Motor

Power % 𝝎𝝎 (rad/sec)
-100 -14.661
-90 -12.915
-80 -11.519
-70 -10.123
-60 -8.7266
-50 -7.3304
-40 -5.9341

94
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
-30 -4.5379
-20 -3.1416
-10 -1.7453
10 1.7453
20 3.1416
30 4.5379
40 5.9341
50 7.3304
60 8.7270
70 10.123
80 11.519
90 12.915
100 14.486
𝟐𝟐
𝑹𝑹 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

With the graph shown in Appendix Figure 3 (where absolute values are taken).

Appendix Figure 3. Angular Velocity vs. % Power, Motor

The data is recalled for the robot arm below in Appendix Table 4.

95
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
Appendix Table 4. Velocity versus Power %, Robot Arm

Power(%) 𝝎𝝎 (rad/sec)
-100 -13.090
-90 -11.694
-80 -10.559
-70 -9.3375
-60 -8.0285
-50 -6.8068
-40 -5.4105
-30 -4.1888
-20 -2.8798
-10 -1.5708
10 1.4836
20 2.7925
30 4.1888
40 5.5850
50 6.8068
60 8.2030
70 9.4248
80 10.821
90 12.043
100 13.439
𝟐𝟐
𝑹𝑹 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗

With the graph shown in Appendix Figure 4 (where absolute values are taken).

96
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

Appendix Figure 4. Angular Velocity vs. % Power, Robot Arm

Thus, in both cases, 𝜔𝜔 is linear with input power percentage. Since the input power
is a ramp, 𝜔𝜔 will be a linear function. Thus we will have:

𝜔𝜔𝑓𝑓 − 𝜔𝜔0
𝜔𝜔(𝑡𝑡 ) = 𝜔𝜔0 + ∗ 𝑡𝑡 (𝐶𝐶)
𝑡𝑡𝑓𝑓 − 𝑡𝑡0

However, we also know that for a linear 𝜔𝜔(𝑡𝑡):

𝜔𝜔(𝑡𝑡 ) = 𝜔𝜔0 + 𝛼𝛼𝛼𝛼 (𝐷𝐷)

Thus, we know that:

𝜔𝜔𝑓𝑓 − 𝜔𝜔0
𝛼𝛼 = = 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 (𝐸𝐸)
𝑡𝑡𝑓𝑓 − 𝑡𝑡0

97
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

6.3 The equation for Finding 𝑱𝑱 Experimentally

Returning to the mechanical equation of the motor, Equation 7-revisited 4, and


replacing the functions with their known expressions, we have:

𝜔𝜔𝑓𝑓 − 𝜔𝜔0 𝑖𝑖𝑓𝑓 − 𝑖𝑖0


𝐽𝐽𝑚𝑚 ∗ 𝛼𝛼 + 𝐵𝐵𝑚𝑚 ∗ �𝜔𝜔0 + ∗ 𝑡𝑡� ≡ 𝐾𝐾𝑖𝑖 ∗ �𝑖𝑖0 + ∗ 𝑡𝑡 � (𝐹𝐹)
𝑡𝑡𝑓𝑓 − 𝑡𝑡0 𝑡𝑡𝑓𝑓 − 𝑡𝑡0

Since we know that this must be true for all 𝑡𝑡, we can compare coefficients, and we
have:

𝐽𝐽𝑚𝑚 ∗ 𝛼𝛼 + 𝐵𝐵𝑚𝑚 ∗ 𝜔𝜔0 ≡ 𝐾𝐾𝑖𝑖 ∗ 𝑖𝑖0 (𝐺𝐺)

In this way, we find 𝐽𝐽. However, there is one more thing to note. We will input both
a ramp power, with slope of 10 𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝/𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠, as well as a constant power of
40 𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝, and the ramp will be delayed until after the motor has reached steady-state for
40% input power. There are 2 reasons for this. First, when we averaged the value for 𝐵𝐵,
we only considered input powers at least as large as 50%. Therefore, we must stay in that
power range, to stay within the “linear” operating point of 𝐵𝐵𝑚𝑚 . Second, if the ramp power
was input straight away, the motor would be starting from rest, and would still have internal
friction and other effects to overcome, hence the likely presence of an unwanted “time
constant”. Thus, the ramp power is input after reaching a non-zero steady-state.

6.4 Moment of Inertia Simulink® Model

The Simulink model is shown in Appendix Figure 5 below.

Appendix Figure 5. Simulink® Model with constant and ramp inputs for J experiment

98
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018

6.5 Moment of Inertia Typical MATLAB® Graph

The 𝜔𝜔(𝑡𝑡) graph will look as shown below in Appendix Figure 6.

Appendix Figure 6. Angular velocity as a function of time, J experiment

With 𝑡𝑡0 = 1.065 as the end time of steady-state and stthe art of ramped power, and
with 𝑡𝑡𝑓𝑓 = 4.875 as the end time of ramped power.

6.6 Moment of Inertia, Motor

The results for the motor only are shown below in Appendix Table 5.

Appendix Table 5. Moment of Inertia Experimental Results, Motor

𝐾𝐾𝑖𝑖 = 0.2247 𝐵𝐵𝑚𝑚 = 0.01038


𝑷𝑷𝟎𝟎 𝑷𝑷𝒇𝒇 𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕 𝒊𝒊𝟎𝟎 𝒕𝒕𝟎𝟎 𝒕𝒕𝒇𝒇 𝝎𝝎𝟎𝟎 𝝎𝝎𝒇𝒇 𝜶𝜶 J
(%) (%) (sec) (A) 𝒊𝒊𝒇𝒇 (A) (sec) (sec) (rad/sec) (rad/sec) (rad/sec^2) (kg.m^2)
-40 -100 7.0 0.036 0.063 1.000 6.930 5.988 14.37 1.413491 0.001326

99
LEGO® MINDSTORMS® EV3® CONTROL LAB © Farid Golnaraghi
August 1, 2018
-40 -90 6.0 0.038 0.055 1.000 5.930 6.006 12.89 1.396349 0.00165
-40 -80 5.0 0.039 0.053 1.000 4.930 6.003 11.48 1.393639 0.001817
-40 -70 4.0 0.037 0.051 1.000 3.930 6.002 10.20 1.432765 0.001454
-40 -60 3.0 0.036 0.048 1.000 2.860 6.020 8.861 1.527419 0.001205
-40 -50 2.0 0.036 0.041 1.000 1.920 6.028 7.384 1.473913 0.001243
40 50 2.0 0.042 0.052 1.000 1.910 6.132 7.289 1.271429 0.002416
40 60 3.0 0.042 0.055 1.000 2.930 6.091 8.727 1.365803 0.002281
40 70 4.0 0.042 0.056 1.000 3.920 6.104 10.07 1.358219 0.002283
40 80 5.0 0.043 0.060 1.000 4.930 6.047 11.68 1.433333 0.002362
40 90 6.0 0.040 0.061 1.000 5.930 6.060 12.89 1.385396 0.001947
40 100 7.0 0.040 0.068 1.000 6.900 6.042 14.37 1.411525 0.001924
𝑱𝑱𝒎𝒎 = 0.001826
Standard Deviation = 0.000449

Thus, 𝑱𝑱𝒎𝒎 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝒌𝒌𝒌𝒌 ∗ 𝒎𝒎𝟐𝟐 .

6.7 Moment of Inertia, Robot Arm

The results for the robot arm are shown below in Appendix Table 6.

Appendix Table 6. Moment of Inertia Experimental Results, Robot Arm

𝐾𝐾𝑖𝑖 = 0.2247 𝐵𝐵𝑚𝑚 = 0.01448


𝑷𝑷𝟎𝟎 𝑷𝑷𝒇𝒇 𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕 𝒕𝒕𝟎𝟎 𝝎𝝎𝟎𝟎 𝝎𝝎𝒇𝒇 𝜶𝜶 J
(%) (%) (sec) 𝒊𝒊𝟎𝟎 (A) 𝒊𝒊𝒇𝒇 (A) (sec) 𝒕𝒕𝒇𝒇 (sec) (rad/sec) (rad/sec) (rad/sec^2) (kg.m^2)
-40 -100 7.0 0.054 0.110 1.000 6.870 5.997 14.19 1.395741 0.002472
-40 -90 6.0 0.055 0.098 1.000 5.895 6.086 12.62 1.334831 0.002656
-40 -80 5.0 0.052 0.087 1.000 4.890 5.997 11.28 1.358098 0.002210
-40 -70 4.0 0.048 0.082 1.000 3.825 5.997 9.845 1.362124 0.001543
-40 -60 3.0 0.056 0.077 1.000 2.895 5.997 8.592 1.369393 0.002848
-40 -50 2.0 0.051 0.060 1.000 1.890 6.086 7.160 1.206742 0.002194
40 50 2.0 0.051 0.071 1.000 1.890 6.131 7.071 1.056180 0.002445
40 60 3.0 0.052 0.075 1.000 2.895 5.997 8.592 1.369393 0.002191
40 70 4.0 0.053 0.083 1.000 3.825 5.997 9.935 1.393982 0.002314
40 80 5.0 0.052 0.086 1.000 4.875 6.086 11.28 1.340387 0.002143
40 90 6.0 0.054 0.095 1.000 5.895 5.997 12.80 1.389785 0.002483
40 100 7.0 0.056 0.107 1.000 6.870 5.997 14.14 1.387223 0.002811
𝑱𝑱𝒂𝒂𝒂𝒂𝒂𝒂 = 0.002359
Standard Deviation = 0.000352

Thus, 𝑱𝑱𝒂𝒂𝒂𝒂𝒂𝒂 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 𝒌𝒌𝒌𝒌 ∗ 𝒎𝒎𝟐𝟐 .

100

You might also like