UNLV Theses, Dissertations, Professional Papers, and Capstones
8-1-2014
Feedback Speed Control of a Small Two-Stroke
Internal Combustion Engine that Propels an
Unmanned Aerial Vehicle
Paul D. Fjare
University of Nevada, Las Vegas, pfjare@gmail.com
Follow this and additional works at: http://digitalscholarship.unlv.edu/thesesdissertations
Part of the Acoustics, Dynamics, and Controls Commons, and the Navigation, Guidance,
Control and Dynamics Commons
Repository Citation
Fjare, Paul D., "Feedback Speed Control of a Small Two-Stroke Internal Combustion Engine that Propels an Unmanned Aerial
Vehicle" (2014). UNLV Theses, Dissertations, Professional Papers, and Capstones. 2179.
http://digitalscholarship.unlv.edu/thesesdissertations/2179
This Thesis is brought to you for free and open access by Digital Scholarship@UNLV. It has been accepted for inclusion in UNLV Theses, Dissertations,
Professional Papers, and Capstones by an authorized administrator of Digital Scholarship@UNLV. For more information, please contact
digitalscholarship@unlv.edu.
FEEDBACK SPEED CONTROL OF A SMALL TWO-STROKE
INTERNAL COMBUSTION ENGINE THAT PROPELS
AN UNMANNED AERIAL VEHICLE
by
Paul D. Fjare
Bachelor of Science in Mechanical Engineering
University of Nevada, Las Vegas
A thesis submitted in partial fulfillment
of the requirements for the
Master of Science in Engineering - Mechanical Engineering
Department of Mechanical Engineering
College of Engineering
The Graduate College
University of Nevada, Las Vegas
August 2014
THE GRADUATE COLLEGE
We recommend the thesis prepared under our supervision by
Paul D. Fjare
entitled
Feedback Speed Control of a Small Two-Stroke Internal Combustion
Engine that Propels an Unmanned Aerial Vehicle
is approved in partial fulfillment of the requirements for the degree of
Master of Science in Engineering - Mechanical Engineering
Department of Mechanical Engineering
William Culbreth, Ph.D., Committee Chair
Robert Boehm, Ph.D., Committee Member
Woosoon Yim, Ph.D., Committee Member
Sahjendra Singh, Ph.D., Graduate College Representative
Kathryn Hausbeck Korgan, Ph.D., Interim Dean of the Graduate College
August 2014
ii
Abstract
Unmanned aerial vehicles (UAV) require intelligent control of their power source. Small
UAV are typically powered by electric motors or small two-stroke internal combustion (IC)
engines. Small IC engines allow for longer flight times but are more difficult to control and
cause significant ground noise. A hybrid operation that uses the engine at high altitudes
and the electric motors at low altitudes is desired. This would allow for extended flight with
acceptable ground noise levels. Since the engine can not be restarted in the air it must be
able to remain at idle for an extended time without stalling. A feedback controller is created
for an OS160FX carbureted two-stroke engine. The controller implements a ProportionalIntegral-Derivative (PID) algorithm to regulate the rotational speed of the engine shaft.
The controller also monitors the temperature of the engine and is capable of monitoring
the altitude of the aircraft. It is constructed with commercially available components and
is based on an open-source micro-controller. The engine and the controller were ground
tested to determine the engine’s performance characteristics and the appropriate tuning
parameters of the PID algorithm. The controller allows the engine to idle at 1800 rpm
without stalling. The controller is able to quickly respond to changes in the commanded
speed and settle on this speed within 10 seconds. The speed is regulated through the
engine’s full range of speeds. The performance of the controller was found to be negatively
affected by sub-optimal carburetor fuel-valve settings.
iii
Acknowledgments
First, I would like to thank my parents for encouraging my education and supporting me
in all my endeavors. Next, I would like to thank my research advisor, Dr. Culbreth, for
giving me the opportunity to work on this project. Also, I would like to thank Dr. Boehm,
Dr. Singh, and Dr. Yim for serving on my committee.
A special thank you to my father for assisting me. I would not have completed this
research without his help.
iv
Table of Contents
Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii
Nomenclature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Research Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Research Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1
2
3
2 Literature Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1 Engine Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.1 Two-Stroke Engines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.2 Scavenging Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.3 Carburetor Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.4 Ignition Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.5 Glow Engines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Control Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.1 PID Control Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.2 Proportional Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.3 Integral Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.4 Derivative Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.5 Modifications of the PID Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.6 Algorithm Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
6
6
8
8
10
11
11
13
13
14
15
15
17
3 Experimental Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1 Control System Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Controller Software and PID Algorithm Implementation . . . . . . . . . . . . . . . . . . .
3.2.1 Serial Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2.2 Automatic Control Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Break-in Engine and Tune Carburetor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.1 Carburetor and Fuel System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.2 Start-up Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.3 Break-in Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.4 Tuning Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4 Throttle and Speed Relationship . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4.1 Sensitivity to Carburetor Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5 Performance Measures and Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.6 Selection of PID Tuning Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
21
25
25
26
28
28
30
31
32
33
37
38
40
v
4 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.1 Long Term Reference Following . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Setpoint Weighting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3 Bumpless Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4 Idle performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5 Disturbance Rejection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.6 Control Variable Saturation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.7 Engine Temperature Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.8 Controller Sensitivity to Carburetor Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
50
53
53
54
55
56
57
58
59
5 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6 Future Work and Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Appendix A Additional Test Response Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Appendix B Controller Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Appendix C Exploded View of Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Appendix D Micro-controller Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100
CV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101
vi
List of Tables
Table
Table
Table
Table
Table
3.1
3.2
3.3
3.4
3.5
Performance Measures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Steps of Reference Path A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Response performance with Ki = 0.000030. . . . . . . . . . . . . . . . . . . . . . . . . .
Response performance with Ki = 0.000045. . . . . . . . . . . . . . . . . . . . . . . . . .
Response performance with Ki = 0.000050 and 0.000055. . . . . . . . . . . . .
vii
40
41
43
43
45
List of Figures
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
Figure
2.1
2.2
2.3
2.4
2.5
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
3.10
3.11
3.12
3.13
3.14
3.15
3.16
3.17
3.18
3.19
3.20
3.21
3.22
3.23
3.24
3.25
3.26
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
4.10
4.11
Sequence of events in a two-stroke engine cycle from [5]. . . . . . . . . . . . .
Basic carburetor from [7]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Open loop system vs. a closed loop system from [9]. . . . . . . . . . . . . . . . .
Typical feedback control block diagram adapted from [10]. . . . . . . . . . .
P-term response from [9]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
OS160FX Engine from [11]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Engine test stand. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Diagram of the control system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Engine controller housing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Servo and throttle arm linkage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
High-speed needle valve (HSN). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Low-speed needle valve (LSN). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Engine fuel system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Demonstrated use of electric starting motor. . . . . . . . . . . . . . . . . . . . . . . .
Glow plug location. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Throttle Step Test A. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Throttle Step Test B. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Gradual speed drop following a negative throttle step. . . . . . . . . . . . . . .
Relationship between throttle and speed. . . . . . . . . . . . . . . . . . . . . . . . . . .
Process gain at different operating points. . . . . . . . . . . . . . . . . . . . . . . . . .
Performance variations due to different carburetor settings. . . . . . . . . . .
Reference speed test paths. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Response with Ki = 0.000045 and no Kp . . . . . . . . . . . . . . . . . . . . . . . . . .
Response with Ki = 0.000030 and no Kp . . . . . . . . . . . . . . . . . . . . . . . . . .
Response with Kp = 0.080 and Ki = 0.000030. . . . . . . . . . . . . . . . . . . . . .
Response with Kp = 0.080 and Ki = 0.000045. . . . . . . . . . . . . . . . . . . . . .
Response with Kp = 0.060 and Ki = 0.000050. . . . . . . . . . . . . . . . . . . . . .
Response with Kp = 0.065 and Ki = 0.000050. . . . . . . . . . . . . . . . . . . . . .
Response with Kp = 0.070 and Ki = 0.000050. . . . . . . . . . . . . . . . . . . . . .
Response with Kp = 0.080 and Ki = 0.000050. . . . . . . . . . . . . . . . . . . . . .
Response with Kp = 0.080 and Ki = 0.000055. . . . . . . . . . . . . . . . . . . . . .
Response to Reference Path A with Kp = 0.065 and Ki = 0.000050. . .
Response to Reference Path B with Kp = 0.065 and Ki = 0.000050. . .
Response to Reference Path C with Kp = 0.065 and Ki = 0.000050. . .
Response to Reference Path D with Kp = 0.065 and Ki = 0.000050. . .
Long term reference speed tracking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Response with setpoint weight of 0.20. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Successful bumpless transfer from manual to automatic control. . . . . . .
Controller performance with reference speed of 1800 rpm. . . . . . . . . . . .
Disturbance in the form of an emptying fuel tank. . . . . . . . . . . . . . . . . . .
Control variable saturation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Engine temperature during a Reference Path A test . . . . . . . . . . . . . . . .
viii
7
9
11
12
14
20
21
22
23
24
29
29
30
31
31
34
34
35
36
37
38
39
42
42
44
45
46
46
47
47
48
50
51
52
52
53
54
55
56
57
58
59
Nomenclature
AFR Air-to-fuel ratio.
HSN High-speed needle valve.
IC Internal combustion.
IRE Infrared reflectance encoder.
ISR Interrupt service routine.
LSN Low-speed needle valve.
MAX6675 MAX6675 K-Thermocouple-to-Digital Converter.
MC1 Arduino Duemilanove micro-controller.
MC2 Arduino Mega 2560 micro-controller.
MPL115A1 MPL115A1 barometric pressure sensor.
OS160FX O.S. Engines 160FX glow engine.
PID Proportional-Integral-Derivative.
UAV Unmanned aerial vehicle.
ix
1
Introduction
1.1
Background
In recent years there have been efforts to develop small unmanned aerial vehicles (UAV)
capable of extended flight. UAV have piloting systems with embedded intelligence that
determines the trajectory of the aircraft [1]. The piloting system or auto-pilot sends the
appropriate commands to the aircraft’s power source required to maintain the desired flight
speed. Small aircraft typically rely on propeller propulsion that is powered by electric
motors or small internal combustion (IC) engines.
Electric motors have the advantage of simple control, quiet operation, and low
maintenance. Small IC engines allow for longer flight times than electric motors but are
more difficult to control.
Their performance is dependent on ambient temperature,
altitude, and fuel flow. They also generate significant ground noise and require regular
maintenance.
A UAV was developed at the University of Nevada, Las Vegas through a 2007 research
grant from the Air Force Research Laboratory [1]. The UAV can be powered by a single
small two-stroke diesel engine or by two small electric motors. The current piloting system
on the UAV sends operating commands to the engine in the form of throttle position. The
next step in this research is to design and build a digital feedback controller that can bring
the engine to a rotational speed commanded by the auto-pilot and maintain that speed.
At high altitudes the ground noise generated by an engine is less than at low altitudes.
1
A hybrid operation that uses an IC engine at high altitudes and switches to the electric
motors at low altitudes would potentially allow for acceptable ground noise levels and
extended flight. The IC engines on small aircraft typically are started by hand and can not
be re-started in flight. This means that the engine must run at idle while the electric motors
are operating. The engine is at idle when it is rotating at its lowest running speed. At this
speed the engine does not produce significant thrust. The noise created by the engine is
significantly lower when idling then when running at high speeds so this is an acceptable
operation. This hybrid operation requires an engine that will run steadily at low speeds
without stalling. The new engine controller should allow for this hybrid operation.
1.2
Research Objectives
The main objective of this research was to build and implement an inexpensive digital
feedback controller that regulates the speed of a small two-stroke IC engine that propels a
small UAV. The representative engine was the O.S. Engines 160FX (OS160FX)
carbureted two-stroke engine that is popular in the recreational aircraft community. It
was desired that the controller hardware be based on commercially available parts that
can be adapted for use on engines comparable to the OS160FX. The controller software
and the implemented control algorithm were to be written so that they could easily be
adapted by future operators. The requirements for the engine controller were that it allow
the engine to quickly and reliably change to a desired speed and maintain that speed
within a defined tolerance. Another requirement for the engine controller was that it allow
2
the engine to idle for an extend period without stalling.
The controller also had to
monitor the temperature of the engine and the altitude of the aircraft.
A secondary objective was to determine the sensitivity of the controller to carburetor
settings. The carburetor on the OS160FX and other small two-stroke engines is typically
adjusted or ‘tuned’ manually in the field.
These tunings are crude and require an
experienced operator to perform. Minor adjustments can cause significant variations of
the engine’s performance characteristics.
1.3
Research Methodology
The first step to achieving the research goals was to set up a facility to test the engine
on the ground. For this research the engine was not tested on an aircraft in flight. The
facility chosen was a garage area that had adequate ventilation. A test stand was built that
supports the engine, fuel tank, and controller hardware.
The next step was to set up a control system that could adjust the engine’s throttle and
monitor the engine’s performance. The control system consisted of the engine controller
and a ground station that communicated wirelessly. The engine controller was based on
an Arduino micro-controller which read the sensors, implemented the control algorithm,
and sent a control signal to a small DC servo motor that served as the throttle actuator.
The throttle position was set manually by entering commands in a laptop computer or was
determined by the control algorithm. The sensor values were printed to a small LCD screen
so the engine could be monitored in real-time. The sensor values and other data related to
3
the control algorithm were logged for analysis.
After the control system was in place, the engine was put through a ‘break in’ period that
is required of new engines and the carburetor fuel valves were adjusted or ‘tuned’ to provide
optimal performance. The break-in period involved running the engine at low-speeds for
short periods of time. The speed and run-time were gradually increased as the engine ran
through several tanks of fuel. The purpose of the break-in period was to allow the engine
parts to settle together. Once the break-in period was completed the carburetor could be
tuned for optimal engine performance. The fuel valves were set so the engine could reach
high-speeds without overheating, have smooth acceleration throughout the speed range, and
idle reliably.
After the carburetor was tuned, the engine’s performance characteristics were
determined. The performance characteristics were determined by recording and analyzing
the response of the engine speed to changes in the throttle position. The test results with
different carburetor tunings were used to determine the variability in engine performance
that results from imprecise carburetor adjustments.
Next,
the control algorithm was written,
implemented,
and tested.
A
Proportional-Integral-Derivative (PID) algorithm was chosen because it can be
implemented with inexpensive micro-controllers and it is a widely adopted and proven
control method. There are three tuning parameters of the PID algorithm that must be
carefully chosen for the controller to provide acceptable control of a dynamic process.
Tests were run with different combinations of these parameters to determine a suitable
4
setting for each parameter.
5
2
Literature Review
2.1
Engine Theory
An internal combustion (IC) engine converts chemically bound fuel energy into mechanical
energy [2]. In an IC engine the combustion of an air-fuel mixture in a combustion chamber
and the resulting expansion of high-pressure gases drives a piston that oscillates in a
cylinder. The piston is attached to a connection rod and crankshaft linkage that translates
the reciprocating motion of the piston to the angular rotation of an output shaft [3]. On
an aircraft engine the output shaft is connected to a propeller to generate thrust [4].
The first type of IC engine is a four-stroke engine. In a four-stroke engine there are four
strokes of the piston required to complete a cycle. Each stroke performs a different function
of the cycle. The functions of an engine cycle are intake, compression, power, and exhaust.
The second type of IC engine is two-stroke engine which completes the cycle functions in
just two strokes of the piston. The two-stroke engine is smaller and simpler in operation
than the four-stroke engine and produces an equivalent amount of power [5].
2.1.1
Two-Stroke Engines
The sequence of events that occur in a typical two-stroke cycle are shown in Figure 2.1. The
cycle starts with the intake of air and fuel that have been mixed with the carburetor. As
the piston is traveling upward there is a drop in crankcase pressure. The air-fuel mixture
from the carburetor, driven by the difference between atmospheric and crankcase pressures,
enters the crankcase. This air-fuel mixture remains in the crankcase until the piston opens
6
Figure 2.1: Sequence of events in a two-stroke engine cycle from [5].
up the transfer port on the down-stroke. Once the transfer port is open the air-fuel mixture
in the crankcase, which has been compressed by the piston, rushes into the combustion
chamber. This mixture is further compressed during the upstroke of the piston until it
ignites due to the heat of compression or spark ignition. The combustion of the air-fuel
mixture produces high pressure gases that expand rapidly and force the piston downward.
As the piston moves downward it uncovers the exhaust port which allows the products of
combustion to exit the chamber. The compression and intake functions both occur on the
up stroke while the power and exhaust function both occur on the down stroke or power
stroke [5].
7
2.1.2
Scavenging Theory
The process of pushing out exhaust gases and drawing in a fresh air-fuel mixture is called
scavenging.
In a properly scavenged engine all exhaust gases are pushed out of the
combustion chamber and a fresh air-fuel mixture is drawn in from the crankcase. The two
main types of scavenging configurations are cross-scavenging and loop-scavenging. On a
cross-scavenged engine the transfer port is positioned directly across from the exhaust
port. A baffle on the piston head deflects the air-fuel charge upward to prevent it from
flowing directly out the exhaust port [5]. There is significant mixing between the exhaust
gases and the fresh air-fuel mixture in cross-scavenged engines and some exhaust gases
remain in the combustion chamber. A loop-scavenged engine directs the incoming air-fuel
mixture in a looping path that pushes the exhaust gases out of the combustion chamber
with less mixing than a cross-scavenged engine. One type of loop-scavenging is Schnuerle
scavenging. A Schnuerle scavenged (ported) engine has two transfer ports angled away
from the exhaust port that direct the air flow upward in a looping path. Some Schnuerle
scavenged engines have an additional boost-port opposite the exhaust port [6].
2.1.3
Carburetor Theory
Small two-stroke engines typically use a carburetor to prepare the air-fuel mixture that
enters the engine crankcase. A diagram of a basic carburetor is shown in Figure 2.2. There
are many carburetor designs of varying complexity but the general concept is as follows. A
throttle valve controls the mass flow rate of air through the carburetor inlet. The intake air
8
flows through a converging-diverging nozzle called a venturi which increases the air velocity.
The higher air velocity corresponds with a drop in pressure. The pressure difference created
between the air inlet and the throat of the venturi draws in fuel through a discharge port
near the throat distributing the fuel across the air flow. The pressure difference, which
depends on the air flow rate, is used to regulate the fuel flow. A higher air flow rate will
Figure 2.2: Basic carburetor from [7].
cause a rise in the pressure difference. Thus a carburetor provides a different air-to-fuel
ratio (AFR) at different speeds and operating conditions. The stochiometric ratio is the
AFR that provides just enough air in the mixture for complete combustion of the fuel. An
AFR below the stochiometric ratio is considered ‘rich’ and an AFR above the stochiometric
ratio is considered ‘lean’. A basic carburetor can not provide an optimal AFR over the
whole engine load range [3]. Since most two-stroke engines use the fuel for lubrication and
coolant the AFR is kept rich. The typical carburetor on a small aircraft engine has fuel
valves that must be tuned correctly to provide acceptable performance through the entire
speed range.
9
2.1.4
Ignition Theory
There are three main types of engines used in small aircraft: spark-ignition, compression
ignition, and glow ignition. Spark ignition engines trigger combustion by activating an
electric discharge in a spark plug . A gasoline engines rely on spark ignition. Compression
ignition engines compress the air so intensely that the temperature generated is greater than
the ignition temperature of the fuel. The diesel engine cycle utilizes compression ignition
[2].
Glow-ignition engines run on a nitromethane-methanol blend of fuel with an ignition
temperature that cannot be reached through compression alone. A glow plug located at
the top of the combustion chamber is utilized to help ignite the air-fuel mixture. When an
electric current is applied to a glow plug, a platinum coiled-wire element incandesces and
produces temperatures that exceed 1,500 degrees Fahrenheit. During the engine operation
there is an exothermic reaction that takes place between the platinum in the coil and
methanol vapor that further increases the temperature of the coil. The engine is started
by turning the engine by hand or with an electric starting motor. The combination of the
glow plug and the compression of the mixture causes ignition. Once the engine has been
started the electric current can be removed and the engine will continue to fire due to the
heat from the exothermic reaction [8].
The fuel requirement of an engine depends on its ignition method. Compression engines
require a fuel that is highly ignitable. Spark ignition engines require a fuel that is ignition
resistant so that auto-ignition does not cause uncontrolled combustion [2].
10
2.1.5
Glow Engines
The test engine used in this study is a carbureted, glow-ignition, Schnuerle ported, twostroke engine. This type of engine will be referred to as a ‘glow engine’. Glow engines are
commonly used on small aircraft because they are small, lightweight, simple in operation,
and provide satisfactory performance.
2.2
Control Theory
The engine controller designed and implemented in this research implements ProportionalIntegral-Derivative (PID) control which is a form of feedback control. A feedback control
system makes corrective actions based on the difference between a desired quantity of a
dynamic process and the actual measured quantity. A feedback control system is a closed
loop system. A closed-loop system consists of two (or more) systems that are interconnected
in a cycle. If there is no interconnection the system is an open-loop system. Figure 2.3
shows the idea of an open-loop system and a closed-loop system. In the closed-loop system
the output of system one is the input of system two and the output of system 2 is the input
of system one. In an open-loop system the first system is not affected by the second [9].
u
System 1
r
y
u
System 1
System 2
(a) Closed loop
System 2
(b) Open loop
Figure 2.3: Open loop system vs. a closed loop system from [9].
In a typical feedback control system the two systems are the controller and the
11
process. Feedback control is necessary to account for disturbances and changes in the
process dynamics [10]. A classic example of feedback control is the cruise control system
found in modern cars. The purpose of a cruise control system is to maintain a speed set
by the driver.
It maintains this speed by varying the throttle.
The correct throttle
position is determined by considering the difference between the reference speed and the
actual measured value of speed [9]. Manual control of the throttle (gas pedal) would be an
example of open-loop control.
d
r
e
+
Controller
u
Actuator
Process
y
-
Sensor
Figure 2.4: Typical feedback control block diagram adapted from [10].
Figure 2.4 shows the block diagram of a typical feedback controller where y is the
measured process variable (process output), r is the reference variable, e = r − y is the
control error, u is the control variable, and d is a disturbance signal. The reference variable
is often called the setpoint. The controller determines the value of the control variable that
will bring the process variable to the value of the reference variable and maintain that value
despite unplanned or unmeasured disturbances.
12
2.2.1
PID Control Algorithm
A PID controller is a three-term controller that has become the standard feedback controller
in commercial industries. PID controllers have been widely adopted because they provide
satisfactory performance while being intuitive and relatively simple. PID controllers are
often the fundamental component of more advanced control schemes [10].
The PID algorithm consists of three terms: the proportional term (P-term), the integral
term (I-term), and the derivative term (D-term). The terms are summed to determine
the value of the control variable. The proportional, integral, and derivative terms can be
thought of as acting on the current, past, and future error respectively. Each term of this
algorithm will be discussed in detail. The full continuous-time form of the PID algorithm
is:
Z
u(t) = Kp e(t) + Ki
t
e(τ )dτ + Kd
0
de(t)
dt
(2.1)
Z
de(t)
1 t
e(τ )dτ + Td
= Kp e(t) +
Ti 0
dt
The parameters of the PID algorithm are the proportional gain Kp , the integral gain Ki ,
and the derivative gain Kd . Sometimes the parameters of integral time Ti and derivative
time Td are used instead of integral and derivative gain [9].
2.2.2
Proportional Term
Kp e(t)
13
(2.2)
The proportional term shown in Equation 2.2 is proportional to the current control error.
It acts to increase or decrease the control variable in attempt to limit the future error.
The proportional term is able to provide a small control variable change when error is
small to avoid excessive effort from the actuator. The proportional gain determines how
aggressively the proportional term responds to an error. Figure 2.5 shows a simulated
response of a system with proportional control. It shows that the proportional term by
K = 5
K = 2
1
K = 1
0
0
5
10
15
20
Figure 2.5: P-term response from [9].
itself will always produce a steady-state error. A high proportional gain will give a result in
a quick response to a reference change but if the proportional gain is too high the controller
will become unstable. The steady state error is eliminated by adding the integral term [10].
2.2.3
Integral Term
Z
Ki
t
e(τ )dτ
(2.3)
0
The integral term is shown in Equation 2.3. It is proportional to the integral, or continual
summation, of the control error over time. It allows the controller to account for any
unexpected or unmeasured disturbances and eliminates the steady-state error. If there is a
positive error the integral term will increase until the error is zero. A negative error causes
14
the integral term to decrease. A large integral gain will allow for effective attenuation of
disturbances but too large of an integral gain will cause oscillations in the process and
control variables [10].
2.2.4
Derivative Term
Kd
de(t)
dt
(2.4)
The derivative term is shown in Equation 2.4. It is proportional to the derivative or rate of
change of the control error. The rate of change of the error can offer a prediction of error.
The derivative term has the potential to anticipate an incorrect trend in control error and
counter it. The derivative term is used to dampen an oscillatory system. The greater the
derivative gain the more damped the system becomes but performance will deteriorate if it
is too high [10].
2.2.5
Modifications of the PID Algorithm
A controller that implements the PID Algorithm as shown in Equation 2.1 will likely not
perform well. There are several issues with this standard from that must be addressed to
ensure a well performing controller [10].
The first issue that is commonly faced is a phenomenon known as integral wind-up.
Recall that the integral term sums the error history. Integral wind-up occurs when the
control variable attains the actuator limit (saturation) during a transient response. When
the controller is saturated the control error does not decrease as fast as it would otherwise.
15
This causes the integral term to become large or wind up. This large integral term causes
the controller to stay saturated even if the process variable has attained the set-point value
leading to large overshoots and settling times. There are several strategies used to deal
with integral wind-up. One of which is to disable integration when the control variable
saturates. A modification of this strategy is to only stop integration when the control
variable and control error have the same sign. This allows the integral term to help bring
the control variable out of saturation. The issue of integral wind-up is not an issue when
the incremental form of the algorithm is used [10]. The incremental algorithm is explained
in Section 2.2.6
Another issue is that proportional gains required for fast disturbance rejection cause an
oscillatory response following a step change in the reference variable. A strategy for dealing
with this is to define the proportional term as follows:
u(t) = Kp (βr(t) − y(t))
(2.5)
where β is a weighting factor between 0 and 1. The weighting factor is applied to the
reference variable so that the proportional gain acts on only part of the control error during
the step change. Setpoint weighting acts to smooth the step change of the reference variable
to damp the response of the process variable[10].
While the derivative term can improve the controller performance there are critical
issues that cause it to not be frequently used. More than 80% of today’s PID controllers
16
are actually PI controllers [10]. Since the derivative term responds to the rate of change of
error an abrupt reference variable change will cause the derivative to term to be large. This
causes an undesired spike of the control output during a reference variable step. This spike
is known as derivative kick. Derivative kick is solved by applying the derivative term to the
process variable instead of control error. This is referred to as derivative on measurement.
It is shown below that when the reference variable is constant that derivative of the error
is equal to the negative of the derivative of the process variable.
d(r(t) − y(t))
de(t)
=
dt
dt
de(t)
d(0 − y(t))
dy(t)
=
=−
dt
dt
dt
(2.6)
The derivative term also amplifies measurement noise in the manipulated variable. This
noise can result in rapid changes of the control variable that can damage the actuator [10].
The PID algorithm with derivative on measurement and setpoint weighting is
u(tk ) = Kp
2.2.6
1
βr(tk ) − y(tk ) +
Ti
Z
0
t
dy(t)
e(τ )dτ − Td
dt
(2.7)
Algorithm Discretization
The algorithm must be transformed to a discrete form so that it can be implemented
with a digital controller. The discrete form of Equation 2.7 can be found by applying the
backwards finite difference method to the derivative and integral terms [10]. The backwards
finite difference method is a common discretization technique. The proportional term is
17
discretized by replacing the continuous variables with their sampled versions. The integral
is expressed as a sum of the error history.
Z
t
e(τ )dτ =
k
X
0
e(ti )∆t
(2.8)
i=1
where e(ti ) is the error at the current iteration and ∆t is a predefined sample time. The
derivative term becomes:
e(tk ) − e(tk−1 )
de(t)
=
dt
∆t
(2.9)
where tk is the the current sampling instant, and tk−1 is the previous sampling instant. The
discrete form of equation 2.7 is
u(tk ) = Kp
!
k
∆Td
∆t X
(y(tk ) − y(tk−1 ))
e(ti ) −
βr(tk ) − y(tk ) +
Ti
∆t
(2.10)
i=1
As an alternative to equation 2.10 the control variable at time instant u(tk ) can be calculated
using its value at the previous time instant u(tk−1 ) [10]. Subtracting u(tk−1 ) from u(tk ):
!
k
∆t X
∆Td
e(ti ) −
(y(tk ) − y(tk−1 ))
u(tk ) − u(tk−1 ) = Kp βr(tk ) − y(tk ) +
Ti
∆t
i=1
!
k−1
∆t X
∆Td
− Kp βr(tk−1 ) − y(tk−1 ) +
e(ti ) −
(y(tk−1 ) − y(tk−2 )) (2.11)
Ti
∆t
i=1
18
This can be re-written as:
u(tk ) = u(tk−1 ) + Kp (βr(tk ) − βr(tk−1 ) + y(tk−1 ) − y(tk ))
+ Ki ∆te(tk ) +
Kd
(2y(tk−1 ) − y(tk ) − y(tk−2 ))
∆t
(2.12)
Equation 2.12 is the incremental form of the PID algorithm. It is also known as the velocity
form. The incremental form avoids the issue of integral windup and allows for bumpless
transfer [15].
19
3
Experimental Setup
The engine used in this research is a 160FX glow engine manufactured by O.S. Engines
(OS160FX). The OS160FX has a 1.6 cubic inch displacement with a power output of 3.7
horsepower at 9,000 rpm. The engine weight with muffler is 42.3 ounces. The engine has
a listed practical speed range of 1,800 rpm to 10,000 rpm [11]. The actual speed range is
dependent on fuel and the pitch and diameter of the propeller. The engine was fitted with
a 17 inch plastic propeller with a 5 inch pitch.
Figure 3.1: OS160FX Engine from [11].
A temporary facility was prepared for testing the engine. The chosen test facility was
a well ventilated garage area. A test stand was constructed and secured to the floor of the
test facility. The test stand was constructed from wood and can easily be disassembled for
transport. The top surface was covered in aluminum sheeting for easy oil cleanup. The
assembled engine, fuel tank, and controller hardware were mounted to the test stand. A 12
volt battery was placed under the test stand to provide power for the controller hardware.
The test stand with installed equipment is shown in Figure 3.2.
20
Figure 3.2: Engine test stand.
3.1
Control System Setup
A control system was designed and built to control the engine and monitor its performance.
The control system consists of the engine controller and a ground station that communicates
with the engine controller and records data. The engine controller measures the rotational
speed of the engine shaft, the engine head temperature, and the barometric pressure. It
uses a servo motor to adjust the engine throttle. The components of the control system are
listed below.
•
•
•
•
•
•
•
•
•
•
Arduino Duemilanove micro-controller (MC1)
Arduino Mega 2560 micro-controller (MC2)
Infrared reflectance encoder (IRE)
K-type thermocouple wire
MAX6675 K-Thermocouple-to-Digital Converter (MAX6675)
MPL115A1 barometric pressure sensor (MPL115A1)
Hitec HS-5125MG digital servo
XBee radio modules
20x4 Character LCD Screen
Laptop computer
21
The Arduino Duemilanove micro-controller (MC1) takes readings from the sensors and
implements the control algorithm. The MC1 sends sensor values and control algorithm data
to the Arduino Mega 2560 micro-controller (MC2). The two micro-controllers communicate
wirelessly with a pair of XBee radio modules. The MC2 is connected to a laptop computer
and relays commands that are entered in the computer’s serial monitor to the MC1. The
MC2 also prints data received from the MC1 to a file and displays select data on the LCD
screen. A diagram of this control system is shown in Figure 3.3. A schematic of the sensor
connections to the MC1 is in Appendix B.
Figure 3.3: Diagram of the control system.
The engine controller is comprised of the MC1, the sensors, and the servo motor. The
ground station is comprised of the MC2, the LCD screen, and the laptop computer. The
MC1 has 14 digital input/output pins, 6 analog input pins, and a 16 MHz crystal oscillator
[12]. Figure 3.4 shows the wiring in the engine controller housing.
22
Figure 3.4: Engine controller housing.
The throttle position was adjusted with the Hitec HS-5125MG digital servo. Servos are
small DC motors with internal circuitry that provides fine control of angular position. The
position is set by sending a digital square wave signal with a specific pulse-width to the
servo with a micro-controller. The pulse-width can be specified in microsecond increments.
The Hitec HS-5125MG has a 90° total range. This angle range corresponds to a pulse-width
range of 900 to 2100 microseconds [13]. The angular precision of the servo is 0.0750 degrees.
The engine throttle does not require the entire range of the servo. The throttle is fully closed
at 1810 microseconds and fully open at 1300 microseconds. This gives a throttle precision
of 0.2 percent. Figure 3.5 shows the servo and throttle arm linkage.
The rotational speed of the engine shaft was determined with an infrared reflectance
encoder (IRE). The IRE carries an infrared LED and photo-transistor pair that allows it to
sense the reflectance of a surface. The IRE has a voltage output of 5 volts when it detects
a surface with a reflectance below a threshold value and outputs 0 volts otherwise [14].
A mark was placed on the shaft hub with black tape that passes the IRE once per shaft
23
Figure 3.5: Servo and throttle arm linkage.
revolution. As a result the MC1 receives one pulse from the IRE for each shaft revolution.
The rotational speed was calculated using the elapsed time between pulses from the IRE
or the period. The calculation of the period requires the use of hardware interrupts. The
MC1 has two pins that support hardware interrupts. Each time a pulse is received from the
IRE the program is halted while an interrupt service routine (ISR) is executed. The ISR
is simply a function that performs some action and occurs during every interrupt. During
an interrupt all other operations are paused including those responsible for timing. For
this reason ISR functions must be kept as short as possible. The ISR triggered by pulses
from the IRE calculates the time that has elapsed since the last pulse. The relationship for
calculating speed is shown in Equation 3.1.
Speed [rev/min] =
60, 000, 000 [µs/min]
P eriod [µs/rev]
(3.1)
The temperature of the engine head was monitored using a K-type thermocouple and
the MAX6675 K-Thermocouple-to-Digital Converter (MAX6675). The thermocouple was
24
attached to a bolt near the exhaust port. It was determined with an infrared thermal camera
that the temperature at the exhaust bolt is consistently 30 degrees lower than the surface
of the engine head. The MAX6675 digitizes the voltage signal from the thermocouple and
performs cold junction compensation. It outputs the temperature with a resolution of 0.25
degrees Celsius. The barometric pressure was measured with the MPL115A1 barometric
pressure sensor (MPL115A1). The barometric pressure can be related to the altitude of the
aircraft.
3.2
3.2.1
Controller Software and PID Algorithm Implementation
Serial Communication
A custom program was written in the C language for each of the micro-controllers. The
full code for both programs is listed in Appendix D. Function libraries were written to read
the MAX6675 and MPL115A1 sensors via a serial protocol interface (SPI). The programs
have a serial communication system that allows the MC1 and MC2 to communicate with
each other and any computer with a serial monitor. The program on the MC1, aside from
reading sensors and implementing the control algorithm, sends sensor values and other data
to the MC2. Text commands entered in the laptop’s serial monitor are used to interface
with the program on the MC1. The purpose of the MC2 is to relay commands entered in the
laptop’s serial monitor to the MC1. It also has to the receive the data from the MC1, print
this data to the laptop’s serial monitor, and display select data to a LCD screen. The serial
communication system uses ASCII characters to control the flow of data. For example,
25
when the MC1 sends the measured speed value of 6500 rpm to the MC2 it is in the form
‘6500V’. The ‘V’ character tells the MC2 that the incoming numerical values represent the
measured speed.
3.2.2
Automatic Control Loop
The controller implements the incremental form of the discrete PID algorithm.
The
control variable is the value sent to the servo that corresponds to a throttle position. A
change in the throttle position results in the change of the process variable, the rotational
speed of the engine shaft. The control algorithm supports setpoint weighting, derivative
on measurement, low-pass speed measurement filtering, on-line tuning parameter
updating, and throttle servo overdrive protection. The program repeats the following
control sequence if a predefined sample time has passed.
1. Read sensors and update measurement values.
2. Execute PID algorithm if in automatic mode.
3. Report sensor measurements and other data.
The program function that executes the PID algorithm is shown below.
26
void velPID ( ) { // PID a l g o r i t h m , v e l o c i t y ( i n c r e m e n t a l ) form
/∗ Apply 1 s t o r d e r low−p a s s f i l t e r t o measured s p e e d . Alpha i s a w e i g h t i n g
f a c t o r b e t w e e n 0 and 1 t h a t t h a t d e t e r m i n e s t h e a g g r e s s i v e n e s s o f t h e
f i l t e r . Setting alpha to zero d i s a b l e s f i l t e r i n g .
∗/
l o w p a s s S p e e d = a l p h a ∗ l a s t L o w p a s s S p e e d + (1− a l p h a ) ∗ measuredSpeed ;
// C a l c u l a t e terms o f PID v e l o c i t y a l g o r i t h m
// P r o p o r t i o n a l Term
K1 = kp∗ s e t p o i n t W e i g h t ∗ ( s e t p o i n t S p e e d − l a s t S e t p o i n t S p e e d )
+ kp ∗ ( l a s t M e a s u r e d S p e e d − l o w p a s s S p e e d ) ;
// I n t e g r a l Term
K2 = k i ∗ ( s e t p o i n t S p e e d − l o w p a s s S p e e d ) ;
// D e r i v a t i v e Tem
K3 = kd ∗ ( 2 ∗ l a s t M e a s u r e d S p e e d − l o w p a s s S p e e d − l a s t L a s t M e a s u r e d S p e e d ) ;
// C a l c u l a t e c o n t r o l v a r i a b l e
o ut pu t = l a s t O u t p u t − K1 − K2 − K3 ;
// Convert o u t p u t t o c l o s e s t i n t e g e r
t h r o t t l e P o s = f l o o r ( o ut pu t + 0 . 5 ) ;
/∗ P r e v e n t o v e r d r i v i n g o f t h r o t t l e s e r v o and s t a l l i n g o f
engine in the event of control v a r i a b l e saturation .
∗/
if ( throttlePos < throttle open ){
o ut pu t = ( double ) t h r o t t l e o p e n ;
throttlePos = throttle open ;
}
if ( throttlePos > throttle safe ){
ou tp ut = ( double ) t h r o t t l e s a f e ;
throttlePos = throttle safe ;
}
// Remember v a r i a b l e s f o r n e x t i t e r a t i o n
lastLowpassSpeed = lowpassSpeed ;
lastLastMeasuredSpeed = lastMeasuredSpeed ;
lastMeasuredSpeed = lowpassSpeed ;
lastSetpointSpeed = setpointSpeed ;
l a s t O u t p u t = ou tp ut ;
// Write t h e t h r o t t l e p o s i t i o n t o s e r v o .
t h r o t t l e . writeMicroseconds ( throttlePos ) ;
}
The control variable unit is the pulse-width of the signal to the servo. The way the
throttle is installed an increasing throttle opening corresponds to a decreasing pulse-width.
This requires that the terms of the PID be subtracted from the previous value of the control
variable.
The throttle takes approximately 94 milliseconds to move from idle position to open
throttle. So there is an inherent delay that is less than 94 milliseconds. The controller must
27
allow the servo to move to the desired position before giving it a new position. The sample
time of the control algorithm is 100 milliseconds to allow for servo movement.
An important requirement for a feedback controller is bumpless transfer. A switch from
manual to automatic control that does not disrupt the controlled process is a bumpless
transfer. To ensure an uneventful transfer to automatic control the program performs the
following actions immediately after receiving a command to enter automatic control.
• Set reference speed r(tk ) to current measured speed y(tk ).
• Set r(tk−1 ) to r(tk ).
• Set y(tk−1 ) and y(tk−2 ) to y(tk ).
• Set control output u(tk ) (throttle position) to current manually set value.
• Set all terms of PID algorithm to zero to remove any residual value created by previous
periods of automatic operation.
3.3
3.3.1
Break-in Engine and Tune Carburetor
Carburetor and Fuel System
The OS160FX has a rotary barrel carburetor with a low-speed needle (LSN) valve for
adjusting fuel flow at low speeds and an external high-speed needle (HSN) valve for adjusting
fuel flow at high speeds. Figure 3.6 shows the HSN which is the primary way of controlling
the flow of fuel into the engine. At large throttle openings the HSN is the only fuel valve
that effects the flow. The LSN, shown in Figure 3.7, allows more precise fuel flow control
at low speeds. The LSN consists of a tapered needle that enters a fuel spray-bar as the
28
(b) Disassembled view
(a) Installation
Figure 3.6: High-speed needle valve (HSN).
throttle opening closes. This is shown in Figure 3.7b. The needle restricts the flow of
fuel at low-speeds while allowing full flow at high-speeds. An adjustment screw, seen in
Figure 3.7a, controls how far the spray-bar extends into the carburetor. This adjustment
determines the range of throttle positions that are affected by the LSN.
(b) Tapered needle entering spraybar
(a) Adjustment screw
Figure 3.7: Low-speed needle valve (LSN).
The position of the knob on the HSN and screw on the LSN must be set or ‘tuned’
correctly for good engine performance. The correct position depends on many factors
29
including ambient temperature, humidity, altitude, engine wear, and desired performance
characteristics. The HSN and LSN must be tuned together because they effect one another.
The fuel system is shown in Figure 3.8. A 1200 cubic centimeter fuel tank was used with
15 percent nitromethane fuel. The fuel line runs from the exhaust chamber to the tank so
that the tank can be pressurized with exhaust gases. The fuel line runs from the tank to
the HSN with a fuel filter in-line and from the HSN to the carburetor.
Figure 3.8: Engine fuel system.
3.3.2
Start-up Sequence
The engine was started manually. The start-up sequence of the engine was as follows. First
the engine was primed to introduce fuel into the carburetor. This was done by sealing the
top of the carburetor with one hand while rotating the propeller with the other. The throttle
was fully open during this process. Next the glow plug was ignited and the throttle was set
to idle position. The engine was then started by spinning the propeller at approximately
2000 rpm with an electric starter motor. After the engine was started the power source was
30
removed from the glow plug. Figure 3.9 shows the use of the starting motor and Figure
3.10 shows the location of the glow plug.
Figure 3.9: Demonstrated use of electric starting motor.
Figure 3.10: Glow plug location.
3.3.3
Break-in Procedure
A new engine is required to go through a break-in procedure. During a break-in procedure
an engine is run at low speeds with a rich air-fuel mixture. The purpose of the break-in
procedure is to allow the moving parts of the engine to ‘mate’ or settle together. This limits
the stresses on the components. The rich air-fuel mixture ensures a well lubricated engine.
31
The break-in procedure was conducted as follows. The engine was started and allowed
to run for several minutes at a time, allowing it to cool between runs. Each run was
progressively longer. The engine was operated near idle for the first half-tank of fuel. Next,
the throttle was gradually cycled between quarter and half throttle for a second half-tank of
fuel. Then, the engine was run at half to three-quarter throttle while occasionally bringing
it to full throttle for a tank of fuel. After 2 tanks of fuel the engine was considered broken
in. The tank was not allowed to be completely emptied because an engine that runs out
of fuel has a momentary jump in speed before it dies. This acceleration can damage a new
engine.
3.3.4
Tuning Procedure
The tuning procedure requires making small adjustments (1/8 turns) of the HSN and LSN
and observing how the adjustments effect performance. The speed is monitored but the
judgement of a good tuning was largely based on the sound and temperature of the engine.
It is a process that requires an experienced operator to achieve acceptable performance
throughout the entire speed range.
There were many techniques used to determine the correct carburetor settings but the
following is a procedure that was used often to make sure the engine would run well and
be controllable. The first step was to run the engine at moderate to high speeds to warm
up the engine. Next, the engine was brought to full throttle and the HSN was set to the
position that gave the maximum speed. Typically this setting was too lean and caused the
32
engine temperature to be too high. The HSN was richened gradually until the temperature
dropped to an acceptable value. With the HSN set, the LSN was then set to a position
that allowed for smooth acceleration through the speed range. This was an iterative process
because adjustments to the LSN effect the HSN. An acceptable temperature as measured
by the thermocouple was around 160 degrees Celsius.
3.4
Throttle and Speed Relationship
Understanding the effect of the control output variable on the process variable is critical to
controlling a system. In this case the process variable is the rotational speed of the engine
and the control variable is the throttle position. In order to see the relationship between
speed and throttle position, throttle step tests were performed. During a throttle step test
the throttle position was stepped in equal increments and the response of the speed to these
steps was recorded. The results of the throttle step tests are shown in Figures 3.11 and 3.12
. Throttle Step Test A has steps of 20 percent throttle taken every 80 seconds. Throttle
Step Test B has steps of 9.8 percent taken every 40 seconds.
33
Throttle Step Test
10000
100
8000
80
6000
60
4000
40
2000
0
100
200
300
400
Time (seconds)
500
600
700
Throttle Position (%)
Rotational Speed (rpm)
Measured Speed
Throttle Position
20
Figure 3.11: Throttle Step Test A.
Throttle Step Test
10000
100
8000
80
6000
60
4000
40
2000
0
100
200
300
400
Time (seconds)
500
600
Throttle Position (%)
Rotational Speed (rpm)
Measured Speed
Throttle Position
20
Figure 3.12: Throttle Step Test B.
The relationship between throttle position and speed is clear. As expected a larger
34
opening of the throttle results in higher speeds. The speed is not steady at a given throttle
position though. Figure 3.11 shows that the speed has tendency to drift or gradually move
away from a value. This drifting of speed is seen most following negative throttle steps
when the engine is slowing down. Figure 3.13 shows that at 40 percent throttle the speed
gradually drops from 4723 rpm to 4278 rpm in a span of 75 seconds. This tendency to drift
is not seen as much during the higher speeds. The speed is particularly unstable at low
speeds near idle.
Throttle Step Test
X: 564.3
Y: 4723
Throttle Position (%)
Rotational Speed (rpm)
Measured Speed
Throttle Position
X: 640
Y: 4278
4000
40
520
540
560
580
600
620
Time (seconds)
640
660
680
Figure 3.13: Gradual speed drop following a negative throttle step.
The results of Throttle Step Test B, Figure 3.12, shows that the the engine performs
differently on the upward speed trajectory then it does on the downward speed trajectory.
More steps must be taken to bring the engine from high speeds to low speeds. This could
be due to the momentum of the shaft and propeller that was produced at higher speeds.
Another potential source is excess fuel in the crankcase that is introduced during the wider
35
openings of the throttle. The automatic controller had to counter this phenomenon when
adjusting speed. The average speed at each throttle position was calculated in order to
determine the relationship between speed and throttle position. This relationship is shown
in Figure 3.14.
Average Speed vs Throttle Position
9000
Upward Trajectory
Downward Trajectory
Rotational Speed (rpm)
8000
7000
6000
5000
4000
3000
2000
20
30
40
50
60
70
Throttle Position %
80
90
100
Figure 3.14: Relationship between throttle and speed.
A common measure for describing the dynamic behavior of a process is the process
gain. The process gain defines the sensitivity of the output variable to changes in the input
variable and is calculated as shown in Equation 3.2 [15].
K=
∆Output [rpm]
∆Input [%]
(3.2)
The output and input units depend on the process and measurement methods. In this
case the output units are in rpm and the input units are throttle position expressed as a
percentage. The process gain is often dependent on the load or operating point. Figure
36
3.15 shows the process gain calculated at each positive step of Throttle Step Test B. The
process gain is 150 rpm
% at step 4 which is more than twice the value seen at steps 3 and
5. This suggests that the speed is most sensitive to changes in throttle when the engine is
transitioning from low to high speeds.
160
Process gain [rpm]/[%]
140
120
100
80
60
40
20
1
2
3
4
5
6
7
8
Step
Figure 3.15: Process gain at different operating points.
3.4.1
Sensitivity to Carburetor Tuning
Specific tests were not completed to investigate the effects of different fuel valve positions
on the engine position. Figure 3.16 shows throttle step test results with three different
carburetor tuning settings. Tuning 1 and 2 were considered good tunings since they provided
a consistent speed response to the throttle steps. The variation seen between Tunings 1 and
2 was expected between any two given tests. Tuning 3 was considered a poor tuning due
to the elevated speeds at small throttle openings and small response to a change in throttle
seen near 5000 rpm.
37
9000
Carburetor Tuning 1
Carburetor Tuning 2
Carburetor Tuning 3
Rotational Speed (rpm)
8000
7000
6000
5000
4000
3000
2000
0
100
200
300
400
Time (seconds)
500
600
700
Figure 3.16: Performance variations due to different carburetor settings.
3.5
Performance Measures and Goals
With the throttle and speed relationship determined the next step was to test the
performance of the PID algorithm. This involved running the engine and observing the
responses of the measured speed to step changes in the reference speed. The measured
speed and throttle positions were recorded for analysis.
The controller code has a subroutine that allows for programmed reference speed
changes. This allowed for consistent tests of the controller performance. The programmed
reference speed paths are shown in Figure 3.17. Each reference speed path has a 40 second
period between each step.
Reference Path A was used most when comparing tuning
parameter combinations because it has large and moderate speed steps. The symmetric
Reference Path B was useful because it showed if the controller corrected for the engines
38
performance difference between upward and downward trajectories.
8000
7000
6000
5000
4000
3000
5000
4500
4000
3500
3000
0
8000
7000
6000
5000
4000
3000
100
200
Time (seconds)
Reference Path C
Rotational Speed (rpm)
0
Rotational Speed (rpm)
Reference Path B
Rotational Speed (rpm)
Rotational Speed (rpm)
Reference Path A
200
400
600
Time (seconds)
800
0
100 200 300 400
Time (seconds)
Reference Path D
0
200
400
600
Time (seconds)
8000
7500
7000
6500
6000
800
Figure 3.17: Reference speed test paths.
The performance measures that were used when judging the responses were steadystate error, settling time, overshoot, steady-state standard error, oscillation amplitude, and
maximum steady-state deviation. A steady-state error of zero was required for all responses
to a reference change. The settling time is the time it takes for the measured speed to reach
its steady-state after a reference command is received. The overshoot is the amount the
speed overshoots the reference speed during the initial response. Only overshoot greater
than 100 rpm was considered overshoot. The steady-state standard error is a measure of
the variation of the measured speed y(t) around a reference speed r(t) during a steady-state
39
and is given by the Equation 3.3.
v
u
u
s=t
N
1 X
(yi − r)2
N −1
(3.3)
i=1
where N is the number of samples available during the steady-state period.
Variation from the reference value during steady-state can be caused by a disturbance,
measurement noise, or persistent oscillations due to process or controller dynamics. The
maximum steady-state deviation is the maximum deviation from the reference value
during steady-state. The maximum oscillation amplitude is the maximum amplitude of
any sinusoidal type oscillations seen in a response.
The acceptable values for the
performance measures are shown in Table 3.1.
Table 3.1: Performance Measures
Measure
Acceptable Value(s)
SS error
Maximum SS deviation
Settling time
Maximum overshoot
Maximum oscillation amplitude
3.6
0 rpm
-100 rpm to 100 rpm
< 10 seconds
200 rpm
100 rpm
Selection of PID Tuning Parameters
The most challenging part of implementing the PID algorithm was selecting the
appropriate tuning parameters. The parameters were chosen to minimize settling time,
overshoot, and oscillations. It was known that the derivative term adds complications to
controller design, often with limited benefit. For this reason a PI controller was designed
40
first.
After an acceptable PI controller was designed it was determined whether the
derivative term provided any clear benefit.
The first tests of the PI algorithm required trial-and-error to determine a realistic range
for the tuning parameters which were the proportional gain Kp and the integral gain Ki .
The trial and error tests pointed to a range of 0.10 to 0.01 for Kp and 0.00015 to 0.00001
for Ki with a sample time of 100 milliseconds. The next tests systematically varied the
parameters to determine their effects on the response to Reference Path A. The knowledge
gained from these tests was used to select candidates for the final parameter combination.
These candidates were tested and a best choice was selected based on a compromise between
responsiveness and stability.
Table 3.2: Steps of Reference Path A.
Step
Step
Step
Step
Step
Step
1
2
3
4
5
6
3000
7000
8000
5000
6000
7000
rpm
rpm
rpm
rpm
rpm
rpm
to
to
to
to
to
to
7000
8000
5000
6000
7000
4000
rpm
rpm
rpm
rpm
rpm
rpm
Tests with a moderate Ki and no Kp helped to illustrate the effects of the parameters.
Figure 3.18 shows the speed response with a Ki of 0.000045 and no Kp . The steps of
Reference Path A are referred to as shown in Table 3.2. There is excessive overshoot seen
in the response at step 1, step 3, and step 6. The response also exhibits steady-state
oscillations at 3000, 5000, and 6000 rpm. The oscillations are largest at 6000 rpm. Figure
3.19 shows a change in the response with a lower Ki of 0.000030. The overshoot at step 1
has been nearly eliminated but still exists at step 3 and step 6. There are still oscillations
41
but they are smaller. The high magnitude of the overshoots and oscillations were not seen
with moderate levels of Kp during the trial-and-error tests.
Kp = 0.0, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.18: Response with Ki = 0.000045 and no Kp .
Kp = 0.0, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.19: Response with Ki = 0.000030 and no Kp .
42
More tests were run to determine the effect of adding proportional gain. The tables below
summarize how the response changed with the addition and increase of the proportional
gain. The addition of the proportional gain dampened the oscillations and diminished
overshoot but it had a drawback. An increase in proportional gain was accompanied with
a greater settling time that was most evident in positive steps. Note that in Table 3.4 the
large setting times seen with a Kp of 0.00 and 0.02 were due to overshoot that occured.
Table 3.3: Response performance with Ki = 0.000030.
Ki
Kp
0.00003
0.00003
0.00003
0.00003
0.00003
0.00003
0.00003
0.00003
0.00003
0.00
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
Overshoot
at 5000 rpm
(rpm)
Oscillation
Amplitude
at 6000 rpm
(rpm)
497
428
326
298
241
153
189
144
0
358.5
355
363
251
271
187
179
153
131
Settling Time
Step 1
(seconds)
9.3
5.6
8.1
13.7
15.5
15.0
14.9
14
15.8
Table 3.4: Response performance with Ki = 0.000045.
Ki
0.000045
0.000045
0.000045
0.000045
0.000045
0.000045
0.000045
0.000045
0.000045
Kp
0.00
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
Overshoot
at 5000 rpm
(rpm)
Oscillation
Amplitude
at 6000 rpm
(rpm)
645
533
457
413
270
191
183
0
0
491
406
291
304
231
280
220
183
100
43
Settling Time
Step 1
(seconds)
11.32
15.1
7.9
8.2
10.4
7.24
11.3
11.2
11.6
The best response was obtained with a Ki of 0.000030 was with a Kp of 0.080. This
response is shown in Figure 3.20. The oscillation amplitude at 6000 rpm was nearing the
acceptable range with a value of 131 rpm but there was a long settling time of 15.8 seconds.
The best response with a Ki of 0.000045 was also with a Kp of 0.080. It is shown in Figure
3.21. The oscillation amplitude was within the acceptable range, and the overshoot was
eliminated, but the settling time at 7000 rpm was still greater than 10 seconds. The rest of
the plots of the responses listed in Tables 3.3 and 3.4 can be found in Appendix A.
Kp = 0.080, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.20: Response with Kp = 0.080 and Ki = 0.000030.
The results of these tests indicated that a larger Ki provides a quicker response but there
must be an appropriate Kp to dampen the integral term without increasing the settling time
to an unacceptable level. Since a faster response was desired, tests were run with a integral
gains of 0.000050 and 0.000055. Table 3.5 outlines the results.
44
Kp = 0.080, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.21: Response with Kp = 0.080 and Ki = 0.000045.
Table 3.5: Response performance with Ki = 0.000050 and 0.000055.
Ki
Kp
0.00005
0.00005
0.00005
0.00005
0.000055
0.000055
0.060
0.065
0.070
0.080
0.065
0.080
Overshoot
Step1
(rpm)
Maximum
Deviation
6000 rpm
(rpm)
ST*
Step 1
(seconds)
ST*
Step 2
(seconds)
ST*
Step 5
(seconds)
284
197
192
127
326
235
100
150
179
160
183
143
5.6
8
10.4
9.44
9.75
9.33
8
8.4
10
11.2
9.5
5.5
5.3
8.8
8
10.8
10.7
9.8
ST*
Step 6
(seconds)
4.8
7.4
6.2
10.3
5.7
6.7
*ST=settling time
The quickest response was with a Ki of 0.000050 and a Kp of 0.06. The settling time
at step 1 was only 5.6 seconds but there was a large overshoot of 284 rpm at step 3. A Kp
of 0.065 reduced this overshoot to 197 rpm and still provided a quick response. Increasing
the Kp to 0.07 and 0.08 decreased this overshoot further but increased settling times to an
45
unacceptable level. The responses with a Ki of 0.000050 are shown in the figures below.
Kp = 0.060, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.22: Response with Kp = 0.060 and Ki = 0.000050.
Kp = 0.065, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.23: Response with Kp = 0.065 and Ki = 0.000050.
46
Kp = 0.070, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.24: Response with Kp = 0.070 and Ki = 0.000050.
Kp = 0.080, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.25: Response with Kp = 0.080 and Ki = 0.000050.
47
It was expected that a Ki of 0.000055 would provide a quicker response than a Ki of
0.000050. Figure 3.26 shows that while the immediate response is quicker with a Ki of
0.000055 the acceleration decreases just before reaches the reference speed. The responses
with a Ki of 0.000055 also had too much overshoot at step 3 and had rapid oscillations at
4000 rpm.
Kp = 0.080, Ki = 0.000055
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 3.26: Response with Kp = 0.080 and Ki = 0.000055.
Tests with the derivative term did not provide conclusive results but they were limited.
It is likely that the value of the derivative gain Kd was too low to provide a clear effect. A
process that changes direction within a few samples is typically not benefited by derivative
term. The derivative term is most useful in a slow moving control loop where overshoot is
not acceptable. Furthermore a well tuned PI control is likely to provide better performance
than a moderately tuned PID controller [16]. A PI controller with a Kp of 0.065 and a Ki
48
of 0.000050 was chosen as the final controller.
Through further research it was found that the incremental algorithm has a unique
property that can cause issues. The integral term and proportional do not necessarily have
the same sign at a given moment. The signs are the same when the process variable is
moving away from the reference but are opposite when approaching the reference [15]. This
explains why an increasing proportional term caused longer settling times. This unique
property can cause oscillatory behavior if there is not a strong integral term. Modifications
can be made to the algorithm so that the signs of the integral and proportional term
are always the same. This would allow for a quicker response. The property can also
be advantageous because it can effectively dampen the integral term as the reference is
approached. If the modifications were only applied when the process variable was outside
a conditional band around the reference, the algorithm would theoretically allow for quick
response while taking advantage of the integral dampening near the reference [15]. It is
believed this would have given better results.
49
4
Results
The final controller met the performance requirements described in Section 3.5 with a few
exceptions. The results the reference path tests are shown in the figures below with a Kp
of 0.065 and a Ki of 0.000050. The largest settling time in the Reference Path A test,
shown in Figure 4.1, was 8.8 seconds and the largest overshoot was 197 rpm. During the
largest step response the speed reached 90 percent of the reference in less than 3 seconds.
There was a single steady-state deviation of 150 rpm from the 6000 rpm reference which
was greater than the acceptable value of 100 rpm. This single deviation was not indicative
of the overall performance and was considered acceptable.
Kp = 0.065, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 4.1: Response to Reference Path A with Kp = 0.065 and Ki = 0.000050.
The Reference Path B test in Figure 4.2 shows that the responses to negative and
50
positive steps are comparable. This indicates the the controller can correct for the difference
in engine performance seen between the upward and downward trajectories of the throttle
step tests. There is an overshoot greater than 200 rpm during the second negative step. In
this region of engine operation the LSN starts to effect the fuel flow. This sudden restriction
of the fuel flow was believed to cause this instability. This instability source is unavoidable
with the given carburetor and fuel system.
Kp = 0.065, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
200
250
Time (seconds)
300
350
400
Figure 4.2: Response to Reference Path B with Kp = 0.065 and Ki = 0.000050.
The responses to Reference Path C and D, Figure 4.3 and 4.4, show that the controller
performs well when small reference speed commands are given.
The high frequency
oscillations in Figure C is measurement noise created by engine vibrations that occurred
at low speeds.
51
Kp = 0.065, Ki = 0.000050
5500
Reference Speed
100 rpm guide
Measured Speed
Rotational Speed (rpm)
5000
4500
4000
3500
3000
2500
0
100
200
300
400
500
Time (seconds)
600
700
800
Figure 4.3: Response to Reference Path C with Kp = 0.065 and Ki = 0.000050.
Kp = 0.065, Ki = 0.000050
8500
Reference Speed
100 rpm guide
Measured Speed
Rotational Speed (rpm)
8000
7500
7000
6500
6000
5500
0
100
200
300
400
500
Time (seconds)
600
700
800
Figure 4.4: Response to Reference Path D with Kp = 0.065 and Ki = 0.000050.
52
4.1
Long Term Reference Following
Figure 4.5 shows at the controller can maintain a reference speed over a long term period.
Kp = 0.065, Ki = 0.000055
8000
Reference Speed
100 rpm guide
Measured Speed
7500
Rotational Speed (rpm)
7000
6500
6000
5500
5000
4500
4000
0
1
2
3
Time (minutes)
4
5
Figure 4.5: Long term reference speed tracking.
4.2
Setpoint Weighting
Figure 4.6 shows the response to Reference Path A if setpoint weighting is enabled. When
compared to Figure 4.1 there is a smoother response to steps 1 and 6. The step 1 response
reaches 90% of the reference value in 4.8 seconds with setpoint weighting compared to 2.9
seconds without. The step 1 settling time increases from 8 seconds to 10.2 seconds. The
oscillations caused by the rapid drop in speed during step 6 are removed with setpoint
weighting. With poor carburetor settings a sudden opening of the throttle would cause the
engine to die. These sudden throttle openings resulting from a large reference step changes
were eliminated with setpoint weighting without a large drop in responsiveness.
53
Kp = 0.065, Ki = 0.000050, SPW = 0.2
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Figure 4.6: Response with setpoint weight of 0.20.
4.3
Bumpless Transfer
Figure 4.7 shows the transfer from manual to automatic control. The red guide lines indicate
the start of automatic control. It is seen that this transfer is a bumpless transfer since there
was no significant disruption of the controlled process. When the command is received
to enter automatic control the reference speed is set to be the last measured speed. The
algorithm keeps the speed near this last measured speed. The speed under manual control
appears to have less variation around its average value than under automatic control. The
standard error of the speed under manual manual control was 45.08 while the steady-state
standard error under automatic control was 46.73. This increase in variance around the
reference speed (average speed in the case of manual control) was considered acceptable.
54
Kp = 0.065, Ki = 0.000055
Reference Speed
100 rpm guide
Measured Speed
Average Speed
100 rpm guide
5200
Rotational Speed (rpm)
5000
4800
4600
4400
4200
4000
1170
1180
1190
1200
Time (seconds)
1210
1220
Figure 4.7: Successful bumpless transfer from manual to automatic control.
4.4
Idle performance
The engine was able to idle safely at 1800 rpm without issue under PI control. The
manufacture lists 1800 rpm as the lowest practical speed that can be achieved with this
engine [11]. Figure 4.8 shows the speed during idle with a reference speed of 1800 rpm.
There are oscillations at this low speed that are not seen at speeds above 3000 rpm. A
precise control of speed is not required at idle. The controller was required to keep the
engine from stalling at low speeds. The controller met this requirement.
55
Kp = 0.065, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
2400
Rotational Speed (rpm)
2200
2000
1800
1600
1400
1200
0
5
10
15
20
Time (seconds)
25
30
Figure 4.8: Controller performance with reference speed of 1800 rpm.
4.5
Disturbance Rejection
The disturbances on the engine that effect speed can come in the form of head or cross
winds during flight and internal disturbances such as poor fuel flow and other irregularities.
Figure 4.9 shows the rejection to a disturbance in the form of an emptying fuel tank. While
this particular disturbance will be avoided in practice it helps to illustrate how the algorithm
handles disturbances. As the fuel line nears the bottom of the tank there are sudden drops
in speed. The control algorithm sees this and counters by increasing the value of the control
variable and the speed returns to the reference value with some overshoot. The larger the
drop in speed the greater the overshoot. A final surge of fuel allows the engine to maintain
speed for about 20 seconds before the engine dies.
56
Kp = 0.065, Ki = 0.000055
6600
Reference Speed
100 rpm guide
Measured Speed
Rotational Speed (rpm)
6400
6200
6000
5800
5600
5400
5200
280
290
300
310
320
330
Time (minutes)
340
350
360
370
Figure 4.9: Disturbance in the form of an emptying fuel tank.
4.6
Control Variable Saturation
Figure 4.10 shows the speed response during control variable saturation. When the reference
speed is increased to above the engine speed range the controller tries to bring the speed to
this value but reaches the throttle limit. The throttle stays fully open until the reference
speed is set to an achievable value. At this point the control algorithm resumes normal
operation without a large disruption in the control process.
57
Kp = 0.065, Ki = 0.000050
8800
Reference Speed
100 rpm guide
Measured Speed
8600
Rotational Speed (rpm)
8400
8200
8000
7800
7600
7400
7200
7000
6800
0
20
40
60
80
100
Time (seconds)
120
140
160
Figure 4.10: Control variable saturation.
4.7
Engine Temperature Monitoring
A requirement of the engine controller was that it monitor the temperature during flight.
Figure 4.11 shows the measured values of engine temperature during a Reference Path A
test. Higher speeds result in higher temperatures and a drop in speed allows the engine
to cool. The initial drop in temperature is a result of the engine cooling after a warm up
period. After the first increase in speed the temperature decreases for about 2 seconds
before starting to rise. This is due to a sudden increase in the flow rate of air across the
engine head and a rich air-fuel mixture that results from a wide throttle opening. The
momentary increase in temperature after the first drop in speed is due to a suddenly lean
air-fuel mixture and low air-speed across the engine head.
58
160
8000
150
7000
140
6000
130
5000
120
4000
110
3000
100
2000
0
50
100
150
Time (seconds)
200
250
Temperature C°
Rotational Speed (rpm)
9000
90
Figure 4.11: Engine temperature during a Reference Path A test
4.8
Controller Sensitivity to Carburetor Tuning
It was found that the controller is negatively affected by sub-optimal carburetor tunings.
The main reason for the carburetor to be out of tune was a change in ambient
temperature. In Section 3.4, it was found that the engine is most sensitive to changes in
throttle position when transitioning from low to high speeds.
This sensitivity was
magnified by poor carburetor tunings, causing the response to be unstable in this region.
The carburetor was tuned often to limit this sensitivity and ensure a controllable engine.
59
5
Conclusions
An engine controller was built to regulate the speed of a small two-stroke engine intended
for use on a small UAV. The controller was developed for the OS160FX engine but it can
be adapted to other comparable engines. The controller monitors the temperature of the
engine and will alert the ground station if there is a unsafe operating temperature. It
can also monitor altitude but the effects of altitude on the engine performance were not
accounted for in the control algorithm. The engine controller was able to reliably regulate
the speed of the OS160FX engine through the entire speed range of the engine. Responses
to reference speed steps smaller than 4000 rpm have settling times less than 10 seconds
with less than 200 rpm overshoot. Deviations from the reference speed at steady-state
are kept under 100 rpm with occasional exceptions. The engine was able to safely idle at
speeds as low as 1800 rpm. The engine controller can prevent the engine from stalling by
dropping too far below this speed. The controller provides good rejection of disturbances
caused by moderate drops and surges in fuel flow. The controller performance was found
to be sensitive to the carburetor’s fuel valve settings. A poorly tuned carburetor caused
instability in the transition region between low and high speeds.
The incremental form of the PID algorithm was suited to the task of small two-stroke
engine feedback control. It was found that only the proportional and integral term of the
PID algorithm were necessary to achieve the performance goals. The derivative term was
switched off by setting the derivative gain to zero. The integral term was the dominant
factor in determining how quickly the engine reached the reference speed. The proportional
60
term was necessary to dampen the integral term. An integral gain Ki of 0.000050 and a
proportional gain Kp of 0.065 were chosen as the final tuning parameters. The incremental
form of the PID algorithm allowed the controller to avoid issues related to control variable
saturation and enabled a bumpless transfer from manual to automatic mode.
61
6
Future Work and Recommendations
The next step in the development of the engine controller is to test it in flight. This
requires interfacing the engine controller with the UAV’s auto-pilot. The auto-pilot must
send reference speed commands to the engine controller in the form of serial data. The
auto-pilot must also be able to receive serial data from the engine controller so that it
can relay sensor data to the ground station. The components of engine controller should
integrated together in a smaller form than the current controller housing. This would
require the sensors and micro-controller chip to be wired together using a printed PCB
circuit board. Further steps should be taken to limit the effects of engine vibrations on
the sensors to provide long term reliability. The performance of the IRE used to measure
speed was sensitive to dust and drops of fuel. It should be replaced with a more durable
and consistent encoder.
A possible avenue for future research would be to use the simplex method, or other
numerical search method, to automatically tune the PID parameters. Automatic tuning
would allow the controller to adjust for changing conditions and optimize the algorithm for
the current operating point of the engine. The simplex method would perform a pattern
search to find the PID tuning parameter combination that minimizes a performance measure
or a function that incorporates multiple measures.
62
Appendix A
Additional Test Response Plots
Kp = 0.0, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
63
200
250
Kp = 0.010, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.020, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
64
200
250
Kp = 0.030, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.040, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
65
200
250
Kp = 0.050, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.060, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
66
200
250
Kp = 0.070, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.080, Ki = 0.000030
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
67
200
250
Kp = 0.0, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.010, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
68
200
250
Kp = 0.020, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.030, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
69
200
250
Kp = 0.040, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.050, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
70
200
250
Kp = 0.060, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.070, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
71
200
250
Kp = 0.080, Ki = 0.000045
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
72
200
250
Kp = 0.060, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.065, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
73
200
250
Kp = 0.070, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.080, Ki = 0.000050
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
74
200
250
Kp = 0.065, Ki = 0.000055
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
200
250
Kp = 0.080, Ki = 0.000055
Reference Speed
100 rpm guide
Measured Speed
8000
Rotational Speed (rpm)
7000
6000
5000
4000
3000
0
50
100
150
Time (seconds)
75
200
250
76
TX_HV
TX2_HV
TX_HV
TX2_HV
RX_LV
RX2_LV
MAX6675
Logic
Level
Converter
VL VH
RX_LV
DNG
RX2_LV
Part10
J5
N/C
A5/SCL
A4/SDA
A3
GND
D7
SCK/D13
MISO/D12
MOSI/PWM D11
SS/PWM D10
PWM D9
D8
PWM D6
A2
D4
PWM D3
D2
RX/D1
TX/D0
GND
OUT
PWM D5
VIN
Arduino
Uno
(Rev3)
5V
IN
7833
A0
A1
IOREF
AREF
RESET2
RESET
3V3
U12
U13
Part9
MPL115A1
TX_HV
TX2_HV
CSB
DRDY
GND
Vcc
Logic
Level
Converter
VL VH
RX2_LV
DNG
RX_LV
MISO
SCK
MOSI
TX_HV
TX2_HV
RX_LV
RX2_LV
U11
Part11
XBEE
1
RSSI
6
9
8
7
5
10
GND
RTS
CTS
DIO9
DIO5
DIO4
Xbee radio
DTR
RES
DIO11
RESET
DIO2
DIO3
DIO0
DIO1
DIN
DIO12
VDD
DOUT
3
4
1
2
11
12
13
15
16
17
18
19
20
U10
Appendix B
Controller Schematic
Appendix C
Exploded View of Engine
C.M3x18
(19260)
1
(29581000)
2
3
6
N.+M3x6
4
5
4
7
5
1
2
8
15
10-1
N.M3.5x6
3
14
13
8
20
12
7
10
9
6
N.+M3.5x6
C.M3.5x10
11
3-1
3-2
18
17
S.M3x3
19-5
19-2
19-3
19-4
19-1
16
Type of screw
C...Cap Screw M...Oval Fillister-Head Screw
F...Flat Head Screw N...Round Head Screw S...Set Screw
19
No.
Code No.
1
2
3
4
5
6
7
8
9
10
10-1
11
12
13
14
15
16
17
18
19
19-1
19-2
19-3
19-4
19-5
20
29604000
29603100
29603400
29603200
29606000
28117000
29405000
29581000
29610100
29608000
45508200
29320000
46231000
29601000
29630000
29602000
29614000
29607000
71704240
28282000
28281970
24981837
26381501
26711305
46181950
29613000
71608001
29325000
29325300
29325400
29326000
Description
Cylinder Head
Cylinder Liner
Piston Ring
Piston
Piston Pin
Piston Pin Retainers (2pcs.)
Connecting Rod
Carburetor Complete (Type 60F)
Propeller Lock Nut Set
Drive Hub
Woodruff Key
Thrust Washer
Crankshaft Ball Bearing (F)
Crankcase
Crankshaft Ball Bearing (R)
Crankshaft
Gasket Set
Cover Plate
Remote Needle Valve Bracket
Remote Needle Valve Assembly
Needle Assembly
"O" Ring (2pcs.)
Set Screw
Ratchet Spring
No.
Code No.
1
2
3
3-1
3-2
4
5
6
7
8
27881400
29581200
45582300
46066319
24881824
29581100
45581820
22681953
29015019
25081700
Description
Throttle Lever Assembly
Carburetor Rotor
Mixture Control Valve Assembly
"O" Ring (L)
"O" Ring (S)
Carburetor Body
Rotor Guide Screw
Fuel Inlet (No.1)
Carburetor Gasket
Carburetor Fixing Screw
O.S. GENUINE PARTS & ACCESSORIES
Code No.
71920000
72200080
72200130
29310110
71531000
72403050
79870050
55500004
79871070
71521000
Fuel Outlet
Screw Set
Glow Plug No.8
E-5010 Silencer Assembly
Assembly Screw
Retaining Screw (C.M5x20)
Exhaust Adaptor
Description
Radial Motor Mount
Needle Valve Extension Cable Set
Booster Terminal Kit
3/8" -M5(S) Propeller Locknut Set For Truturn Spinner
Non-Bubble Weight
Super Filter (L)
M5 Blind Nut (10pcs.)
M5 Lock Washer (10sets)
M3.5x10 Cap Screw Set (10pcs.)
Long Socket With Plug Grip
The specifications are subject to alteration for improvement without notice.
77
Appendix D
Micro-controller Code
// /////////////////////////////////////////////
// /////
HOWARD HUGHES
////////////////
// //// / / / / | / / / | | / / /////////////////
// /// / / / / | / / / | | / / //////////////////
// // / / / / / | / / | | / / ///////////////////
// / \
/ / | /
/
/ //// PAUL FJARE ////
// COLLEGE OF ENGINEERING ///// MC1 CODE //////
// //////////////////////////////////////////////
// //////////////
// LIBRARIES //
// //////////////
#include < s t d l i b . h> // C Standard General U t i l i t i e s L i b r a r y
#include < u t i l / d e l a y . h> // AVR d e l a y f u n c t i o n s
#include <Servo . h> // Servo l i b r a r y
#include <MPL115A1 . h> // MPL115A1 b a r o m e t r i c p r e s s u r e s e n s o r
library
#include <max6675 . h> // MAX6675 K−t y p e t h e r m o c o u p l e s e n s o r
library
#include <SPI . h> // SPI l i b r a r y ( r e q u i r e d f o r MPL115A1 and
MAX6675)
// ////////////////////////////
// ENGINE UNIQUE PARAMETERS //
// ////////////////////////////
// Maximum
const long
// Minimum
const long
realistic
max RPM =
realistic
min RPM =
RPM
9000;
RPM
1;
// ////// SERVO POSITION CONSTANTS ////////
// P o s i t i o n o f t h r o t t l e s e r v o a t c l o s e d t h r o t t l e
const int t h r o t t l e c l o s e d = 1 8 1 0 ;
// P o s i t i o n o f t h r o t t l e s e r v o a t open t h r o t t l e
const int t h r o t t l e o p e n = 1 3 0 0 ;
// P o s i t i o n o f t h r o t t l e s e r v o a t i d l e
const int t h r o t t l e i d l e= 1 7 2 6 ;
// P o s i t i o n o f t h r o t t l e s e r v o a t minimum t h r o t t l e
// where e n g i n e w i l l not s t a l l .
const int t h r o t t l e s a f e = 1 8 1 0 ;
// T h r o t t l e s e r v o p o s i t i o n range
const int t h r o t t l e r a n g e = t h r o t t l e c l o s e d − t h r o t t l e o p e n ;
// ////////
78
// PINS //
// ////////
const int t h r o t t l e P i n = 5 ; // t h r o t t l e s e r v o
const int f u e l P i n = 3 ; // f u e l v a l v e s e r v o
const int r e l a y P i n 1 = 4 ; // g l o w p l u g r e l a y
const int r e l a y P i n 2 = 6 ; // h e a t e r r e l a y
const int t ac ho m et e rP in = 2 ; // t a c h o m e t e r
// ///////////
// SENSORS //
// ///////////
// I n i t i a l i z e t h e r m o c o u p l e s e n s o r o b j e c t
const int thermoCS = 1 0 ; // c h i p s e l e c t p i n
MAX6675 t h e r m o c o u p l e ( thermoCS ) ;
double minimumTemp = 1 0 0 . 0 ;
double maxTemp = 2 0 0 . 0 ;
// I n i t i a l i z e b a r o m e t r i c p r e s s u r e s e n s o r o b j e c t
const int baroCS = 9 ; // c h i p s e l e c t p i n
const int baroSDN = 8 ; // shutdown p i n
MPL115A1 barometer ( baroCS , baroSDN ) ;
//SSS
// //////////
// SERVOS //
// //////////
// I n i t i a l i z e t h r o t t l e s e r v o
Servo t h r o t t l e ;
// I n i t i a l i z e f u e l v a l v e s e r v o
Servo f u e l ;
// Servo p o s i t i o n s
int t h r o t t l e P o s , f u e l P o s ;
// //////////
// TIMING //
// //////////
long Time ; // m i l l i s e c o n d s
long now , lastNow , thermoNow ,
long reportNow , reportLastNow ;
long b e f o r e , a f t e r , d u r a t i o n ;
long nowTest , lastNowTest ; //
long t e s t I n t e r v a l = 4 0 0 0 0 ; //
thermoLastNow ;
// m i l l i s e c o n d s
// m i l l i s e c o n d s
milliseconds
milliseconds
// //////////////
// TACHOMETER //
// //////////////
// Time b e t w e e n p u l s e s from t a c h o m e t e r ( m i c r o s e c o n d s )
v o l a t i l e long p e r i o d ;
v o l a t i l e long m i c r o s e c o n d s ;
79
// ///////////////////
// MEASURED VALUES //
// ///////////////////
// Temporary s t o r a g e f o r incoming d a t a
long v a l u e ;
double t e m p e r a t u r e ; // C e l c i u s
double p r e s s u r e ; // inHg
double measuredSpeed , s e t p o i n t S p e e d ;
double smoothMeasuredSpeed , l a s t S e t p o i n t S p e e d ;
double lastMeasuredSpeed , l a s t L a s t M e a s u r e d S p e e d ;
double lowpassSpeed , l a s t L o w p a s s S p e e d ;
// ////////////////////////////////
// CONTROL ALGORITHM PARAMETERS //
// ////////////////////////////////
// Sample time o f a l g o r i t h m ( m i l l i s e c o n d s )
long SampleTime = 1 0 0 ;
// Parameters f o r v e l o c i t y form o f a l g o r i t h m
double K1 , K2 , K3 ;
// Output p a r a m e t e r s
double output , l a s t O u t p u t ;
// P r o p o r t i o n a l g a i n
double Kp = 0 . 0 4 5 ;
// I n t e g r a l g a i n
double Ki = 0 . 0 0 0 0 4 5 ;
// D e r i v a t i v e g a i n
double Kd = 0 . 0 ;
double kp , ki , kd ;
double s e t p o i n t W e i g h t = 1 . 0 ; // s e t t o 1 . 0 t o d i s a b l e e f f e c t o f
setpoint weighting
double a l p h a = 0 . 0 ; // s e t t o 0 . 0 t o d i s a b l e l o w p a s s f i l t e r on
measured s p e e d s i g n a l
// ////////////
// BOOLEANS //
// ////////////
// Manual o f Automatic ( PI )
b o o l e a n manual = true ;
// S t a r t or s t o p t e s t r o u t i n e
boolean testRoutine = false ;
boolean heating = false ;
80
int t e s t I t e r a t i o n = 0 ;
void s e t u p ( ) {
// I n i t i a l i z e s e r i a l communication
S e r i a l . begin (9600) ;
// S e t modes f o r t a c h o m e t e r hardware i n t e r r u p t p i n
// and r e l a y p i n .
pinMode ( tachometerPin , INPUT) ;
pinMode ( r e l a y P i n 1 , OUTPUT) ;
pinMode ( r e l a y P i n 2 , OUTPUT) ;
// D e c l a r e hardware i n t e r r u p t p i n and
// i n t e r r u p t s e r v i c e r o u t i n e ( ISR ) .
a t t a c h I n t e r r u p t ( 0 , tachometer , RISING ) ;
// S e t t h r o t t l e p i n
t h r o t t l e . a t t a c h ( t h r o t t l e P i n ) ; // a t t a c h s e r v o o b j e c t s t o p i n s
// S e t i n i t i a l t h r o t t l e p o s i t i o n
throttlePos = throttle idle ;
t h r o t t l e . writeMicroseconds ( t h r o t t l e i d l e ) ;
// S e t i n i t i a l t u n i n g v a l u e s
SetTunings (Kp, Ki , Kd) ;
}
// /////////////
// MAIN LOOP //
// /////////////
void l o o p ( ) { // Main program l o o p
// Get s e r i a l commands
GetCommands ( ) ;
auxillaryHeating () ;
manageTestRoutine ( ) ;
// Determine c u r r e n t time
now = m i l l i s ( ) ;
i f ( now−lastNow >= 8 0 ) {
// Take s e n s o r r e a d i n g s t o u p d a t e v a l u e s
81
// o f p r e s s u r e , t e m p e r a t u r e , and s p e e d .
updateMeasurements ( ) ;
// Run c o n t r o l a l g o r i t h m i f i n a u t o mode
i f ( ! manual )
velPID ( ) ;
Time = m i l l i s ( ) ;
// Report s e n s o r and c o n t r o l a l g o r i t h m d a t a
ReportData ( ) ;
lastNow = m i l l i s ( ) ;
}
}
// /////////////////////
// CONTROL ALGORITHM //
// /////////////////////
void velPID ( ) { // PID a l g o r i t h m , v e l o c i t y form
/∗ Apply 1 s t o r d e r l o w p a s s f i l t e r t o measured s p e e d . Alpha i s
a weighting
f a c t o r b e t w e e n 0 and 1 t h a t t h a t d e t e r m i n e s t h e
aggressiveness of the
f i l t e r . Setting alpha to zero d i s a b l e s f i l t e r i n g .
∗/
l o w p a s s S p e e d = a l p h a ∗ l a s t L o w p a s s S p e e d + (1− a l p h a ) ∗
measuredSpeed ;
// C a l c u l a t e terms o f PID v e l o c i t y a l g o r i t h m
// P r o p o r t i o n a l Term
K1 = kp∗ s e t p o i n t W e i g h t ∗ ( s e t p o i n t S p e e d − l a s t S e t p o i n t S p e e d )
+ kp ∗ ( l a s t M e a s u r e d S p e e d − l o w p a s s S p e e d ) ;
// I n t e g r a l Term
K2 = k i ∗ ( s e t p o i n t S p e e d − l o w p a s s S p e e d ) ;
// D e r i v a t i v e Tem
K3 = kd ∗ ( 2 ∗ l a s t M e a s u r e d S p e e d − l o w p a s s S p e e d −
lastLastMeasuredSpeed ) ;
// C a l c u l a t e c o n t r o l v a r i a b l e
output = l a s t O u t p u t − K1 − K2 − K3 ;
// Convert o u t p u t t o c l o s e s t i n t e g e r
t h r o t t l e P o s = f l o o r ( output + 0 . 5 ) ;
82
/∗ P r e v e n t o v e r d r i v i n g o f t h r o t t l e s e r v o and s t a l l i n g o f
engine in the event of c o n t r o l v a r i a b l e s atu ra tio n .
∗/
if ( throttlePos < throttle open ){
output = ( double ) t h r o t t l e o p e n ;
throttlePos = throttle open ;
}
if ( throttlePos > throttle safe ){
output = ( double ) t h r o t t l e s a f e ;
throttlePos = throttle safe ;
}
// Remember v a r i a b l e s f o r n e x t i t e r a t i o n
lastLowpassSpeed = lowpassSpeed ;
lastLastMeasuredSpeed = lastMeasuredSpeed ;
lastMeasuredSpeed = lowpassSpeed ;
lastSetpointSpeed = setpointSpeed ;
l a s t O u t p u t = output ;
// Write t h e t h r o t t l e p o s i t i o n t o s e r v o .
t h r o t t l e . writeMicroseconds ( throttlePos ) ;
}
void SetTunings ( double propgain , double i n t g a i n , double d e r g a i n ) {
kp = p r o p g a i n ;
k i = i n t g a i n ∗ ( double ) SampleTime ;
kd = d e r g a i n / ( double ) SampleTime ;
}
// ///////////////////////
// UPDATE MEASUREMENTS //
// ///////////////////////
void updateMeasurements ( ) {
/∗ ∗
∗ Update measured v a l u e s o f e n g i n e speed , e n g i n e head
∗ t e m p e r a t u r e , and b a r o m e t r i c p r e s s u r e .
∗/
measuredSpeed = c a l c u l a t e S p e e d ( p e r i o d , max RPM, min RPM ,
measuredSpeed ) ;
// S e r i a l . p r i n t l n ( m i l l i s ( ) ) ;
detachInterrupt (0) ;
p r e s s u r e = barometer . b a r o p P r e s s u r e ( ) ;
thermoNow = m i l l i s ( ) ;
i f ( thermoNow − thermoLastNow > 3 0 0 ) {
temperature = thermocouple . r e a d C e l s i u s ( ) ;
thermoLastNow = m i l l i s ( ) ;
}
83
a t t a c h I n t e r r u p t ( 0 , tachometer , RISING ) ;
// S e r i a l . p r i n t l n ( m i l l i s ( ) ) ;
// d u r a t i o n o f t h i s f u n c t i o n i s a b o u t 6 ms
}
// ////////////////////////////
// ENGINE SPEED MEASUREMENT //
// ////////////////////////////
double c a l c u l a t e S p e e d ( long PERIOD uS , long MAX RPM, long MIN RPM,
double DEFAULT RPM) {
/∗ ∗
∗ This f u n c t i o n c a l c u l a t e s t h e s p e e d o f an e n g i n e s h a f t w i t h
a
∗ 1 PPR ( p u l s e s p e r r e v o l u t i o n ) t a c h o m e t e r . The f u n c t i o n
returns
∗ s p e e d i n RPM [ r e v /min ] .
∗
∗ ///////// PARAMETERS /////////
∗
∗ PERIOD: time b e t w e e n p u l s e s o f t h e t a c h o m e t e r i n
microseconds .
∗ MAX RPM: maximum r e a l i s t i c v a l u e o f e n g i n e s p e e d i n RPM.
∗ MIN RPM: minimum r e a l i s t i c v a l u e o f e n g i n e s p e e d i n RPM.
∗ DEFAULT RPM: v a l u e o f s p e e d t o r e t u r n i f t h e v a l u e o f t h e
∗ p e r i o d i s not w i t h i n l i m i t s .
∗
∗ ///////// EQUATIONS /////////
∗
∗ s p e e d [ r e v /min ] = 6 0 ,0 0 0 , 00 0 [ m i c r o s e c /min ] / p e r i o d [
microsec / rev ]
∗
∗ p e r i o d [ m i c r o s e c / r e v ] = 6 0 , 0 0 0 , 0 0 0 [ m i c r o s e c /min ] / rpm [
r e v /min ]
∗/
double rpm ;
long p e r i o d u s = PERIOD uS ;
long max rpm = MAX RPM;
long min rpm = MIN RPM;
double d e f a u l t r p m = DEFAULT RPM;
// Maximum a l l o w a b l e p e r i o d
s t a t i c long period max = 60000000L/min rpm ;
// Minimum a l l o w a b l e p e r i o d
s t a t i c long p e r i o d m i n = 60000000L/max rpm ;
84
// Check t h a t p e r i o d i s w i t h i n l i m i t s
i f ( p e r i o d u s > p e r i o d m i n && p e r i o d u s < period max )
// Awesome ! C a l c u l a t e s p e e d
rpm = 6 0 0 0 0 0 0 0 . 0 / ( double ) p e r i o d u s ;
else
// Use d e f a u l t v a l u e o f s p e e d
rpm = d e f a u l t r p m ;
return ( rpm ) ;
}
void t a c h o m e t e r ( ) {
/∗ ∗
∗ ISR ( I n t e r r u p t S e r v i c e Routine ) t h a t i s t r i g g e r e d when t h e
microcontroller
∗ r e c i e v e s a p u l s e from t h e t a c h o m e t e r . I t c a l c u l a t e s t h e
time b e t w e e n t h e
∗ c u r r e n t p u l s e and t h e p r e v i o u s p u l s e , t h e p e r i o d .
∗
∗ V a r i a b l e s s h a r e d b e t w e e n ISR f u n c t i o n s and normal f u n c t i o n s
∗ s h o u l d be d e c l a r e d ” v o l a t i l e ” . This t e l l s t h e c o m p i l e r
t h a t such
∗ v a r i a b l e s might change a t any time , and t h u s t h e c o m p i l e r
must
∗ r e l o a d t h e v a r i a b l e whenever you r e f e r e n c e i t , r a t h e r than
∗ r e l y i n g upon a copy i t might have i n a p r o c e s s o r r e g i s t e r .
∗/
period = micros ( ) − microseconds ;
microseconds = micros ( ) ;
}
void b u m p l e s s T r a n s f e r ( ) {
/∗ ∗
∗ This f u n c t i o n i s c a l l e d when t h e program s w i t c h e s
∗ t o a u t o m a t i c mode (PID a l g o r i t h m i s a c t i v e ) . I t s e t s
∗ a l l terms o f t h e PID a l g o r i t h m t o z e r o t o remove any
∗ r e s i d u a l values created during previous periods of
∗ a u t o m a t i c o p e r a t i o n . The s e t p o i n t s p e e d i s s e t t o
∗ t h e most r e c e n t measured s p e e d t o p r e v e n t an a b r u p t
∗ jump i n s p e e d . The a l g o r i t h m remembers t h e c o n t r o l
∗ o u t p u t , s e t p o i n t speed , and measuremed s p e e d from
∗ p r e v i o u s i t e r a t i o n s . S i n c e t h e r e has been no p r e v i o u s
∗ i t e r a t i o n t h e s e v a l u e s must be s e t t o t h e c u r r e n t v a l u e s .
∗/
K1 = 0 ;
K2 = 0 ;
K3 = 0 ;
85
filteredK3 = 0;
output = ( double ) t h r o t t l e P o s ;
l a s t O u t p u t = output ;
s e t p o i n t S p e e d = measuredSpeed ;
l a s t S e t p o i n t S p e e d = measuredSpeed ;
l o w p a s s S p e e d = measuredSpeed ;
lastLowpassSpeed = lowpassSpeed ;
l a s t L a s t M e a s u r e d S p e e d = measuredSpeed ;
l a s t M e a s u r e d S p e e d = measuredSpeed ;
}
// /////////////////////
// AUXILLARY HEATING //
// /////////////////////
void a u x i l l a r y H e a t i n g ( ) {
i f ( t e m p e r a t u r e > maxTemp) {
Serial . println (”e”) ;
}
i f ( h e a t i n g && t e m p e r a t u r e >= minimumTemp) {
d i g i t a l W r i t e ( r e l a y P i n 1 , LOW) ;
d i g i t a l W r i t e ( r e l a y P i n 2 , LOW) ;
heating = false ;
}
}
// ////////////////
// TEST ROUTINE //
// ////////////////
void manageTestRoutine ( ) {
s t a t i c long s t e p s = 2 2 ;
long t e s t S e t p o i n t S p e e d [ 2 2 ] =
{6000 ,6200 ,6400 ,6600 ,6800 ,7000 ,7200 ,7400 ,7600 ,7800 ,
8000 ,7800 ,7600 ,7400 ,7200 ,7000 ,6800 ,6600 ,6400 ,6200 ,6000 ,2999};
i f ( testRoutine ){
nowTest = m i l l i s ( ) ;
i f ( nowTest−lastNowTest > t e s t I n t e r v a l ) {
// t h r o t t l e P o s = t e s t T h r o t t l e [ t e s t I t e r a t i o n ] ;
// t h r o t t l e . w r i t e M i c r o s e c o n d s ( t h r o t t l e P o s ) ;
setpointSpeed = testSetpointSpeed [ t e s t I t e r a t i o n ] ;
t e s t I t e r a t i o n += 1 ;
i f ( t e s t I t e r a t i o n > s t e p s −1 ) {
testRoutine = false ;
86
testIteration = 0;
}
lastNowTest = m i l l i s ( ) ;
}
}
}
// ////////////////
// GET COMMANDS //
// ////////////////
void GetCommands ( ) {
i f ( S e r i a l . a v a i l a b l e ( ) > 0) {
char ch = S e r i a l . r e a d ( ) ;
i f ( ch >= ’ 0 ’ && ch <= ’ 9 ’ ) {
// a c c u m u l a t e t h e v a l u e and p u t a c c u m l a t e d v a l u e s i n
array
v a l u e = ( v a l u e ∗ 1 0 ) + ( ch − ’ 0 ’ ) ;
}
else {
switch ( ch ) {
// // THROTTLE ////
case ’ t ’ : // s e t t h r o t t l e p o s i t i o n
i f ( v a l u e >= t h r o t t l e o p e n && v a l u e <=
throttle closed ){
throttlePos = value ;
t h r o t t l e . writeMicroseconds ( throttlePos ) ;
}
break ;
case ’ z ’ : // t h r o t t l e p o s i t i o n t o c l o s e d ( k i l l e n g i n e
)
t h r o t t l e . writeMicroseconds ( t h r o t t l e c l o s e d ) ;
throttlePos = throttle closed ;
break ;
case ’ x ’ : // t h r o t t l e p o s i t i o n t o f u l l y open
t h r o t t l e . writeMicroseconds ( throttle open ) ;
throttlePos = throttle open ;
break ;
case ’ a ’ : // t h r o t t l e t o i d l e p o s i t i o n
t h r o t t l e . writeMicroseconds ( t h r o t t l e i d l e ) ;
throttlePos = t h r o t t l e i d l e ;
break ;
case ’ q ’ : // open t h r o t t l e by 10
i f ( t h r o t t l e P o s >= t h r o t t l e o p e n + 1 0 ) {
t h r o t t l e P o s −= 1 0 ;
t h r o t t l e . writeMicroseconds ( throttlePos ) ;
}
87
break ;
case ’w ’ : // c l o s e t h r o t t l e by 10
i f ( t h r o t t l e P o s <= t h r o t t l e c l o s e d − 1 0 ) {
t h r o t t l e P o s += 1 0 ;
t h r o t t l e . writeMicroseconds ( throttlePos ) ;
}
break ;
case ’Q ’ : // open t h r o t t l e by 100
i f ( t h r o t t l e P o s >= t h r o t t l e o p e n + 1 0 0 ) {
t h r o t t l e P o s −= 1 0 0 ;
t h r o t t l e . writeMicroseconds ( throttlePos ) ;
}
break ;
case ’W’ : // c l o s e t h r o t t l e by 100
i f ( t h r o t t l e P o s <= t h r o t t l e c l o s e d − 1 0 0 ) {
t h r o t t l e P o s += 1 0 0 ;
t h r o t t l e . writeMicroseconds ( throttlePos ) ;
}
break ;
// // SETPOINT SPEED ////
case ’ s ’ : // s e t s e t p o i n t s p e e d v a l u e
i f ( v a l u e >= 0 && v a l u e <= max RPM) {
setpointSpeed = ( float ) value ;
}
break ;
case ’ b ’ : // i n c r e a s e s e t p o i n t s p e e d by 100
i f ( s e t p o i n t S p e e d <= max RPM − 1 0 0 . 0 )
s e t p o i n t S p e e d += 1 0 0 . 0 ;
break ;
case ’ n ’ : // d e c r e a s e s e t p o i n t s p e e d by 100
i f ( s e t p o i n t S p e e d >= 1 0 0 . 0 )
s e t p o i n t S p e e d −= 1 0 0 . 0 ;
break ;
case ’B ’ : // i n c r e a s e s e t p o i n t s p e e d by 1000
i f ( s e t p o i n t S p e e d <= max RPM − 1 0 0 0 . 0 )
s e t p o i n t S p e e d += 1 0 0 0 . 0 ;
break ;
case ’N ’ : // d e c r e a s e s e t p o i n t s p e e d by 1000
i f ( s e t p o i n t S p e e d >= 1 0 0 0 . 0 )
s e t p o i n t S p e e d −= 1 0 0 0 . 0 ;
break ;
// // TUNING PARAMS ////
case ’ j ’ : // i n c r e a s e prop . g a i n by 0 . 0 0 1
Kp += 0 . 0 0 1 ;
SetTunings (Kp, Ki , Kd) ;
88
break ;
case ’ k ’ : // d e c r e a s e prop . g a i n by 0 . 0 0 1
i f (Kp >= 0 . 0 0 1 ) {
Kp −= 0 . 0 0 1 ;
SetTunings (Kp, Ki , Kd) ;
}
break ;
case ’ J ’ : // i n c r e a s e prop . g a i n by 0 . 0 1
Kp += 0 . 0 1 ;
SetTunings (Kp, Ki , Kd) ;
break ;
case ’K ’ : // d e c r e a s e prop . g a i n by 0 . 0 1
i f (Kp >= 0 . 0 1 ) {
Kp −= 0 . 0 1 ;
SetTunings (Kp, Ki , Kd) ;
}
break ;
case ’ y ’ : // i n c r e a s e i n t e g r a l g a i n by 0 . 0 0 0 0 0 0 1
Ki += 0 . 0 0 0 0 0 1 ;
SetTunings (Kp, Ki , Kd) ;
break ;
case ’ u ’ : // d e c r e a s e i n t e g r a l g a i n by 0 . 0 0 0 0 0 0 1
i f ( Ki >= 0 . 0 0 0 0 0 1 ) {
Ki −= 0 . 0 0 0 0 0 1 ;
SetTunings (Kp, Ki , Kd) ;
}
break ;
case ’Y ’ : // i n c r e a s e i n t e g r a l g a i n by 0 . 0 0 0 0 1
Ki += 0 . 0 0 0 0 1 ;
SetTunings (Kp, Ki , Kd) ;
value = 0;
break ;
case ’U ’ : // d e c r e a s e i n t e g r a l g a i n by 0 . 0 0 0 0 1
i f ( Ki >= 0 . 0 0 0 0 1 ) {
Ki −= 0 . 0 0 0 0 1 ;
SetTunings (Kp, Ki , Kd) ;
}
break ;
case ’ g ’ : // i n c r e a s e d e r i v a t i v e g a i n by 0 . 0 1
Kd += 0 . 0 1 ;
SetTunings (Kp, Ki , Kd) ;
break ;
case ’ h ’ : // d e c r e a s e d e r i v a t i v e g a i n by 0 . 0 1
i f (Kd >= 0 . 0 1 ) {
Kd −= 0 . 0 1 ;
SetTunings (Kp, Ki , Kd) ;
}
break ;
89
case ’G ’ : // i n c r e a s e d e r i v a t i v e g a i n by 0 . 1
Kd += 0 . 1 ;
SetTunings (Kp, Ki , Kd) ;
break ;
case ’H ’ : // d e c r e a s e d e r i v a t i v e g a i n by 0 . 1
i f (Kd >= 0 . 1 ) {
Kd −= 0 . 1 ;
SetTunings (Kp, Ki , Kd) ;
}
break ;
case ’ d ’ : // i n c r e a s e s e t p o i n t w e i g h t
s e t p o i n t W e i g h t += 0 . 0 5 ;
break ;
case ’D ’ : // d e c r e a s e d e r i v a t i v e g a i n by 0 . 0 0 0 0 0 0 1
i f ( s e t p o i n t W e i g h t >= 0 . 0 5 )
s e t p o i n t W e i g h t −= 0 . 0 5 ;
break ;
case ’ ( ’ : // i n c r e a s e a l p h a
a l p h a += 0 . 0 5 ;
break ;
case ’ ) ’ : // d e c r e a s e a l p h a
i f ( a l p h a >= 0 . 0 5 )
a l p h a −= 0 . 0 5 ;
break ;
// // BOOLEANS ////
case ’m’ : // e n a b l e or d i s a b l e a u t o mode
manual = ! manual ;
i f ( ! manual ) {
bumplessTransfer () ;
}
break ;
case ’ o ’ : // i n i t i a t e or t e r m i n a t e t e s t r o u t i n e
testRoutine = ! testRoutine ;
break ;
case ’O ’ : // r e s e t t e s t I t e r a t i o n
testIteration = 0;
break ;
case ’ r ’ : // t o g g l e a u x i l l a r y h e a t i n g on/ o f f
heating = ! heating ;
break ;
}
value = 0;
}
}
}
90
// ///////////////
// REPORT DATA //
// ///////////////
void ReportData ( ) {
// send c o n t r o l mode s t a t e manual / a u t o
S e r i a l . p r i n t ( manual ) ;
Serial . println (” ! ”) ;
delay us (100) ;
// send t e s t r o u t i n e s t a t e on/ o f f
Serial . print ( testRoutine ) ;
S e r i a l . p r i n t l n ( ”&” ) ;
delay us (100) ;
// send h e a t i n g s t a t e on/ o f f
S e r i a l . print ( heating ) ;
S e r i a l . p r i n t l n ( ”R” ) ;
delay us (100) ;
// send c u r r e n t time
S e r i a l . p r i n t ( Time ) ;
S e r i a l . p r i n t l n ( ”T” ) ;
delay us (100) ;
// send t h r o t t l e p o s i t i o n
Serial . print ( throttlePos ) ;
S e r i a l . p r i n t l n ( ”F” ) ;
delay us (100) ;
// send p r e s s u r e
Serial . print ( pressure ∗10.0 ,0) ;
S e r i a l . p r i n t l n ( ”P” ) ;
delay us (100) ;
// send t e m p e r a t u r e
S e r i a l . p r i n t ( temperature , 0 ) ;
S e r i a l . p r i n t l n ( ”C” ) ;
delay us (100) ;
// send Kp
S e r i a l . p r i n t (Kp∗ 1 0 0 0 . 0 , 0 ) ;
S e r i a l . p r i n t l n ( ”{” ) ;
delay us (100) ;
// send Ki
91
S e r i a l . p r i n t ( Ki ∗ 1 0 0 0 0 0 0 . 0 , 0 ) ;
S e r i a l . p r i n t l n ( ”}” ) ;
delay us (100) ;
// send Kd
S e r i a l . p r i n t (Kd∗ 1 0 0 0 . 0 , 0 ) ;
Serial . println (” [ ”) ;
delay us (100) ;
// send s e t p o i n t s p e e d
S e r i a l . print ( setpointSpeed , 0 ) ;
S e r i a l . p r i n t l n ( ”S” ) ;
delay us (100) ;
// send l o w p a s s s p e e d
S e r i a l . p r i n t ( lowpassSpeed ∗ 1 0 0 . 0 , 0 ) ;
S e r i a l . p r i n t l n ( ”#” ) ;
delay us (100) ;
// send measure s p e e d
// a l w a y s send l a s t b e c a u s e i t t e l l s
// MC2 when i t i s time t o p r i n t v a l u e s
// t o s e r i a l monitor .
S e r i a l . p r i n t ( measuredSpeed ∗ 1 0 0 . 0 , 0 ) ;
S e r i a l . p r i n t l n ( ”V” ) ;
delay us (100) ;
delay ms (5) ;
}
// //////////////////////////////////////////////
// /////
HOWARD HUGHES
////////////////
// //// / / / / | / / / | | / / /////////////////
// /// / / / / | / / / | | / / //////////////////
// // / / / / / | / / | | / / ///////////////////
// / \
/ / | /
/
/ //// PAUL FJARE ////
// COLLEGE OF ENGINEERING ///// MC2 CODE /////
// //////////////////////////////////////////////
// //////////////
// LIBRARIES //
// //////////////
#include < s t d l i b . h> // C Standard General U t i l i t i e s L i b r a r y
#include < u t i l / d e l a y . h> // AVR d e l a y f u n c t i o n s
#include <L i q u i d C r y s t a l . h> // LCD L i b r a r y
// C r e a t e LCD l i b r a r y o b j e c t
L i q u i d C r y s t a l l c d ( 1 3 , 1 2 , 8 , 9 , 1 0 , 1 1 ) ; // l c d ( rs , e , D4 , D5 , D6
, D7)
92
// ///////////////////////////
// ENGINE UNIQUE PARAMETERS //
// ////////////////////////////
// Maximum
const long
// Minimum
const long
realistic
max RPM =
realistic
min RPM =
RPM
9000;
RPM
1;
// ////// SERVO POSITION CONSTANTS ////////
// P o s i t i o n o f t h r o t t l e s e r v o a t c l o s e d t h r o t t l e
const int t h r o t t l e c l o s e d = 1 8 1 0 ;
// P o s i t i o n o f t h r o t t l e s e r v o a t open t h r o t t l e
const int t h r o t t l e o p e n = 1 3 0 0 ;
// P o s i t i o n o f t h r o t t l e s e r v o a t i d l e
const int t h r o t t l e i d l e= 1 7 4 6 ;
// P o s i t i o n o f t h r o t t l e s e r v o a t minimum t h r o t t l e
// where e n g i n e w i l l not s t a l l .
const int t h r o t t l e s a f e = 1 7 5 6 ;
// ////////
// PINS //
// ////////
// P o t e n t i o m e t e r knob c o n t r o l l i n g t h r o t t l e
int t h r o t t l e K n o b P i n = 8 ;
// P o t e n t i o m e t e r knob c o n t r o l l i n g t h r o t t l e
int fuelKnobPin = 9 ;
// //////////
// TIMING //
// //////////
long now ;
long lastNow ;
long Time ;
// //////////
// VALUES //
// //////////
// Temporary s t o r a g e f o r incoming d a t a
long v a l u e ;
double t e m p e r a t u r e ; // C e l c i u s
double p r e s s u r e ; // inHg
double measuredSpeed , lastMeasuredSpeed , l o w p a s s S p e e d ;
double s e t p o i n t S p e e d ; // RPM
int f u e l P o s , l a s t F u e l P o s ;
// C o n t r o l A l g o r i t h m Parameters
93
// RPM
double
double
double
double
Kp, Ki , Kd ;
K1 , K2 , K3 , f i l t e r e d K 3 ;
error , lastError , lastLastError ;
output ;
// ////////////
// BOOLEANS //
// ////////////
// Manual o f Automatic ( PI )
b o o l e a n manual ;
// S t a r t or s t o p t e s t r o u t i n e
boolean testRoutine ;
boolean heating ;
// /////////
// SETUP //
// /////////
void s e t u p ( ) {
S e r i a l . b e g i n ( 9 6 0 0 ) ; // PC s e r i a l
S e r i a l 1 . b e g i n ( 9 6 0 0 ) ; // W i r e l e s s s e r i a l
lcd . begin (20 ,4) ;
lcd . display () ;
}
// /////////////
// MAIN LOOP //
// /////////////
void l o o p ( ) {
getCommands ( ) ;
getReportedData ( ) ;
now = m i l l i s ( ) ;
i f ( ( now−lastNow ) >= 1 0 0 ) {
i f ( KnobControl ) {
setThrottle () ;
}
updateLCD ( ) ;
lastNow = now ;
}
}
// ////////////////
94
// GET COMMANDS //
// ////////////////
void getCommands ( ) {
/∗ Get commands from s e r i a l monitor and r e l a y t h e s e commands
t o o t h e r m i c r o c o n t r o l l e r . ∗/
i f ( S e r i a l . a v a i l a b l e ( ) > 0) {
char ch = S e r i a l . r e a d ( ) ;
i f ( ch >= ’ 0 ’ && ch <= ’ 9 ’ ) {
// a c c u m u l a t e t h e v a l u e and p u t a c c u m l a t e d v a l u e s i n
array
v a l u e = ( v a l u e ∗ 1 0 ) + ( ch − ’ 0 ’ ) ;
}
else {
switch ( ch ) {
case ’ t ’ : // s e t t h r o t t l e p o s i t i o n ex . 1600 t
i f ( v a l u e >= t h r o t t l e o p e n && v a l u e <=
throttle closed ){
S e r i a l 1 . print ( value ) ;
}
value = 0;
break ;
case ’ s ’ : // s e t s e t p o i n t s p e e d v a l u e
i f ( v a l u e >= 0 && v a l u e <= max RPM) {
S e r i a l 1 . print ( value ) ;
}
value = 0;
break ;
}
S e r i a l 1 . p r i n t l n ( ch ) ;
value = 0;
}
}
}
// ////////////
// GET DATA //
// ////////////
void getReportedData ( ) {
i f ( S e r i a l 1 . a v a i l a b l e ( ) > 0) {
char ch = S e r i a l 1 . r e a d ( ) ;
95
i f ( ch >= ’ 0 ’ && ch <= ’ 9 ’ ) {
// Accumulate t h e v a l u e
v a l u e = ( v a l u e ∗ 1 0 ) + ( ch − ’ 0 ’ ) ;
}
else {
switch ( ch ) {
case ’ ! ’ : // g e t c u r r e n t time
manual = v a l u e ;
break ;
case ’& ’ : // g e t t e s t r o u t i n e s t a t e
testRoutine = value ;
break ;
case ’R ’ : // g e t h e a t i n g s t a t e on/ o f f
heating = value ;
break ;
case ’T ’ : // g e t Time
Time = v a l u e ;
break ;
case ’F ’ : // g e t t h r o t t l e p o s i t i o n
throttlePos = value ;
break ;
case ’#’ : // g e t l o w p a s s s p e e d
l o w p a s s S p e e d = ( double ) v a l u e / 1 0 0 . 0 ;
break ;
case ’ S ’ : // g e t s e t p o i n t s p e e d
s e t p o i n t S p e e d = ( double ) v a l u e ;
break ;
case ’P ’ : // g e t p r e s s u r e
p r e s s u r e = ( double ) v a l u e / 1 0 . 0 ;
break ;
case ’C ’ : // g e t t e m p e r a t u r e
t e m p e r a t u r e = ( double ) v a l u e ;
break ;
case ’ I ’ :
K1 = ( double ) v a l u e / 1 0 0 . 0 ;
break ;
case ’E ’ :
K2 = ( double ) v a l u e / 1 0 0 . 0 ;
break ;
case ’ v ’ :
K3 = ( double ) v a l u e / 1 0 0 . 0 ;
break ;
case ’ { ’ : // g e t Kp
Kp = ( double ) v a l u e / 1 0 0 0 . 0 ;
break ;
case ’ } ’ : // g e t Ki
Ki = ( double ) v a l u e / 1 0 0 0 0 0 0 . 0 ;
96
break ;
case ’ [ ’ : // g e t Kd
Kd = ( double ) v a l u e / 1 0 0 0 . 0 ;
break ;
case ’X ’ : // g e t a l p h a
a l p h a = ( double ) v a l u e / 1 0 0 . 0 ;
case ’M’ : // g e t s e t p o i n t w e i g h t
s e t p o i n t W e i g h t = ( double ) v a l u e / 1 0 0 . 0 ;
case ’V ’ : // g e t measured s p e e d
measuredSpeed = ( double ) v a l u e / 1 0 0 . 0 ;
i f ( measuredSpeed != l a s t M e a s u r e d S p e e d )
logData ( ) ;
break ;
}
value = 0;
}
}
}
// ///////////////////////
// DISPLAY DATA ON LCD //
// ///////////////////////
void updateLCD ( ) {
/∗ ∗
///////////////////// LCD MAP ///////////////////
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0| K i 0 . 0 0 0 0 0 0 − − − K p 0 . 0 0 0
1| K d 0 . 0 0 0 − − − M A N − A U X − T R
2| y 0 0 0 0 0 − r 0 0 0 0 0 − c o 0 0 0 0
3| 0 0 0 ∗ C − 0 0 . 0 i n H g − −
∗/
l c d . c l e a r ( ) ; // c l e a r a l l c h a r a c t e r s on s c r e e n
// / LINE 0 ///
l c d . s e t C u r s o r ( 0 , 0 ) ; // l c d . s e t C u r s o r ( c o l , row )
l c d . p r i n t ( ”Ki” ) ;
l c d . p r i n t ( Ki , 6 ) ;
lcd . setCursor (13 ,0) ;
l c d . p r i n t ( ”Kp” ) ;
l c d . p r i n t (Kp, 3 ) ;
97
// / LINE 1 ///
lcd . setCursor (0 ,1) ;
l c d . p r i n t ( ”Kd” ) ;
l c d . p r i n t (Kd, 3 ) ;
lcd . setCursor (10 ,1) ;
i f ( ! manual )
l c d . p r i n t ( ”AUTO” ) ;
lcd . setCursor (14 ,1) ;
i f ( heating )
l c d . p r i n t ( ”AUX” ) ;
lcd . setCursor (18 ,1) ;
i f ( testRoutine )
l c d . p r i n t ( ”TR” ) ;
// / LINE 2 ///
lcd . setCursor (0 ,2) ;
l c d . p r i n t ( ”PV” ) ;
l c d . p r i n t ( measuredSpeed , 0 ) ;
lcd . setCursor (8 ,2) ;
l c d . p r i n t ( ”SP” ) ;
lcd . print ( setpointSpeed , 0 ) ;
lcd . setCursor (15 , 2) ;
l c d . p r i n t ( ”T” ) ;
lcd . print ( throttlePos ) ;
// / LINE 3 ///
lcd . setCursor (0 ,3) ;
l c d . p r i n t ( temperature , 0 ) ;
l c d . p r i n t ( ( char ) 2 2 3 ) ;
l c d . p r i n t ( ”C” ) ;
lcd . setCursor (6 ,3) ;
lcd . print ( pressure ,1) ;
l c d . p r i n t ( ” inHg ” ) ;
}
// ////////////
// LOG DATA //
// ////////////
98
void logData ( ) {
S e r i a l . p r i n t ( Time ) ;
Serial . print (” ,”) ;
delay us (100) ;
S e r i a l . p r i n t (Kp, 3 ) ;
Serial . print (” ,”) ;
delay us (100) ;
S e r i a l . p r i n t ( Ki , 6 ) ;
Serial . print (” ,”) ;
delay us (100) ;
S e r i a l . p r i n t (Kd, 3 ) ;
Serial . print (” ,”) ;
delay us (100) ;
Serial . print ( throttlePos ) ;
Serial . print (” ,”) ;
delay us (100) ;
S e r i a l . print ( setpointSpeed ) ;
Serial . print (” ,”) ;
delay us (100) ;
S e r i a l . p r i n t ( temperature ) ;
Serial . print (” ,”) ;
delay us (100) ;
S e r i a l . p r i n t ( lowpassSpeed ) ;
Serial . print (” ,”) ;
delay us (100) ;
S e r i a l . p r i n t ( measuredSpeed ) ;
Serial . print (” ,”) ;
delay us (100) ;
Serial . println () ;
l a s t M e a s u r e d S p e e d = measuredSpeed ;
delay ms (10) ;
}
99
References
[1] B. Sodoma, “Taking flight,” UNLV Mag., vol. 22, pp. 22-24, Jun. 2014.
[2] K. Mollenhauer and H. Tschoeke, “History and Fundamental Principles of the Diesel
Engine,” in Handbook of Diesel Engines. Heidelberg, Berlin: Springer-Verlag, 2010.
[3] J. B. Heywood, “Engine fuel metering and manifold phenomena”, in IC Engines
Fundamentals, McGraw-Hill, 1998.
[4] (2014). Propeller Propulsion [Online]. Available: https://www.grc.nasa.gov/www/
k-12/airplane/propeller.html
[5] A. C. Roth, “Two-Cycle and Four-Cycle Engines,” in Small Gas Engines. GoodheartWillcox Co. , 2009.
[6] K. W. Stinson, “The Diesel Engine,” in Diesel Eng. Handbook, 10th ed. Stamford, CT:
Diesel Publications, Inc. , 1959.
[7] (2009). Carburetor: mixing the gas vapor with air to make combustion [Online].
Available: http://hdabob.com/the-vehicle/fuel-injection/carburetor/
[8] C. D. Gierke, “Glow plugs exposed,” Model Airplane News, pp. 170-178, Aug. 2004.
[9] K. Astrom, R. Murray, “PID Control,” in Feedback Systems, Princeton, NJ: Princeton
Univ. Press, 2008.
[10] A. Visioli, Practical PID Control. London, UK: Springer-Verlag, 2006.
[11] 160FX [Online]. Available: http://www.osengines.com/engines-airplane/osmg0660/
index.html
[12] Arduino
Duemilanove
[Online].
arduinoBoardDuemilanove
[13] HS-125MG Slim-Wing [Online].
hs-125mg slim-wing.html
Available:
Available:
http://arduino.cc/en/Main/
http://www.servocity.com/html/
[14] Encoder for Pololu wheel [Online]. http://www.pololu.com/product/1217
[15] B. G. Liptak, “Control Theory,” in Instrument Engineers’ Handbook, 4th ed., vol. 2,
Boca Raton: CRC Press, 2003, ch. 2.
[16] P. Welender, “Understanding Derivative in PID Control,” Control Eng., Feb.
2010. [Online]. Available: http://www.controleng.com/search/search-single-display/
understanding-derivative-in-pid-control/4ea87c406e.html
100
Paul Fjare
(702) 373-1188
pfjare@gmail.com
8221 Green Clover Ave. Las Vegas, NV 89149
linkedin.com/in/paulfjare
Nevada EI #0T6809
Education
//////////////////////////////
Master of Science, Mechanical Engineering
University of Nevada, Las Vegas
Expected 2014
Bachelor of Science, Mechanical Engineering
University of Nevada, Las Vegas
2012
GPA - 3.68
Major GPA - 3.36
Skills
//////////////////
• Revit MEP • Solidworks • Excel/Word/Powerpoint
• Matlab • Comsol • Python • Hypermesh • Engineering Equation Solver (EES)
Technical Projects
//////////////////////////////////////////////////////////
Solar Decathlon 2012-2013
•
•
•
•
•
Worked with a talented team of UNLV students, professors, and industry professionals to
build an ultra-efficient solar powered home that was one of 20 entries around the world in
the United States Department of Energy Solar Decathlon 2013.
Designed the domestic water supply and sanitary plumbing systems.
Modeled the plumbing systems in Revit MEP.
Contributed to the creation of graphics for the team’s website.
Team Las Vegas placed 2nd overall and 1st in the nation.
Senior Design 2011
•
•
•
•
Worked in a team with three other students to design and build a prototype of a window
cleaner for office buildings that utilized a dual winch positioning system.
Designed the control system for the prototype’s DC motors.
Managed the team’s progress.
Awarded 2nd Place Mechanical Engineering in the annual Senior Design competition at the
UNLV College of Engineering.
Organizations
///////////////////////////////////////////
American Society of Mechanical Engineers - Member
Society of Asian Scientists and Engineers UNLV Chapter - Director of Marketing 2013