Docstoc

Smart Lamp

Document Sample
Smart Lamp Powered By Docstoc
					        Smart Lamp
   A Real Smart Object



                      by
                  Mark Gauci
Department of Computer Science and Electrical Engineering
                University of Queensland




               Submitted for the degree of
            Bachelor of Engineering (Honours)
                     in the division of
             Computer Systems Engineering.


                     October 1998
i
                                                                        12 Mirreh Place
                                                                            Chapel Hill
                                                                         Brisbane 4069
                                                                    Ph. (07) 3878 4232


                                                                      October 13, 1998


The Dean
School of Engineering
University of Queensland
St. Lucia
Queensland 4072


Dear Sir,


In accordance with the requirements of the Bachelor of Engineering (Honours) in the
division of Computer Systems Engineering, I present the thesis entitled “Smart Light - A
Real Smart Object”. This work was performed under the supervision of Dr. Mark
Schulz.


I declare that the work submitted in this thesis is my own, except as acknowledged in
the text and footnotes, and has been previously submitted for a degree at the University
of Queensland or any other institution.




Yours sincerely,




MARK GAUCI.




                                                                                       ii
iii
To Leno, Joan, Nicholas, Jessica and Snowy.




                                              iv
                                      Abstract

A ‘Smart Object’ could be loosely defined as a product capable of learning a user’s
pattern of use and responding accordingly. The Smart Lamp is an instance of a ‘Smart
Object’.


It was anticipated that the Smart Lamp would be capable of monitoring the user’s use of
a desktop lamp. The system would then attempt to automatically control the lamp, with
no further input required from the user unless this learnt pattern required changing. This
aim was achieved.


The Smart Lamp, using it’s own user interface, including buttons and LCD display,
allows the user to operate the lamp in a simple and efficient way. As with any standard
lamp, the Smart Lamp accepts a standard 240V bayonet light bulb and requires mains
voltage. A passive IR detector is used by the system to determine when the user requires
the lamp to be in an operational mode. When the user does not require the lamp to be
operational, the light bulb is automatically turned off.


The learning algorithm used by the Smart Lamp to determine the user’s pattern of use of
the lamp is based on two previously developed algorithms - the tent roof tensioning
algorithm and double exponential smoothing. With these algorithms forming the basis
of the learning component of the lamp, the Smart Lamp performed extremely well under
four areas of testing - static operating conditions, slowly changing operating conditions,
rapidly changing operating conditions and under the influence of noise type inputs.
However, the system could not make meaningful predictions under a fluctuating pattern
of use.


It is anticipated that many of the principles used throughout the design of the Smart
Lamp would be comparable to those necessary for the creation of other ‘Smart Objects’
- such as a Smart Car, capable of monitoring, with the aim of automating, the driver’s
route home from work.




                                                                                         v
                           Acknowledgements

I would firstly like to thank my supervisor Dr. Mark Schulz whose guidance throughout
the development of this thesis was very much appreciated.


Mr. Geoff Walker supplied the light circuity used in the Smart Lamp. For this, along
with his help regarding the power electronics required in the product, I thank him.


I would also like to recognise the help of Len Payne, for his technical guidance and help
in ordering components, as well as the staff in the electronics workshop who provided
many of the components to realise the Smart Lamp.




                                                                                       vi
                                            Contents


Abstract ...................................................................................... v
Acknowledgements ................................................................... vi
Contents................................................................................... vii
List of Figures............................................................................ ix


1.0     Introduction .......................................................................1
        1.1      The ‘Smart Object’ ..................................................................2
        1.2      Possible Implementations of a ‘Smart Object’.........................3
        1.3      Overview of the Smart Lamp ...................................................4
        1.4      Overview of Report .................................................................5

2.0     Preliminary Research ........................................................7
        2.1      Programming by Demonstration .............................................8
        2.2      Active Learning .......................................................................8
        2.3      Online Learning.......................................................................9
        2.4      Memory Based Learning .......................................................11
        2.5      Statistical Methods for Learning ...........................................12
        2.6      Summary ..............................................................................14

3.0     Specification of the System .............................................15
        3.1      Basic System Description .....................................................15
        3.2      Requirements of the System
                 3.2.1   System controller
                 3.2.2   Learning algorithm
                 3.2.3   Motion sensor
                 3.2.4   Controller-light interface
                 3.2.5   User interface
        3.3      Summary...............................................................................19

4.0     Implementation of the Smart Lamp..................................21
        4.1      Basic Structure of System.....................................................21
        4.2      System Controller..................................................................22
        4.3      Learning Algorithm ................................................................26
                 4.3.1 Comparison of algorithms
                 4.3.2 Description of chosen learning progress
        4.4      Motion Sensor .......................................................................33
        4.5      Controller-light Interface........................................................35
        4.6      User Interface .......................................................................37
        4.7      Summary...............................................................................39



                                                                                                            vii
5.0   Results ............................................................................40
      5.1     Fine Tuning of Learning Algorithm ........................................40
              5.1.1 Smoothing constant α
              5.1.2 Tent roof radius r
      5.2     Testing of System .................................................................41
      5.3     Analysis of Results................................................................44
      5.4     Summary...............................................................................46

6.0   Project Review ................................................................47
      6.1     Summary of Project ..............................................................47
      6.2     Review of Technical Aspects of Project................................49
      6.3     Review of Managerial Aspects of Project..............................50


7.0   Future Modifications ........................................................51

8.0   Broader Implications of ‘Smart Objects’...........................52


Appendix A: References
Appendix B: Software Flowcharts
Appendix C: Software Listings
Appendix D: Parameter Testing Results
Appendix E: Double Exponential Smoothing Testing




                                                                                                         viii
                             List of Figures

Figure 1.    The Smart Lamp
Figure 2.    General Block Diagram of System
Figure 3.    Block Diagram of the System
Figure 4.    Detailed Overview of the System
Figure 5.    Memory Map of System
Figure 6.    Flowchart of Automatic Operating Mode
Figure 7.    Single vs. Double Exponential Smoothing
Figure 8.    Implementation of Calculation of Smoothed Coefficients
Figure 9.    Flowchart of learning software
Figure 10.   Implementation of Tent-Roof Tensioning
Figure 11.   IR Detector Schematic
Figure 12.   Timer Input Capture 2 Interrupt Routine
Figure 13.   Schematic of Light Circuitry
Figure 14.   Timer Input Capture Routine
Figure 15.   LCD Circuitry
Figure 16.   Method of Writing to LCD Driver
Figure 17.   Graph of Results under Static Use
Figure 18.   Graph of Results under Slowly changing conditions
Figure 19.   Graph of Results under Rapidly Changing Use
Figure 20.   Graph of Results under Noise Type Inputs




                                                                      ix
                                                                           Chapter 1: Introduction




1.0 Introduction


The Smart Lamp is a desktop lamp capable of learning a user’s pattern of use to allow
automatic control of the lamp’s intensity. The final product is shown in figure 1.




                                                                           240V
                                                                           lamp
      LCD display




         Pushbuttons

                                                                            IR detector




                                Figure 1. The Smart Lamp



The learning within the product is performed using two algorithms, double exponential
smoothing and tent roof tensioning.


Using the interface shown in figure 1, the user can adjust the lamp intensity as required.
Any such changes are monitored by the lamp to ensure that the performance of the
Smart Lamp reflects the current requirements of the user.


It was found that the system learnt small changes within 48 hours of retraining, whilst
72 hours was required for large changes.


The product incorporates a microprocessor and related circuitry, a LCD, push buttons
and a standard bayonet lamp. Within the microprocessor is the software that controls the
operation of the system.



                                                                                                1
                                                                           Chapter 1: Introduction




1.1    The ‘Smart Object’


The concept behind the ‘Smart Object’ is very similar to that of many other fields in
computer engineering, computer programming and psychology. That is, to realise a
method which has the capacity to learn. In particular, the principle of ‘Smart Objects’ is
based on learning online, rather than learning off-line before being placed in an
operational mode.


The implementation of a ‘Smart Object’ is dependent solely on the application. The
object could be anything from a piece of computer software to a silicon chip. Virtually
anything that has the capacity to learn online could be termed as a ‘Smart Object’.
However, it is anticipated that the principles used to design a ‘Smart Object’, such as the
Smart Lamp, would be comparable to those in other instances of ‘Smart Objects’.


The possibilities for ‘Smart Objects’ in a technology intensive age are virtually endless.
Mark Weiser’s concept of ubiquitous computing [15] is closely related to the ‘Smart
Object’. Weiser believes that in the near future, computers of various forms will
surround us. This concept is introduced to the area of video conferencing by Buxton [5]
to show how embedded systems can be developed to satisfy the requirements outlined
by Weiser. These computers will be embedded into everyday objects to make life easier.
However, although they will be everywhere, they will fit into their environments so well
that they become a necessary yet unobtrusive part of life.


Such embedded computers could easily take the form of ‘Smart Objects’.


Imagine a toaster that had the capabilities to monitor the cooking of bread to ensure that
the bread did not burn, a car that knew the way home from work or a television that
knew which station you wanted to watch. All of these instances are possible ‘Smart
Objects’. Ideally, a ‘Smart Object’ should, as specified by Weiser for ubiquitous
computers, be unobtrusive. Therefore, the ‘Smart Toaster’ should operate exactly like a



                                                                                                2
                                                                           Chapter 1: Introduction




normal toaster and require little to no programming by the user. Similarly, the car
should be able to realise the way home from work by monitoring the daily driving
patterns of the user, rather than the user having to explicitly program the car’s driving
route.


The Smart Lamp has the capacity to learn the pattern of use of a desktop lamp. The
system will be able to monitor the intensity of the lamp during the day and night to
provide for automatic control of the lamp.


The Smart Lamp will be based around the idea of a smart desktop lamp. The reason for
this is so that the system can be built in a self-contained unit, rather than having to be
connected to the wiring of a room’s lighting. However, the principles developed
throughout this thesis will also apply to standard room based lighting systems.




1.2      Possible Implementations of a ‘Smart Object’


The ‘Smart Object’ can take various forms. Essentially, any system that has the capacity
to learn online could be termed a ‘Smart Object’.


Ideally, this implementation would take the form a microcomputer which would be
small enough to be embedded within the product. Such a microcomputer would have
enough onboard RAM and ROM to allow extremely sophisticated algorithms to be used
to enable the online learning. Specifically, memory based learning could be used which
requires that all data be kept within the system infinitely, clearly not possible unless
large amounts of RAM are available.


Under such an algorithm, the system would be able to produce the learning required by
considering all the data captured by the ‘Smart Object’. Furthermore, assuming enough
ROM (where the learning software resides within the system), the system could
comprise a number of different learning algorithms and then these could be combined to


                                                                                                3
                                                                           Chapter 1: Introduction




provide an overall learning algorithm for the system. Such an approach could then
ensure that only the best elements of each algorithm are taken into account, therefore
providing the best learning possible.


Assuming such a system existed, the 24 hours of each day would be considered a
continuous system. This would ensure that the system was as accurate as possible. The
lamp would then be able to alter the lamp intensity every few minutes to provide the
best possible response.




1.3     Overview of the Smart Lamp


Clearly the Smart Lamp can only have a limited amount of both ROM and RAM. The
main limitation that arises from this is to restrict the number of learning algorithms that
can be used to perform the online learning of the system. Also, the amount of data that
can be stored is limited. Therefore, instead of the Smart Lamp being capable of
representing each 24 hours as a continuous function, the day will need to be discretised
to minimise the amount of data needed to be stored.


This learning takes the form of a statistical analysis to determine the pattern of use by
the user. Essentially, this involves the use of double exponential smoothing to allow the
pattern of use to change over time, therefore providing the online learning nature of the
system. An algorithm known as the tent roof tensioning algorithm is also used to
construct the flash map – the structure which contains the data required to determine the
correct light intensity. This algorithm ensures that the map produced is continuous in
nature that does not include spikes of data that may correspond to periodic hours of light
or no light.


The design incorporates an IR detector to determine when the user of the Smart Lamp is
in the room, and therefore allows the system to produce the required flash map.




                                                                                                4
                                                                           Chapter 1: Introduction




The Smart Lamp is contained within a single plastic box. It incorporates a built-in 240V
lamp, a LCD display and four push buttons. A reset button is also incorporated into the
lamp. The lamp requires a 12V supply, to power the controller circuitry and the IR
detector, and a 240V main supply to power the actual light bulb.




1.4     Overview of Report


This report will outline the various stages associated with the development of the Smart
Lamp.


The second chapter of this report will discuss in detail the research undertaken into the
area of smart objects, as well as other associated areas such as online learning, active
learning and programming by demonstration.


Chapter 3 will provide the specification of the system. This will include both the general
specification of the final product and the requirements of the learning algorithm required
to give the performance required from a ‘Smart Object’.


The fourth chapter will discuss the implementation of the Smart Lamp. This will include
the hardware, software and learning algorithm designs. The system controller will be
decribed, including both the hardware and software components. The implementation of
the learning algorithm will include both a comparison of the most appropriate
algorithms, as well as the form of the final algorithm to be used in the product. The need
for a motion sensor, a controller-light interface and a user interface will also be
discussed.


The results and a discussion of these results obtained from the Smart Lamp will be
provided in chapter 5. The selection of the parameters required for the learning
algorithm will be explained. The procedure followed to test the system will then be




                                                                                                5
                                                                            Chapter 1: Introduction




outlined, with the results of these tests provided along with a full analysis of these
results.


A project review will be provided in chapter 6. This will include a summary of the
project, as well as a review of both the technical and managerial aspects of the project.


Chapter 7 will outline a number of possible modifications that could be made to the
Smart Lamp to produce an even better product.


The concluding chapter will briefly discuss the broader implications that arise from the
development of the Smart Lamp, an implementation of a ‘Smart Object’.




                                                                                                 6
                                                                     Chapter 2: Preliminary Research




2.0 Preliminary Research


As the Smart Lamp is a ‘Smart Object’, it was necessary for a suitable learning
algorithm to be used. Therefore, it was necessary to investigate the possibilities to allow
an appropriate algorithm to be chosen.


This preliminary research required for Smart Lamp was undertaken in a number of
areas.


There were no existing products that could be found which were similar to the Smart
Lamp. In fact, there were very few examples of any types of ‘Smart Objects’ found. In
contrast, there were many examples of systems based on theories very close to the those
of ‘Smart Objects’. The areas, which were considered relevant for consideration, were:
•   programming by demonstration / teaching / example;
•   active learning;
•   online learning;
•   memory based learning; and
•   statistical methods which may form a basis of a learning algorithm.
The actual term ‘Smart Objects’ was not often used, though the above-mentioned areas
all have aspects in common with ‘Smart Objects’.


From the review of the literature, it was then possible to produce the specification of the
Smart Lamp.


It should be noted that the use of neural networks in this type of application is not
possible because of the real-time nature of the learning process in ‘Smart Objects’. In
contrast, neural networks are trained off-line using pregathered data. The trained system
is then placed into an operational environment. To provide for updated learning, the
system would need to be taken off-line and trained again with the refined data.




                                                                                                  7
                                                                    Chapter 2: Preliminary Research




2.1    Programming by Demonstration


The motivation behind programming by demonstration is that if a user knows how to
perform a task on a computer, then the user should be capable of creating a program to
perform this task on a repetitive basis [14, 16].


The fields of programming by demonstration / learning / example are very similar and
are generally used in PC based systems. Programming by demonstration involves the
end user demonstrating actions on example data. The computer then records and
possibly generalises these actions. The ability for the user to provide verbal or gestural
hints to the system to aid in the learning process is provided in programming by
teaching systems [16].


Generally, programming by demonstration systems are designed for graphical interfaces
[11, 13, 14]. In particular, they often take the form of windows based macros that can be
used to learn the actions of the user.


A more relevant system is discussed by Frank and Foley [13]. They provide details of an
integer interface application based on input examples being used to produce an output
variable. The input variables are considered as vector matrices and the system solves for
the output matrix using Gaussian elimination.




2.2    Active Learning


An overview of active learning is provided by Hamey and RayChaudhuri [8]. They
define the properties of active learning as providing improved generalisation and
reduced data costs, whilst passive learning relies on pregathered information. Hamey
and RayChaudhuri recognise the following as possible implementations of active
learning based systems:



                                                                                                 8
                                                                     Chapter 2: Preliminary Research




•   goal driven learning;
•   reinforcement learning; and
•   querying.


Goal driven learning is defined as being guided by goal based considerations. That is,
not only is the specified target outcome (knowledge) important but also the reason for
requiring such knowledge.


The use of trial and error interactions with the system environment is referred to as
reinforcement learning. It provides a computational approach to the study of learning
from this interaction. Markov Decision Process are usually well suited to representing
delayed reinforcement learning scenarios.


Learning by querying provides the learner with the ability to ask questions of the user.
This is done to acquire more useful data for learning. An implementation of this type of
system is provided by Kulkarni, Mitter and Tsitsiklis [10]. This system is capable of
asking binary valued questions of the user. These questions are either generated
randomly or are based on responses to previous questions. It is stated that this ability to
ask questions of the user separates the areas of passive and active learning.




2.3    Online Learning


Online learning is used to describe systems that are capable of learning whilst being
used by the user. The requirements of a learning algorithm in such a system are provided
by Heiss [9]:
1. Flash map - answer to query immediately.
2. Background adaptation - learning algorithm performed in background, with queries
    taking precedence.




                                                                                                  9
                                                                    Chapter 2: Preliminary Research




3. Arbitrary excitement - even if the same point is repeatedly updated for a long period
    of time, the algorithm must not forget the knowledge about all previously learned
    points.
4. Time variation - algorithm must be able to forget previous knowledge when more
    current information is received.
5. Avoid ‘adaptation holes’ - adjust the neighbourhood of point, not just the operating
    point.
6. Generalisation - the algorithm must be able to generalise the received update
    information in order to actualise the neighbourhood.
7. Robustness - the map should converge to the desired map.


Heiss provides a number of existing algorithms that do not meet one or more of the
above requirements. These are:
•   updating just particular input/output point - fails 5 and 6;
•   tent roof adding - similar to the previous algorithm but it also updates the
    neighbourhood of the operating point by adding a triangular ‘tent roof’ in the local
    neighbourhood of the operating point - fails 5 and 6;
•   spine interpolation within a window - uses spine interpolation techniques - fails
    requirement 3.


An algorithm that satisfies all the requirements, the tent roof tensioning algorithm, is
also provided by Heiss. This involves updating the operating point to the new value,
then it performs an actualisation of the neighbourhood points by linear interpolation
between the nodes yk(ε - r), yk and yk(ε + r).


Another method for developing online systems, Hidden Markov Models (HMMs), is
described by Lee and Yangsheng [2]. The system described by Lee and Yangsheng is
used to learn human gestures for robot interface learning. The HMMs are utilised to
learn these human gestures by assuming the gestures are a doubly stochastic process.
That is, they are Markov processes whose internal state is not observable. A Markov
process is a random process that, given a present state, has a future independent of it’s



                                                                                                10
                                                                     Chapter 2: Preliminary Research




past. For every state transition in such a process, the system generates an observable
output signal whose value depends on a probability distribution that is fixed for each
internal state. Such a system assumes the gestures are discrete HMMs.


The process used to train the system is provided by Lee and Yangsheng:
1. The user makes a series of gestures.
2. The system attempts to classify each gesture in real-time. If it can be classified, it
       performs the action. If not, the user is queried.
3. The system adds the symbols of the encoded gesture to a list of example sequences
       before it retrains the HMM.


HMMs are commonly used for speech recognition, but are also used in characterising
task information and human skills for the transferal to robots in telerobotic applications
[2].


The three main problems associated with HMMs are considered to be:
1. Determining the probability with which a given sequence of observable symbols
       would be generated by a HMM.
2. Determining the most likely sequence of internal states in a given HMM which
       would have given rise to a given sequence of observable symbols.
3. Generating a HMM that best explains a sequence or set of sequences of observables.




2.4       Memory Based Learning


Atkeson [4] defines memory based learning as the process of storing all received data to
enable the production of a model every time the system is queried. It is based on an
algorithm used for robot learning. Locally weighted regression is used by Atkeson to
answer the query.


The stages of the locally weighted regression performed by Atkeson are as follows:



                                                                                                 11
                                                                     Chapter 2: Preliminary Research




1. All initial experiences are simply stored in memory.
2. When required, the system performs a weighted regression to answer a query. The
   weights in the regression depend on the ‘fit parameters’.
3. The ‘fit parameters’ can be optimised using cross validation.


A limitation of memory based learning is the requirement for all data to be stored in the
system, with no algorithms yet determined to allow for the removal of non-critical data.




2.5    Statistical Methods for Learning


A variety of statistical methods have been used to produce algorithms capable of online
learning.


Atkeson and Moore [17] discuss the use of locally weighted regression in lazy learning -
a system where processing of data is deferred until a query requires answering. The
requirements for such a method to be employed are described as follows:
1. Distance function - the system requires a measurement of relevance. It is assumed
   that the relevance can be measured from the distance, with the nearby training points
   being more relevant.
2. Separable criteria - the system applies a weight to each piece of training data.
3. Enough data - there must be enough data to compute the statistics.
4. Labeled data - each training point needs to have an associated output.
5. Representations - each object must produce a fixed length vector of the values for a
   list of specified features x = (x1 x2 ... xn)T.


Other models such as nearest neighbour (where the closest point is chosen) and
weighted averages (average of the outputs of the nearby points, inversely weighted to
the distance from the query point) are also discussed by Atkeson and Moore.




                                                                                                 12
                                                                     Chapter 2: Preliminary Research




Locally weighted regression is also used by Cohn, Ghahramani and Jordan [6] in
preference to neural networks for active learning based systems. They demonstrate that
such mathematical techniques have good predictive power whilst they are capable of
being computed cheaply.


The DOPPELGANGER system, an electronically generated personalised newspaper
described by Orwant, uses a variety of statistical methods for its modeling of the user
[12]. Linear prediction is used to predict when the reader will read the newspaper again.
That is, it attempts to determine the occurrence and duration of an event. The algorithm
uses autocorrelation of the data sequence to predict future values. Significantly, this
algorithm tends to weight short term data more than long term data. Whilst the
confidence of linear prediction is based on how far into the future the predictions are
made, beta distributions, which are used by DOPPELGANGER to determine the articles
of interest to the user, have confidences related to the number of past observations.


Another method that provides for the weighting of more recent data in preference to
older, perhaps irrelevant data, is exponential smoothing [1]. This technique uses
weighted averages to ensure that the most current data has the greatest affect on the
learned data. The use of parameters allows the user to set the affect of new data on the
learned data.


An extension of simple exponential smoothing is double exponential smoothing [1].
This involves the use of two smoothed statistics to determine the forecast.


Both simple and double exponential smoothing are used in forecasting applications. One
advantage of these methods is that only small amounts of data are required to be stored
to provide for the forecasts to be made.




                                                                                                 13
                                                                     Chapter 2: Preliminary Research




2.6    Summary


This chapter has investigated a number of algorithms that could be of significance in the
development of a ‘Smart Object’. As very little work has been done in the area of
‘Smart Objects’ itself, it was necessary to look at other related fields. These included
programming by demonstration, active learning and online learning.


Having performed this initial research, the specification of the product, including that of
the learning algorithm, could be determined.




                                                                                                 14
                                                                       Chapter 3: Specification of the System




3.0 Specification of the System


With the preliminary research into algorithms that could be considered for use within a
‘Smart Object’ completed, the complete specification of the system could be considered.


This specification includes both the basic functionality of the system as well as the
individual components of the product, including the learning algorithm, the system
controller, the motion sensor, the controller-light interface and the user interface.




3.1     Basic System Description


The broad specifications of the Smart Lamp are as follows:
•   to learn in an online manner the user’s pattern of use of a lamp’s lighting levels with
    respect to the time of day;
•   be able to operate with only small amounts of user intervention;
•   allow the lamp to operate in a normal manual mode or in an intelligent mode; and
•   to only have the lamp on when someone is in the room.


The general block diagram of the system in shown in figure 2.



                  4                                                        SWITCHED ACTIVE
    USER
    INPUTS
                                  OVERALL SYSTEM                            LCD DISPLAY

    IR DETECTOR

    ACTIVE




                           Figure 2. General Block Diagram of System



Following the initialisation of the system, a learning mode will be entered to allow the
system to learn the user’s pattern of use. This mode will require the user to operate the



                                                                                                          15
                                                                 Chapter 3: Specification of the System




lights with the buttons on the interface. The system will recognise these actions and
attempt to learn the pattern of use of the lamp with respect to the time of day. It is
anticipated that such a learning process would take approximately 7 days to provide for
a suitable basis upon which the system will be able to automatically control the room’s
lights.


Once the user believes that the system has been taught sufficiently, the user then places
the system into automatic mode. This mode will attempt to determine the required
intensity of the light and then adjusts the lamp to this level. In this mode, the user may
still adjust the intensity of the lamp. Such a change will be processed by the system and
will result in a continuation of the learning process. This property of the system will
provide for the online learning capacity of the Smart Lamp.




3.2       Requirements of the System


To achieve the basic description described, the system will require a number of
elements. These are:
•   a learning algorithm capable of performing online;
•   a system controller;
•   a motion sensor;
•   a controller-light interface; and
•   a user interface.




3.2.1 System controller


The controller of the system will represent the 24 hours of each day as 24 one hour time
blocks. Correspondingly, the system will learn the pattern of use for each of these 24
blocks. This discretisation of the 24 hours is done primarily to simplify the




                                                                                                    16
                                                                  Chapter 3: Specification of the System




programming of the system and to reduce the amount of data recorded by the system.
Such a process is not expected to reduce the performance of the system significantly.


The form of such a controller will need to be small enough to be able to be used in a
standard plastic box capable of being used as the base of a desktop lamp.




3.2.2 Learning algorithm


To allow the lamp’s lighting level to be learnt, the selection of a suitable learning
algorithm is necessary. As the principle of a ‘Smart Object’ is to learn whilst being in an
operational mode, the learning algorithm must be capable of learning both when the
system is initially installed and during the general operation of the system.


The learning algorithm used for the online learning of the Smart Lamp must satisfy a
number of requirements. The most critical are:
•   to weight recent data more than older, perhaps stale, data; and
•   to not be affected by singular or ‘one-off’ instances.


The first requirement ensures that the system can infact learn. For example, assuming
the system was initially taught in summer, then the lamp would probably be taught to go
on later than would be required in winter. However, with this requirement satisfied, the
algorithm, with the necessary input from the user, will be adaptable and will be capable
of reflecting these changing conditions.


The second requirement prevents ‘one-off’ inputs from the user having large effects on
the system. Consider that one day is particularly dark (perhaps due to storms) and the
user wants the lamp on all day. The algorithm should ensure that such an occurrence
does not result in the lamp coming on all day from then on. This ensures that only
patterns of use are considered by the system, and not simply the last 24 hours of use.




                                                                                                     17
                                                                   Chapter 3: Specification of the System




However, if the user has the lamp on all day for a number of days in a row, the system
must be capable of realising that this is probably a pattern of use, rather than a one off
occurrence. This should therefore result in a dramatic change in the system’s learnt
pattern.


The requirements of an online learning algorithm presented by Heiss [9] are also of
importance. Those of relevance to this system are:
•   Flash map - answer the query immediately - this ensures that the lights come on at
    the required intensity as soon as the user enters the room.
•   Background adaptation - learning algorithm performed in background with queries
    taking precedence - ensures system satisfies the flash map requirement.
•   Arbitrary excitement - even if the same point is repeatedly updated for a long period
    of time, the algorithm must not forget the knowledge about all previously learned
    points - consider the system is only used for a period of a month at night. The system
    should still know the relevant lighting intensities for the other times of the day.


However, the other requirements specified by Weiss cannot be supported by this system.
The primary difference is the time variation requirement that implies that new data
overwrites previously stored data, therefore allowing ‘one-off’ instances to affect the
system.




3.2.3 Motion sensor


The use of a motion sensor is required to provide the system with the ability to realise
when someone is in the room, therefore waking up the system to ensure that the relevant
lighting intensity is set for that time period.




                                                                                                      18
                                                                 Chapter 3: Specification of the System




3.2.4 Controller - light interface


To allow the system to control the lighting intensity of a desktop lamp, it is necessary
for the product to be able to dim and brighten the lights from the main controller. The
form of this interface is obviously largely dependent on the controller chosen for the
system.




3.2.5 User interface


The product requires a user interface to enable interaction between the system and the
user. Specifically, this will include displaying the time, light intensity and mode to the
user, as well as buttons to allow the user to set the time, mode and light intensity. As a
‘Smart Object’ is designed to make life easier for the user, it is important that the user
interface makes the lamp easy to operate.




3.3    Summary


The specification of the Smart Lamp presented the requirements of each of the sections
of the product.


The need for a suitable system controller, motion sensor, controller-light interface and
user inputs has been discussed.


In terms of the learning requirements of the system, it was determined that the algorithm
would need to satisfy a number of properties. These were that the basis of the system is
a flash map which is capable of responding to a query as soon as it required, it uses
background adaptation to allow the processing of the data to be performed in the
background to give priority to queries from the controller, and to ensure that elements of
the flash map that are not being updated are retained by the system until necessary.



                                                                                                    19
                                                           Chapter 3: Specification of the System




Having developed the specification of the product, the implementation of the Smart
Lamp can be considered.




                                                                                              20
                                                                Chapter 4: Implementation of the Smart Lamp




4.0 Implementation of the Smart Lamp


Having completed the specification of the product, the implementation of the Smart
Lamp follows.


This essentially involves meeting each of the aspects presented in the specification of
the product, namely the learning algorithm, the system controller, the motion sensor, the
controller-light interface and the user interface.




4.1       Basic Structure of System


The block diagram of the system is provided in figure 3.


    + INPUT
                                                                          LAMP OUTPUT
      - INPUT
         SET
                                OVERALL SYSTEM                            LCD DISPLAY
      MODE

      IR DETECTOR

    ACTIVE




                             Figure 3. Block Diagram of the System



Due to the nature of the product required, it was decided that the most effective
controller for the system would be a microcontroller. Such a controller would consist of
both a microprocessor and suitable controlling software.


The learning component of the Smart Lamp is based on two separate algorithms –
double exponential smoothing and tent-roof tensioning. The use of these algorithms in
terms of the implementation of a ‘Smart Object’ will be discussed, along with an
extended theory of the algorithms.




                                                                                                        21
                                                                 Chapter 4: Implementation of the Smart Lamp




The hardware includes an onboard microcontroller, a LCD display and light circuitry to
allow the lamp to be controlled using the microcontroller. A motion detector was also
required to allow the system to know when there was a person in the room.


The system incorporates 4 push buttons. Two of the button are used to increase (+) the
light intensity and decrease (-) the light intensity. The third button allows the time to be
set and the fourth changes the operating mode of the system.


A detailed overview of the system is provided in figure 4.




                         MOTION                                                LIGHT
                                                 LCD DISPLAY                  CIRCUITRY
                         SENSOR




      USER INPUTS
                                             MICROCONTROLLER




                                              POWER SUPPLY
                                               12V and 240V




                           Figure 4. Detailed Overview of the System




4.2      System Controller


The microcontroller used is the 68HC11 in expanded mode. This setup allows external
memory to be used with the system. Specifically, the system incorporates 8 KB of
external ROM in which the system controller and learning component of the software
resides and 8 KB of RAM used to store the data collected by the system.



                                                                                                         22
                                                                  Chapter 4: Implementation of the Smart Lamp




The microcontrollers that were considered for use within the system were the Motorola
microcontrollers 68HC05, 68HC11, 68HC12 and the 68HC912. The Hitachi H8 and
SH-1 were also considered.


As it was clear from the specification of the system that the microcontroller required
would not need to be particularly sophisticated, it was decided to use a Motorola
microcontroller as this family has been used before in similar instances.


The main difference between the different Motorola microcontrollers is the amount of
onboard memory (RAM and ROM). As support for the 68HC11 was far greater than the
other Motorola microcontrollers, this was chosen as the microcontroller. To allow the
required amount of memory to be incorporated within the system, the 68HC11 expanded
mode can be used to allow for external memory connections.


The memory map of the system is shown in figure 5.


                          0x0000 - 0x00FF        ONBOARD RAM

                          0x1000 - 0x103F         REGISTERS
                                                       .
                                                       .
                         0x6000 - 0x7FFF         EXTERNAL EPROM
                                                       .
                                                       .
                         0xA000 - 0xBFFF          EXTERNAL RAM
                                                       .
                                                       .
                         0xD000 - 0xD003            LCD DISPLAY
                                                       .
                                                       .
                         0xF800 - 0xFFFF        ONBOARD EEPROM




                                Figure 5. Memory Map of System


The controller’s software uses the 68HC11 to control the general operation of the
system. This software was written in the C programming language.



                                                                                                          23
                                                              Chapter 4: Implementation of the Smart Lamp




The specific functions provided by the software are to allow the setting and to keep the
system time, control the LCD driver/display, control the intensity of the lights and to
provide for the user to change the system’s mode of operation.


The flowcharts for all of the separate functions implemented in the software are
included as appendix B.


The basic operation of the system initialises the separate components and then waits for
an interrupt from the user. An interrupt could be caused by the motion detector of the
user depressing a button.


The operating mode of the system can be set using the mode button. These operating
modes are:
1. Learning mode;
2. Automatic mode; and
3. Test mode.


The first mode, learning mode, monitors the user’s pattern of use and develops a flash
map capable of automatically monitoring the system’s lamp intensity. However, under
this mode, the light is not automatically changed. This mode in useful when the system
is being retrained in a manner considerably different to the previous way the lighting
was used.


The automatic mode also monitors the user’s pattern of use, but in contrast to the
learning mode, automatically controls the lamp. Therefore, when the user activates the
IR detector, the system determines the light intensity that it has learnt for that time. This
intensity is then translated into a light intensity on the lamp. While in automatic mode,
the user still has the freedom to adjust the light intensity as necessary. Any changes
made by the user causes the system’s flash map to be updated.




                                                                                                      24
                                                                                     Chapter 4: Implementation of the Smart Lamp




The flowchart corresponding to this automatic mode of operation is shown below.




                                                               Start




                                                            Wait for User




                                            no
                                                          Person in Room


                                                                    yes




                                                      Load Learnt Light Intensity




               Add Intensity to Algorithm
                           &                              Person left Room
                     Turn off Light
                                             yes

                                                                       no




                                                         Light Int. Changed           Update Light Intensity
                                                 no                            yes




                            Figure 6. Flowchart of Automatic Operating Mode



The third mode is a test mode that is included to test the general operation of the
product. No learning is attempted in this mode.


Initially, the system is in learning mode. Once the user believes that the Smart Lamp has
been trained sufficiently, it is expected that automatic mode will be entered to allow for
the automation of the lamp.



                                                                                                                             25
                                                               Chapter 4: Implementation of the Smart Lamp




The system time must be kept by the system as it is this by which the learning is
monitored. Once the system time is set, the time will be updated every minute until the
system is shut down. The time is kept using the 68HC11’s timer output compare 2
interrupt. This interrupt is set to fire every two milliseconds.




4.3    Learning Algorithm


4.3.1 Comparison of algorithms


Learning algorithms that provide for online learning are used in many applications
including the DOPPELGANGER electronic newspaper [12] and human/robot interfaces
[2]. There also exist a number of algorithms that have been proposed for use in an
online environment. These include the tent roof adding and tensioning algorithms
proposed by Weiss [9], and a variety of statistical methods with which learning can be
achieved [1, 4, 6, 12, 18].


As previously discussed, the DOPPELGANGER system incorporates a number of
algorithms with which it models the user. The particular method that is relevant the
Smart Lamp is linear prediction. This uses autocorrelation of a data sequence to predict
future values. It tends to weight short term data more than older data and therefore
satisfies one of the requirements of the algorithm.


The HMMs described by Lee and Yangsheng [2] are also capable of being taught online,
but the need for the system to be represented as a set of states is clearly not suitable.


A number of existing systems utilise locally weighted regression to perform online
learning. These include those discussed by Atkeson [4], Cohn, Ghahramani, and Jordan
[6] and Atkeson, Schaal and Moore [18]. None of these systems however satisfy both of
the requirements of the learning algorithm for the system.



                                                                                                       26
                                                           Chapter 4: Implementation of the Smart Lamp




The tent roof algorithms [9] satisfy a number of requirements of the algorithm.
However, these algorithms simply update the flash maps when new values are added to
the systems, and therefore ‘one-off’ events have a marked effect on the system. This is
clearly unacceptable.


However, with the inclusion of exponential smoothing, as described by Bohas [1], a
suitable algorithm can be implemented in software. This model uses exponential
smoothing to perform forecasts of future events given prior events. The advantage of
this method over many of the other models is that is uses integer values to represent the
data. This contrasts with the graphical interfaces for programming by demonstration
systems and states for HMMs.


Therefore, using exponential smoothing ensures that the problems associated with tent-
roof tensioning, the impact of ‘one-off’ instances, is limited and does not have dramatic
effects on the flash map produced by the system.




4.3.2 Description of chosen learning process


The learning algorithm used in the Smart Lamp was developed from these two different
algorithms - the tent roof tensioning algorithm and double exponential smoothing.


Weighted regression, or more specifically exponential smoothing, is used in forecasting
applications to determine averages that change over time. Bohas [1] provides a thorough
discussion on exponential smoothing in numerically based systems.


The theory of exponential smoothing will now be provided.


Assume that zn is the nth piece of data received by the system where exponential
smoothing is being used to make forecasts of future occurrences.



                                                                                                   27
                                                              Chapter 4: Implementation of the Smart Lamp




The expression
       Sn = (1 - ω)[ zn + ωn-1 + ω2zn-2 + ....]
           = α [zn + (1 - α)zn-1 + (1 - α)2zn-2 + ...]
is called the smoothed statistic or the smoothed value.


The last available smoothed statistic serves as the forecast for all future observations.


For the updating of Sn,
       Sn = (1 - ω)zn + ωSn-1
           = Sn-1 + (1 - ω)[zn - Sn-1].


The initial value of the smoothed statistic, S0, Makridakis and Wheelwright (1978) [1]
used the first observation as the smoothed statistic → S0 = z1.


The smoothing constant α determines the extent to which past observations influence
the forecast. A small α results in a slow response to changes in the level. A large α
results in a rapid response. By adjusting this parameters the two requirements of the
system – to weight recent data than older data and to not be affected by ‘one off’
instances too greatly - can be satisfied.


Therefore, the system can use exponential smoothing for each time period to perform
the online learning nature of the system.


Clearly, this algorithm satisfies the first requirement of the system - to provide online
learning. The amount the system learns from each piece of data is related to the
parameter α. The second requirement, to prevent ‘one-off’ instances greatly affecting
the system, is also satisfied with this algorithm. Again, the parameter α determines the
extent to which the new data affects the system.




                                                                                                      28
                                                                 Chapter 4: Implementation of the Smart Lamp




The other requirements of the system, namely the properties of a flash map, background
adaptation and arbitrary excitement, are not violated by exponential smoothing.


To utilise exponential smoothing as the learning algorithm in this system, each hour of
each day has a corresponding smoothed statistic. This smoothed statistic will gradually
evolve over time to follow the user’s pattern of use.


As previously mentioned, an extension of simple exponential smoothing, known as
double exponential smoothing, exists which uses two smoothed statistics to make the
required forecast. These smoothed statistics,
       ST[1] = αz + (1 - α)ST-1[1]
       ST[2] = αST + (1 - α)ST-1[2]
are used to make the forecast as follows:
       zt+1 = (2 + α / (1 - α))ST[1] - (1 + α / (1 - α))ST[2].


It was found that this algorithm provided more acceptable performance than simple
exponential smoothing and was therefore chosen. Figure 7 indicates the performance of
the two algorithms under rapidly changing operation conditions. From this, it is clear
that double exponential smoothing provides a more acceptable solution than single
exponential smoothing.


Whilst double exponential smoothing was able to satisfy a number of the requirements
of the learning algorithm, namely
•   the system learns - i.e. more recent data is weighted more heavily than older data;
•   the query from the system can be answered immediately (flash map);
•   the calculations required to process the algorithm can be performed in the
    background (background adaption);
•   the system will remember data that has not been changed (arbitrary excitement),
there is one requirement that is not satisfied by the double exponential smoothing
algorithm. That is that there is no smoothing of the data between time periods to ensure




                                                                                                         29
                                                                                                            Chapter 4: Implementation of the Smart Lamp




that the resulting flash map produced by the algorithm does not fluctuate considerably
between neighbouring time periods.



                                              Single vs. Double Exponential Smoothing: Rapidly varying inputs

                    9


                    8



                    7


                    6
  Light Intensity




                    5
                                                                                                                                          Expected
                                                                                                                                          Double Exp. Output
                                                                                                                                          Single Exp. Output
                    4


                    3


                    2


                    1


                    0
                         1   2   3   4   5    6    7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24
                                                                     Time (hours)



                                                  Figure 7. Single vs. Double Exponential Smoothing



To solve this problem, the algorithm proposed by Heiss [9] was used on the data from
the preceding double exponential smoothing stage to produce the required flash map.


Heiss’ algorithm, known as the tent roof tensioning algorithm, produces the required
elements in the flash map using the following formula:


                                     y(ξ) + (yk(ξ + r) - y(ξ))(xi - ξ) / r                        if 0 <= xi - ξ < r
                        yk+1 =       y(ξ) + (yk(ξ - r) - y(ξ))(ξ - xi) / r                        if 0 < ξ - xi < r
                                     yk(xi)                                                       if | ξ - xi | >= r




                                                                                                                                                    30
                                                                  Chapter 4: Implementation of the Smart Lamp




By applying this algorithm to the data produced from the preceding double exponential
smoothing stage, a flash map was continuously being created which satisfied all the
requirements of the system.


The parameter included in the algorithm is known as the tent roof radius. This
determines the range that will be affected by a single update. For example, for a small r,
only those points near the operating point will be affected by the update. In contrast, for
a large r, a large range of the map will be affected by a single update.


The flowchart showing these two stages, which was implemented in software, is shown
in figure 9.


The algorithm firstly applies the double exponential smoothing algorithm to the newly
acquired data. From this, the smoothed coefficients are determined which are then
inputted to the tent roof tensioning algorithm. The calculation of these coefficients is
shown in figure 8.


/* Calculate smoothing coefficients */
s1[time_period] = (a * intensity + w * s1[time_period]) / 100;
s2[time_period] = (a * s1[time_period] + w * s2[time_period])/ 100;
new_factor = (a * 100) / w;
intensity_add = ((200 + new_factor) * s1[time_period] - (100 + new_factor) *
s2[time_period]) / 100;


                 Figure 8. Implementation of Calculation of Smoothed Coefficients




                                                                                                          31
                                                                     Chapter 4: Implementation of the Smart Lamp




                                                  Start




                                               Initialisation




                                          Calculate Smoothing
                                              Coefficients




                                        Use Tent Roof Tensioning
                                          to Update Intensities




                                        Check to Ensure all Values
                                              are in Range




                                                  Return




                            Figure 9. Flowchart of learning software



The flash map is then updated by the tent roof tensioning algorithm to provide the
online nature of the system. This is shown in figure 10.




                                                                                                             32
                                                                Chapter 4: Implementation of the Smart Lamp




/* Update current operating point */
time[time_period] = intensity_add;

/* Perform tensioning for update point to r */
for (i = (time_period + 1); i < (time_period + r); i++) {
       end_period = time_period + r;

       if (end_period > 23)
              end_period = end_period - 24;
       if (i > 23)
             time[i - 24] = intensity_add + ((time[end_period] –
                intensity_add) * (i – time_period) / r);
       else
              time[i] = intensity_add + ((time[end_period] – intensity_add) *
                (i – time_period) / r);
}

/* Perform tensioning for –r to update point */
for (i = time_period – r; i < time_period; i++) {
       start_period = time_period – r;

               if (start_period < 0)
                      start_period = start_period + 24;
               if (i < 0)
                      time[24 + i] = intensity_add + ((time[start_period] -
                        intensity_add) * (time_period – i) / r);
               else
                      time[i] = intensity_add + ((time[start_period] –
                        intensity_add) * (time_period – i) / r);
}

                       Figure 10. Implementation of Tent-Roof Tensioning



The flash map is then checked to ensure that all the values are within the required range.




4.4    Motion Sensor


To allow the system to determine whether there was anyone in the room that was being
monitored, a motion detector was required.


A simple infrared link was also considered to provide for the system to determine when
the doorway way was crossed, but this had serious limitations (e.g. if there is more than
one doorway in the room) and was therefore disregarded.


A standard PIR detector was purchased for use in the system. This detector is capable of
monitoring a 90° angle at a distance of approximately a 10 × 10 metre square.




                                                                                                        33
                                                                   Chapter 4: Implementation of the Smart Lamp




The detector was used to provide an interrupt when activated. The circuitry required for
this is shown in figure 11.




                                Figure 11. IR Detector Schematic



If no person has activated the sensor in 2 minutes, the light is turned off. The light is
reactivated when the sensor indicates the user has returned to the room.


To stop the system from having to continuously service this interrupt, the interrupt,
timer input capture 2, is disabled for 1 minute. Following this minute, the sensor
interrupt is re-enabled. The interrupt routine is shown in figure 12.


interrupt tic2_isr()
{
       TFLG1 = BIT1;
       TMSK1 ^= BIT5;                            /* disable further interrupts */

       /* turn lights back on if automatic mode */
       if (sensor_set == 0) {
              if (mode == 2) {
                     light_counter = time[current_period];
              }
       }
       sensor_set = 120;
}

                        Figure 12. Timer Input Capture 2 Interrupt Routine


This routine shows how the light intensity is automatically placed onto the lamp using
the learned flash map table[] when the system is awakened whilst in automatic mode.




                                                                                                           34
                                                           Chapter 4: Implementation of the Smart Lamp




4.5      Controller-light Interface


Initially it was anticipated that this might take the form of a commercial product that
would be capable of converting either a digital or analogue input to a specific light
intensity. However, such a device was not found and therefore other methods of
controlling the intensity of a light were investigated.


There were three different interfaces considered after a commercial product could not be
purchased. The first method was to use a remote controlled light panel and generate the
infra red signals from the system’s controller. The second was to use a circuit outlined
in the March edition of Electronics Australia. This circuit incorporated an up/down pin,
and address valid pin and a clock. The third alternative was to use a circuit designed by
a lecturer at The University of Queensland, Mr. Geoff Walker. This circuit sends a
signal to the controller every time the supply voltage (240V, 50Hz) crosses zero (a 50Hz
signal) and accepts a low going pulse to allow the light to be turned on. The time
between the output of the 50Hz signal and the low going pulse sets the intensity of the
light.


As the method of control for Geoff Walker’s light circuitry was simple with the 68HC11
(using input capture and output compare) and the circuitry had already been built and
could therefore be used in the prototyping stages of the product, this was the interface
chosen.


The schematic diagram of this circuit is shown in figure 13.




                                                                                                   35
                                                                      Chapter 4: Implementation of the Smart Lamp




                                 Figure 13. Schematic of Light Circuitry



The form of this light circuitry chosen was a desktop lamp. However, as already stated,
the principles developed are exactly the same as those that would be used in a standard
wall based lighting product.


The light intensity can be changed by simply pressing either the + or - buttons. These
buttons cause the controller to change the delay between the 50Hz from the low going
pulse to the light controller.


As mentioned previously, this is done using timer input capture and timer output
compare. The low going pulse from the light interface triggers the input capture. The
system then delays the firing of the output compare, which causes the light to be turned
on, a sufficient amount of time to provide the intensity expected by the user.




                                                                                                              36
                                                                Chapter 4: Implementation of the Smart Lamp




The relevant input capture routine is provided in figure 14.

interrupt tic1_isr()
{
       TOC3 = TIC1 + 100 + 2000 * light_counter;          /* set delay */
       TFLG1 = BIT2;
       TCTL1 = 0x20;                                 /* set to go low */
       TFLG1 = BIT5;
       TMSK1 = TMSK1 | BIT5;                 /* enable output compare */
}

                            Figure 14. Timer Input Capture Routine




4.6    User Interface


Having chosen a microcontroller to control the system, it seemed apparent that the most
suitable method of displaying information to the user was through the use of a LCD.


The two main types of displays possible were the standard 7-segment displays and the
alphanumeric displays. The 7-segment displays generally involved the use of separate
displays and controllers, whilst the alphanumeric displays contained both the display
and controller onboard.


As the main need for the LCD was to display the time, it was decided that the standard
7-segment display would be the simplest and most appropriate selection in this case.


As the 68HC11 was being utilised in expanded mode, the LCD needed to be able to be
placed in the memory map of the 68HC11. This was possible with the 4-digit LCD
driver ICM7211. This driver accepts a binary coded decimal and drives the required
segments of a LCD display, as well as providing the necessary backplane frequency. As
the driver can be placed in the memory map, the method used to write to the LCD is
straightforward. The simplicity of the connections required between the LCD driver and
display is shown in the figure 15.




                                                                                                        37
                                                                     Chapter 4: Implementation of the Smart Lamp




                                     Figure 15. LCD Circuitry


The LCD is used to display the current light intensity (0-9), the system mode as well as
the time at different stages of operation.


The method of writing to the LCD display is extremely simple. Figure 16 shows how
the greeting which appears when the system is turned on, ‘HI’, is written to the display.


/* Definitions */
#define         DIGIT1                 (*(unsigned     char     *)   0xD003    )
#define         DIGIT2                 (*(unsigned     char     *)   0xD002    )
#define         DIGIT3                 (*(unsigned     char     *)   0xD001    )
#define         DIGIT4                 (*(unsigned     char     *)   0xD000    )

start_lcd()
{
       DIGIT1   =   0x0F;                                                          /* blank */
       DIGIT2   =   0x01;                                                              /* I */
       DIGIT3   =   0x0C;                                                             /* H */
       DIGIT4   =   0x0F;                                                          /* blank */
}

                            Figure 16. Method of Writing to LCD Driver




                                                                                                             38
                                                             Chapter 4: Implementation of the Smart Lamp




It was also necessary for the user to be able to control the Smart Lamp through the use
of four functions. The four inputs - the mode, set, up and down pushbuttons – are also
connected to an interrupt of the 68HC11, the pulse accumulator.


The hardware design of the user inputs, including a D flip flop for each of the
pushbuttons, ensures that software debouncing is not required. Once one of the
pushbuttons is depressed, the corresponding D flip-flop is set. As the D flip-flop outputs
are OR-wired to the pulse accumulator bit, the interrupt routine is then entered. The D
flip-flop outputs are also each connected to a bit of PORT E of the 68HC11. The
interrupt routine is then able to read PORT E to determine which button was depressed
and then set the appropriate flag. The routine then clears the flip-flops before returning.




4.7    Summary


This chapter has discussed the implementation of the Smart Lamp corresponding to the
specification provided in chapter 3.


This has involved providing a basic structure of the system, discussing the system
controller, presenting the learning algorithms and outlining the design of the motion
sensor, controller-light interface and the user interface.


With the product built, the necessary testing along with a review of it’s performance was
undertaken.




                                                                                                     39
                                                                                Chapter 5: Results




5.0 Results


Having completed the implementation of the Smart Lamp, it was necessary to test the
product’s performance under a range of conditions.


Firstly though, it was necessary to fine tune the learning algorithm by selecting the
appropriate values for the parameters used within the algorithms. The testing was then
undertaken, followed by a full analysis of the results obtained.




5.1 Fine Tuning of Learning Algorithm


The two parameters which were required in the learning algorithm were the smoothing
constant, α, and the tent roof radius, r.




5.1.1 Smoothing constant α


The smoothing constant determines the extent to which past observations made by the
system influence the forecast, or, in this instance, the flash map being created. In
general, a small α results in a slow response, whilst a large α result is a rapid response.


Bovas [1] recommends a constant between 0.7 and 0.95.


To allow the smoothing constant to be determined, it was necessary to set a value for the
tent roof radius. It was deemed that a radius of 4 would be an acceptable value.


To test the smoothing constant, a simple program was developed to simulate the
learning algorithm used within the Smart Lamp. Using this program, a number of
smoothing constants, namely 0.7, 0.75, 0.8, 0.85 and 0.9 were tested on two sets of data.



                                                                                               40
                                                                              Chapter 5: Results




The first was a slowly changing set of data, which attempted to test the performance of
the constant under normal operating conditions. The second set included extreme data
that was included to simulate rapidly changing conditions.


From the results in appendix D, it was clear that a smoothing coefficient of 0.75 was
most appropriate.




5.1.2 Tent roof radius r


The tent roof radius is used in the tent roof tensioning algorithm to determine the range
of the update area. Therefore, a small radius will cause only a small part of the map to
be updated, whilst a large r will cause a larger range of the map to be updated.


It was deemed that a radius between 2 and 8 would be most appropriate. Therefore,
using the same test conditions as those for the determination of the smoothing constant,
the algorithm was tested with a tent roof radius of 2, 3, 4, 5, 6, 7 and 8. The results of
these tests are included in appendix D.


From these tests, it was deemed that a radius of 6 was most appropriate.




5.2    Testing of System


Having determined the most appropriate value for the parameters - α = 0.75, r = 6 - it
was necessary to test the performance of the system under a range of different operating
conditions. These different operating conditions were:
1. Static conditions - the user does not interfere with the system;
2. Slowly changing conditions - the user requires only small changes to be made to the
   flash map;




                                                                                             41
                                                                                                                                         Chapter 5: Results




3. Rapidly changing conditions - the user requires large changes to be made to the flash
   map in relatively short time periods;
4. Fluctuating conditions - the use of the system fluctuates from one extreme to
   another; and
5. Noise type inputs - ‘one off’ or rare changes made by the user which should not be
   used to influence the development of the flash map.


Due to the nature of the inputs and outputs generated by the fluctuating use case, the
results obtained were meaningless. The system was unable to learn any pattern of use.


The data was inputted into the system every hour. This caused the flash map to be
recalculated every hour. The following graphs show the simplified performance of the
system under the other tests. The data used to generate the graphs, along with the more
thorough graphs, are included as appendix E.


                                                                        Static Inputs

                      9



                      8


                      7


                      6
    Light Intensity




                      5
                                                                                                                                             Expected
                                                                                                                                             Output
                      4



                      3



                      2



                      1


                      0
                          1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24
                                                                    Time (hours)



                                                  Figure 17. Graph of Results under Static Use




                                                                                                                                                        42
                                                                                                                                                                    Chapter 5: Results




                                                                                Slowly Varying Inputs

                   9



                   8



                   7



                   6
Light Intensity




                   5
                                                                                                                                                                         Expected
                                                                                                                                                                         Output
                   4



                   3



                   2



                   1



                   0
                       1   2   3   4   5     6       7       8       9    10        11        12    13    14    15    16   17   18   19   20   21   22   23    24
                                                                                         Time (hours)


                                           Figure 18. Graph of Results under Slowly Changing Use




                                                                                    Rapidly varying inputs


                   9



                   8



                   7



                   6
 Light Intensity




                   5
                                                                                                                                                                         Expected
                                                                                                                                                                         Output
                   4



                   3



                   2



                   1



                   0
                       1   2   3   4   5     6   7       8       9       10    11        12    13    14    15    16   17   18   19   20   21   22   23   24   25
                                                                                     Time (hours)



                                           Figure 19. Graph of Results under Rapidly Changing Use




                                                                                                                                                                                    43
                                                                                                                                            Chapter 5: Results




                                                                          Noise type inputs


                        9



                        8



                        7



                        6
      Light Intensity




                        5
                                                                                                                                                 Expected
                                                                                                                                                 Output
                        4



                        3



                        2



                        1



                        0
                            1   2   3   4   5   6   7   8   9   10   11    12   13   14   15   16   17   18   19   20   21   22   23   24
                                                                      Time (hours)



                                                Figure 20. Graph of Results under Noise Type Inputs




5.3                         Analysis of Results


The preceding graphs demonstrate the performance of the system under a variety of
operating conditions. With the exception of fluctuating use, which would seem to be
extremely difficult to account for, the system performs extremely well.


The static case shows the system does not corrupt the previously learnt flash map when
the system does not need to update the map. This is important as the system will not
change the flash map until it believes, by monitoring the user’s input, that it is necessary
to do so.


Perhaps the most important test is under slowly changing conditions. This test attempts
to change the flash map only slightly, but significantly. This may parallel the real life



                                                                                                                                                            44
                                                                            Chapter 5: Results




situation of the sun rising earlier as occurs in summer. From the data in appendix F, it
can be seen that it takes approximately 48 hours of retraining of the system for it to
perform as required.


The system also performed well under rapidly changing conditions. Whilst these
conditions may not be very practical for a Smart Lamp, they demonstrate the ability of
the product to learn an almost completely new pattern of use. The graphs indicate that
72 hours of retraining was required for the system to be performing as required under
this type of condition.


The performance of the system under the noise type inputs was very important. This
test, in essence, demonstrates the need for the tent roof tensioning algorithm in the
system. Without this algorithm, the system would have learnt these noise type inputs,
which clearly would have been unacceptable. Instead, these inputs were basically
ignored by the system.


However, the performance of the system under this last test also shows the limitation of
the system. Due to the inclusion of the tent roof tensioning algorithm, the user would be
unable to train the system to have spikes of light (or no light) which would appear as
noise type inputs to the system. Whilst this may appear as a major limitation, it was
anticipated that the likelihood of requiring such performance from a Smart Lamp would
be unusual and was therefore deemed unimportant.


The double exponential smoothing ensures that no one input from the user can have a
marked effect on the flash map. Instead, it tends to smooth out the inputs to allow them
to be integrated into the flash map. Therefore, the double exponential smoothing is
important in all four test cases. Without the double exponential smoothing algorithm,
the system would tend to the follow the user’s inputs more than required – the small
fluctuations which may be presented to the system from the user from day to day can be
considered as noise. Therefore, this algorithm allowed the pattern to be extracted from
the user’s inputs. This can be seen clearly from the graphs in appendix F. For the flash




                                                                                           45
                                                                               Chapter 5: Results




map to be changed, the user must generally present the required changes to the system a
number of times. The graphs show that for small changes the system requires
approximately two consecutive updates from the user, whilst four consecutive updates
are required for more dramatic changes to the flash map.


The tent roof tensioning, whilst helping in the noise type conditions as already
mentioned, also ensures that the flash map is a continuous function. This parallels well
with the operation of a light, considering the continuous nature of light in a day.




5.4    Summary


This chapter has discussed the method for selecting the values of the parameters α and r,
the testing procedures and the results obtained from these tests. A full analysis of these
results was also provided.


The system was tested under five operating conditions – static conditions, slowly
varying operating conditions, rapidly varying operating conditions, under the influence
and noise type conditions and under fluctuating patterns of use.


It was found that the system worked well under the four main operating conditions, but
could learn fluctuating patterns of use. This was deemed unimportant as it would not
correspond to normal operation of a desktop lamp.




                                                                                              46
                                                                          Chapter 6: Project Review




6.0 Project Review

This chapter will provide a brief overview of the thesis, before analysing the methods
undertaken throughout its development. This incorporates both technical and managerial
aspects of the project.




6.1    Summary of Project


The aim of this project was to build a ‘Smart Object’ in the form of a desktop lamp.
That is, to build a product capable of learning a user’s pattern of use of a lamp. The
system was then to automate the intensity of the lamp with respect to the time of day. As
the lamp is a standard household product, it was required that the system was capable of
being trained and retrained online, without the lamp having to be taken offline to be
taught the user’s new pattern of use. In a similar way, the user interface of the lamp was
required to be simple, with little to no need for the user to be instructed on how to
operate the lamp.


The Smart Lamp satisfies these broad requirements. Through the use of the built-in
microcontroller, the lamp is capable of monitoring the user’s pattern of use to produce a
flash map. This flash map is a structure containing the learnt lighting intensities for each
of the 24 one hour intervals which exist in every day.


To allow the user to provide the Smart Lamp with its initial flash map, two pushbuttons,
up and down, are used to alter the lighting intensity. Once the user has taught the
system, the system should be capable of automatically controlling the lighting intensity
of the Smart Lamp. These buttons also allow the user to constantly update the system
with a more acceptable flash map as may be required over an extended period of
operation.




                                                                                                47
                                                                        Chapter 6: Project Review




The learning component of the lamp was based on two separate algorithms - double
exponential smoothing and tent roof tensioning.


Double exponential smoothing is used in a variety of forecasting applications. Through
the use of smoothing parameters, which reflect the impact of recent data, this method is
capable of producing a forecast given a chronological set of data.


The results from the double exponential smoothing were inputted to the tent roof
tensioning algorithm. This algorithm ensured that the flash map created by the system
was largely a continuous map to ensure that the map did not contain ‘spikes’ of data that
may have resulted in an unacceptable response.


Having designed and constructed the Smart Lamp, it was necessary to test the system
under a number of operating conditions. These conditions were:
•   static operating conditions;
•   slowly changing operating conditions;
•   rapidly changing operating conditions; and
•   static conditions with ‘noise’ type influences.
The Smart Lamp’s performance under these conditions was extremely good and showed
that the system was capable of operating acceptably under a large variety of conditions.


However, the system was not capable of learning fluctuating patterns of use. Such use
may correspond to the light being turned on every second hour of the day, and off for
every other hour. As this type of use would seem to be unusual for a desktop lamp, this
limitation of the system was not considered to be overly serious.


Therefore, the Smart Lamp is capable of learning a user’s pattern of use and automating
this learnt pattern whenever the user activates the system’s IR detector. The lamp is also
capable of learning a new pattern whilst being maintained in it’s standard operational
mode.




                                                                                              48
                                                                         Chapter 6: Project Review




6.2    Review of Technical Aspects of Project


Whilst the Smart Lamp is capable of monitoring the user’s pattern of use as required,
there are a few aspects of the product which may have been improved had different
technical decisions been made in the designing of the lamp.


Firstly, the hardware developed to produce the Smart Lamp, whilst suitable for a
desktop lamp, comprised a number of chips. These chips, including the processor,
external RAM and EPROM, various logic gates and the LCD driver and display,
required the lamp to be relatively large. It may have been more appropriate to choose a
more sophisticated processor on which to base the design to allow the elimination of the
external memory. This would have significantly reduced the size of the Smart Lamp and
may also have proven easier to debug.


Whilst a fairly simple learning algorithm was used in the design of the lamp, the results
obtained were acceptable and the benefits associated with obtaining better results with a
different, more advanced algorithm is probably minimal and not worth considering.


The main limitation regarding the learning component of the Smart Lamp is in relation
to its inability to learn a cyclic pattern of use. This was demonstrated in the product’s
inability to cope with the fluctuating patterns of use presented in chapter 5. Had this
functionality been included in the design, the user would be able to train the light to
flash on and off continuously, as may be required in a disco type setting.


Such a change to the learning algorithm may have been implemented using linear
prediction as is used in the DOPPELGANGER electronic newspaper system [12]. The
statistical method attempts to determine the occurrence and duration of an event.




                                                                                               49
                                                                        Chapter 6: Project Review




6.2     Review of Managerial Aspects of Project


The managerial side of the project was estimated through the use of Gant charts.


The first aspect of the Gant chart that requires consideration is the almost two months
allocated to research into ‘Smart Objects’ and associated learning algorithms. The
research material available in the area of ‘Smart Objects’ was limited, as little work had
been done previously. Consequently, it is probable that the area could have been
covered sufficiently well in about one month.


The small time allocated for the construction and testing of the PCB was too ambitious.
Due to soldering problems, as well as a problem with the reset circuitry, the testing of
the PCB took approximately a month to be working as required. Fortunately, the PCB
was made in August and therefore this delay did not severely affect the completion date
of the product.


Almost two weeks was devoted to afixing the PCB, buttons and panel fixtures to the
plastic box. This aspect of the project was not considered in the Gant charts as it was
initially thought to be a trivial task.


Though the project did not follow the Gant charts, the progress made throughout the
year was sufficient to ensure a working product was developed within the allotted time.




                                                                                              50
                                                                     Chapter 7: Future Modifications




7.0    Future Modifications


The Smart Lamp is the first product in the area of smart desktop lamps. Though it
performs the task as required, there are modifications that could be made to make an
even better product.


Firstly, using alternative hardware could reduce the size of the product. In particular, a
more powerful microprocessor could be used to reduce the number of chips required in
the design. This would allow a standard wall-fixed lighting panel to be replaced by a
smart lighting panel capable of performing similarly to the Smart Lamp.


Secondly, the user interface of the Smart Lamp, whilst acceptable, was simple and
provided only basic information to the user. A more advanced display, perhaps in the
form of an alphanumeric LCD, would have allowed more information to be provided to
the user to allow the system to have been completely user friendly. As the main purpose
of the Smart Lamp is to make life easier for the user, this would seem to be the most
important, though cosmetic, modification necessary.


Improvements in the main part of the product, the learning algorithm, would appear
limited. As this was the area that was concentrated upon in this thesis, it was necessary
for the best possible performance in this area to be achieved. However, with the advent
of more sophisticated algorithms in the future as the field of ‘Smart Objects’ becomes
more prevalent, an even better algorithm may be able to be used in the product.




                                                                                                 51
                                                          Chapter 8: Broader Implications of ‘Smart Objects’




8.0    Broader Implications of ‘Smart Objects’


The principles developed in the design of the Smart Lamp have shown that a ‘Smart
Object’ can be built capable of learning a user’s pattern of use and automating a simple
task such as altering the intensity of the light. However, these principles could very well
be extended to a number of other products.


In terms of automatic lighting, the design and construction of the Smart Lamp is the
same as a comparable wall fixed lighting fitting. Therefore, the standard light panel
could easily be smart enough to allow a house’s lighting system to be completely
automated.


A number of other products also lend themselves to become ‘Smart Objects’.


The standard toaster could easily be extended to learn the extent to which the toast
should be cooked. Air conditioners and heaters could become ‘Smart Objects’ by
learning the pattern of use over the year and responding accordingly. The garden’s
sprinkler system could be made to water the plants when necessary by considering the
time of year and the recent temperature and rainfall patterns.


However, looking further into the future, imagine the development of a more
sophisticated product such as the Smart Car. The car would be capable of monitoring
the driver’s pattern of travel and eventually allow the driver to be automatically driven
to and from work with a simple voice command. Whilst this may seem somewhat
fanciful, it is clear that the principles of ‘Smart Objects’ have a variety of advantages,
and the development of the Smart Lamp shows that these principles are able to be
implemented in a standard appliance such as a desktop lamp.




                                                                                                         52
Appendix A
References
[1] Bovas, A., Johannes, L., Statistical Methods for Forecasting, 1983.

[2] Lee, C., Yangsheng, ., “Online, interactive learning of gestures for human/robot
interfaces”, Proceedings of IEEE International Conference on Robotics and
Automation, vol. 4, pp. 2982-2987, 1996.

[3] Long, P., “Improved Bounds about On-line Learning of Smooth Functions of a
Single Variable”, Proceedings of the Seventh Workshop on Algebraic Learning Theory,
vol. 1160, 1996.

[4] Atkeson, C., " Memory-Based Learning Control," American Control Conference,
vol. 3, pp. 2131-2136, 1991.

[5] Ubiquitous Video, [ONLINE]. Translation of: Buxton, B., " Ubiquitous Video,"
Nikkei Electronics, num. 632, pp. 187-195, 1995.

[6] Cohn, D., Ghahramani, Z., Jordan, M., " Active Learning with Statistical Models,"
1995.

[7] Hamey, L., RayChaudhuri, R., " Minimisation of Data Collection by Active
Learning," IEEE International Conference on Neural Networks, vol. 3, pp. 1338-1341,
1995.

[8] Hamey, L., RayChaudhuri, T., " Active Learning - Approaches and Issues," Journal
of Intelligent Systems, vol. 7, pp. 205-243, 1997.

[9] Heiss, M., " Online Learning or Tracking of Discrete Input-Output Maps," IEEE
Transactions on Systems, Man. and Cybernetics - Part A: Systems and Humans, vol. 27,
num. 5, pp. 657-667, September, 1997.

[10] Kulkarni, S., Mitter, S., Tsitsiklis, J., " Active Learning Using Arbitrary Binary
Valued Queries," Machine Learning, vol. 11, pp. 23-35, 1993.

[11] Munch, S., Sassin, M., Bocionek, S., " The application of PBD methods to real-
world domains: two case studies," Proceedings of the 7th Australian Joint Conference
on Artificial Intelligence, pp. 92-99, 1994.

[12] Orwant, J., " For want of a bit the user was lost: Cheap user modeling," IBM
Systems Journal, vol. 35, num. 3,4, pp. 398-416, 1996.


[13] Frank, M., Foley, J., “A Pure Reasoning Engine for Programming By
Demonstration,” UIST ‘94: 7th Annual Symposium on User Interface Software and
Technology, pp. 95-101, 1994.

[14] Paynter, G., “Generalising Programming By Demonstration,” Australian Conf. on
Computer Human Interaction, Nov. 24-27, pp. 344-5, 1996.
[15] The Computer for the Twenty-First Century, [ONLINE]. Translation of:
Weiser, M., " The Computer for the Twenty-First Century," Scientific American, pp. 94-
104, September, 1991.

[16] Programming by Demonstration, [ONLINE]. Available from
http://liber.www.media.mit.edu/. Accessed 24/4/98.

[17] The Evolution of Learning Devices: Smart Objects, Information Infrastructures,
and Shared Synthetic Environments, [ONLINE].

[18] Atkeson, C., Moore, A., Schaal, G., “Locally Weighted Regression,” Artificial
Intelligence Review, pp. 11-73, 1995.
Appendix B
Hardware Schematics and PCB Artwork



This section comprises the schematic diagrams and PCB artwork associated with the
development of the Smart Object.


The schematics included are:
1. Controller
2. Light interface
3. LCD driver/display
4. Power supply
5. External memories


The PCB artwork included, in order, is:
1. Top layer
2. Bottom layer
3. Top Overlay
Appendix C
Software Flowcharts



The following flowcharts show the flow of the specific software functions.


1. Tent roof tensioning / Double exponential smoothing.
2. Main section
3. Initialisation
4. IR sensor interrupt – timer capture 2
5. Light interrupts – timer input capture 1, timer output compare 3
6. Pulse accumulator overflow interrupt
7. Clock interrupt
8. Automatic operating mode
Flowchart 1
Tent roof tensioning / Double exponential smoothing




                              Start




                           Initialisation




                       Calculate Smoothing
                           Coefficients




                     Use Tent Roof Tensioning
                       to Update Intensities




                    Check to Ensure all Values
                          are in Range




                              Return
Flowchart 2
Main Section




            Start




                        yes          Set Time
          Set Button
              Hit


           no




                        yes          Set Mode
          Mode Button
              Hit


          no




                         yes
           Up Button             Light Intensity      no
              Hit                       =
                                      max
                               yes

                                            Increase Light Intensity
              yes
Down Button           Light Intensity      no
   Hit                       =
                           min

       no           yes

                                    Decrease Light Intensity
Flowchart 3
Initialisation




                         Start




                     Read Data,
                 Smoothing Coefficients




                   Initialise Interrupts




                    Enable Interrupts




                  Main Program Loop
Flowchart 4
IR Sensor Interrupt - Timer Input Capture 2




                   Start




          Clear Flag (TMSK1 bit 5)




                                     yes
                 Mode = Auto               Load Learnt Light Intensity


                           no




               Disable Further
              Sensor Interrupts




                   Return
Flowchart 5
Light Interrupts - Timer Input Capture 1
                  Timer Output Compare 3




           Start - TIC1                    Start - TOC3




                                      Disable Further TOC3
      Load Relevant Value into
                                            Interrupts
           TOC3 counter




        Set TOC3 Output Pin           Set TOC3 Output Pin to
             to go Low                       go High




          Clear TIC1 Flag              Load TOC3 Counter




          Clear TIC1 Flag
                                              Return




              Return
Flowchart 6
Pulse Accumulator Overflow Interrupt




                    Start




                Read PORTE




               Clear Input Flags




          Set Interrupt to Fire on Next
            Pulse (PACNT = 0xFF)




                                    yes
                   Bit1 High              Up Button Pressed


                            no
                       yes       Down Button Pressed
       Bit1 High


             no




                           yes
       Bit2 High                 Mode Button Pressed



              no




                       yes
       Bit3 High                  Set Button Pressed


              no




Indicate Someone In Room




        Return
Flowchart 7
Clock Interrupt


                   Start




                                yes
                  Seconds =                  Increments Minutes
                     60


                           no




                                yes
              Minutes = 60                    Increments Hours



                        no




                                                    Person in
                                                     Room
                                      no
                                                            yes




                                           Add Light Intensity to Tent
                                           Roof Tensioning Algorithm




                                            Load New Light Intensity
Enable Further IR
   Interrupts




Load Counter for
 Next Interrupt




    Clear Flag




     Restart
Flowchart 8
Automatic Operating Mode



                                                    Start




                                                Wait for User




                                no
                                                   Person in
                                                    Room


                                                         yes




                                          Load Learnt Light Intensity




   Add Intensity to Algorithm
               &                                  Person left
         Turn off Light                            Room
                                 yes

                                                            no




                                                   Light Int.            Update Light
                                                   Changed                Intensity
                                     no                            yes
Appendix D
Software Listing



The following file, learn.c, is the software which was used in the Smart Lamp.


It was compiled using Borland C and linked with the following parameters:
       Text = 4000/0000, Rbss = A000, Bss, Temp = 0


These reflect that the EPROM resided at 4000h in the memory map, whilst the external
RAM was at A000h.
/*
 * FILE:           learn.c
 *
 * VERSION:        1.102
 *
 * BY:             Mark Gauci
 *
 * DESCRIPTION:    This file contains the code for the EPROM which forms part
 *                 of the thesis project Smart Lamp.It performs all of the
 *                 functions required.
 */

#include <intrpt.h>
#include <math.h>

#define           BIT0    0x01
#define           BIT1    0x02
#define           BIT2    0x04
#define           BIT3    0x08
#define           BIT4    0x10
#define           BIT5    0x20
#define           BIT6    0x40
#define           BIT7    0x80
#define           PORTE   (*(unsigned char *) 0x100A )
#define           PORTC   (*(unsigned char *) 0x1003 )
#define           PORTD   (*(unsigned char *) 0x1008 )
#define           PORTB   (*(unsigned char *) 0x1004 )
#define           PORTA   (*(unsigned char *) 0x1000 )
#define           TFLG1   (*(unsigned char *) 0x1023 )
#define           TMSK1   (*(unsigned char *) 0x1022 )
#define           TFLG2   (*(unsigned char *) 0x1025 )
#define           TMSK2   (*(unsigned char *) 0x1024 )
#define           TCTL2   (*(unsigned char *) 0x1021 )
#define           DDRC    (*(unsigned char *) 0x1007 )
#define           DDRD    (*(unsigned char *) 0x1009 )
#define           PACNT   (*(unsigned char *) 0x1027 )
#define           PACTL   (*(unsigned char *) 0x1026 )
#define           TCNT    (*(unsigned short *) 0x100E )
#define           PIOC    (*(unsigned char *) 0x1002 )
#define           PORTCL (*(unsigned char *) 0x1005 )
#define           TOC2    (*(unsigned short *) 0x1018 )
#define           TOC3    (*(unsigned short *) 0x101A )
#define           TIC1    (*(unsigned short *) 0x1010 )
#define           TCTL1   (*(unsigned char *) 0x1020 )
#define           CFORC   (*(unsigned char *) 0x100B )
#define           PAO_VECTh      (*(unsigned char *) 0x0009 )
#define           PAO_VECTl      (*(unsigned short *) 0x000A )
#define           TOC2_VECTh      (*(unsigned char *) 0x0000 )
#define           TOC2_VECTl      (*(unsigned short *) 0x0001 )
#define           TOC3_VECTh     (*(unsigned char *) 0x0006 )
#define           TOC3_VECTl     (*(unsigned short *) 0x0007 )
#define           TIC1_VECTh     (*(unsigned char *) 0x0003 )
#define           TIC1_VECTl     (*(unsigned short *) 0x0004 )
#define           TIC2_VECTh      (*(unsigned char *) 0x0010 )
#define           TIC2_VECTl      (*(unsigned short *) 0x0011 )
#define           IRQ_VECTh       (*(unsigned char *) 0x000C )
#define           IRQ_VECTl       (*(unsigned short *) 0x000D )
#define           RTI_VECTh       (*(unsigned char *) 0x00EB )
#define           RTI_VECTl       (*(unsigned short *) 0x00EC )
#define           DIGIT1          (*(unsigned char *) 0xD003 )
#define           DIGIT2          (*(unsigned char *) 0xD002 )
#define           DIGIT3          (*(unsigned char *) 0xD001 )
#define           DIGIT4          (*(unsigned char *) 0xD000 )
#define           PPROG           (*(unsigned char *) 0x103B )
#define           EPROT           (*(unsigned char *) 0x1035 )
#define           EEPROM1         (*(unsigned char *) 0xF900 )

clear_lcd();
start_lcd();
init_clock();
interrupt clock_isr();
set_mode();
display_time();
interrupt tic2_isr();
init_pacnt();
init_toc3();
init_tic1();
init_tic2();
interrupt pacnt_isr();
interrupt toc3_isr();
interrupt tic1_isr();
set_time();
test_dimmer();
tent_roof(int intensity, int time_period);
read_data();

unsigned   short temp;
unsigned   char count, seconds;
unsigned   char temp3, test3;
unsigned   short two_ms;
unsigned char temp_input;
int changed, debounce_counter, sensor_set;
int light_counter, mode, temp2, start, ircount;
int high_hours, low_hours, high_minutes, low_minutes, current_period;
float tester;
int s1[24], s2[24], z;
int r, a, w, new_factor;
int i, j, k, end_period, start_period, newdata, t, intensity_add, time[24];
int show_time, up_button, down_button, set_button, mode_button;
long int lj;


/*
  * Main
  */
void main(void)
{
         /*
          * initialisations
          */
         DDRD = 0x0C;       /* should change as PDs -> VCC   (0x0C) was 0x0F   */
         light_counter = 9;
         start = 1;
         mode = 2;        /* learning mode */
         ircount = 0;
         low_hours = 2;
         high_hours = 7;
         low_minutes = 0;
         high_minutes = 0;
         show_time = 1;


        /*
         * setup flashing LED
         */
        PORTD = 0x00;
        PORTD = BIT2;

        /*
         * read in data
         */
        read_data();

        /*
          * set smoothing coefficients
          */
        for (i = 0; i < 24; i++) {
                  s1[i] = time[i];
                  s2[i] = time[i];
        }

        /*
         * initialise interrupts
         */
        init_clock();
        init_pacnt();
        init_tic1();
        init_toc3();
        init_tic2();

        clear_lcd();
        start_lcd();

        ei();

        while(1) {

                 /*
                   * setting time
                   */
                 if (set_button == 1) {
                           set_button = 0;
                           set_time();
                 }

                 /*
                   * change operating mode
                   */
                 if (mode_button == 1) {
                           mode_button = 0;
                           show_time = 10;
                           clear_lcd();
                           DIGIT1 = 9 - light_counter;
                           set_mode();
                 }

                 /*
                  * increase light intensity
                  */
                 if (up_button == 1) {
                               up_button = 0;
                               show_time = 10;
                               if (light_counter > 1) {
                                        light_counter--;
                               }
                               clear_lcd();
                               DIGIT2 = 9 - light_counter;
                       }

                       /*
                         * decrease light intensity
                         */
                       if (down_button == 1) {
                                 down_button = 0;
                                 show_time = 10;
                                 if (light_counter < 9) {
                                          light_counter ++;
                                 }
                                 clear_lcd();
                                 DIGIT2 = 9 - light_counter;
                       }
         }
}


/*
  * Clear_lcd
  */
clear_lcd()
{
          DIGIT1   =   0x0F;
          DIGIT2   =   0x0F;
          DIGIT3   =   0x0F;
          DIGIT4   =   0x0F;
}


/*
  * Start_lcd
  */
start_lcd()
{
          DIGIT1   =   0x0F;
          DIGIT2   =   0x01;
          DIGIT3   =   0x0C;
          DIGIT4   =   0x0F;
}


/*
  * Init_clock
  */
init_clock()
{
          TMSK2 = TMSK2 & 0xFC;
          TOC2_VECTh = 0x7E;
          TOC2_VECTl = (int) clock_isr;
          TCTL1 = TCTL1 & 0x3F;   /* disconnect output pin */
          TMSK1 = BIT6;
          TOC2 = TOC2 + 40000;
          two_ms = 0;
}


/*
  * Clock_isr
  */
interrupt clock_isr()
{
          /*
           * Update clock
           */
          if (two_ms == 2) {             /* 50 */

                       two_ms = 0;
                       seconds++;

                       /*
                        * one second passed
                        */
                       if (seconds == 2) {       /* should be 59 */
                                seconds = 0;
                                low_minutes++;

                               if (low_minutes == 10) {
                                        low_minutes = 0;
                                        high_minutes++;

                                        /*
                                         * one hour passed
                   */
                  if (high_minutes == 6) {
                           high_minutes = 0;
                           low_hours++;

                            if (high_hours == 5) {
                                     if (low_hours == 10) {
                                              low_hours = 0;
                                              high_hours = 7;
                                     }
                            }
                            else if (high_hours == 11) {
                                     if (low_hours == 10) {
                                              low_hours = 0;
                                              high_hours = 8;
                                     }
                            }
                            else if (high_hours == 8) {
                                     if (low_hours == 3) {
                                              low_hours = 1;
                                              high_hours = 11;
                                     }
                                     else if (low_hours == 2) {
                                              high_hours = 7;
                                     }
                            }
                            else if (high_hours == 7) {
                                     if (low_hours == 3) {
                                              low_hours = 1;
                                              high_hours = 5;
                                     }
                                     else if (low_hours == 2) {
                                              high_hours = 8;
                                     }
                            }

                            /*
                              * add intensity to algorithm
                              */
                            if (sensor_set > 0) {
                                      if (mode < 3) {
                                               if (time[current_period] != (9 -
                                               light_counter)) {
                                                        tent_roof(9 - light_counter,
                                                        current_period);
                                               }
                                      }
                            }

                            /*
                              * adjust current_period
                              */
                            current_period++;
                            if (current_period == 24) {
                                      current_period = 0;
                            }

                            /*
                              * adjust light automatically
                              */
                            if (sensor_set > 0) {
                                      if (mode == 2) {
                                               light_counter = 9 - time[current_period];
                                      }
                            }
                  }
         }
}

/*
  * should time be shown
  */
if (show_time == 1) {
          display_time();
}

/*
  * adjust waiting time
  */
if (show_time > 1) {
          show_time--;
}

/*
 * adjust PIR response
 */
if (sensor_set > 0) {
         sensor_set--;

         /*
                           * determine if person just left
                           */
                          if (sensor_set == 0) {
                                   if (mode < 3) {
                                            if (time[current_period] != (9 - light_counter)) {
                                                     tent_roof(9 - light_counter, current_period);
                                            }
                                            light_counter = 9;

                                              DIGIT1   =   15;
                                              DIGIT2   =   15;
                                              DIGIT3   =   15;
                                              DIGIT4   =   15;

                                              TMSK1 |= BIT1;

                                              show_time = 40;
                                   }
                          }
                 }

                 if (sensor_set < 300) {
                          TMSK1 |= BIT1;
                 }
        }
        else {
                 two_ms++;
        }

        TOC2 = TOC2 + 40000;

        /*
         * Clear interrupt
         */
        TFLG1 = BIT6;
}

/*
  * Display_time
  */
display_time()
{
          if ((mode < 3) && (start == 0)) {
                   DIGIT1 = low_minutes;
                   DIGIT2 = high_minutes;
                   DIGIT3 = low_hours;
                   DIGIT4 = high_hours;
          }
          else {
                   start_lcd();
          }
}


/*
  * init_pacnt
  */
init_pacnt()
{
          PAO_VECTh = 0x7E;
          PAO_VECTl = (int) pacnt_isr;
          PACTL = 0x50; /* rising edge increments counter */
          TMSK2 |= BIT5;
          PACNT = 0xFF;
}


/*
  * init_toc3
  */
init_toc3()
{
          TOC3_VECTh = 0x7E;
          TOC3_VECTl = (int) toc3_isr;
          TOC3 = TOC3 + 0x0100;
          TCTL1 |= BIT5;
          CFORC = 0x20;
}


/*
  * init_ic1
  */
init_tic1()
{
          TIC1_VECTh = 0x7E;
          TIC1_VECTl = (int) tic1_isr;
          TMSK1 = TMSK1 | BIT2;
          TCTL2 = TCTL2 | BIT5;
}
/*
  * init_tic2
  */
init_tic2()
{
          TIC2_VECTh = 0x7E;
          TIC2_VECTl = (int) tic2_isr;
          TMSK1 = TMSK1 | BIT1;
          TCTL2 = TCTL2 | BIT2;
}


/*
  * pacnt_isr
  */
interrupt pacnt_isr()
{
          if ((TFLG2 & BIT5) == BIT5) {

                 temp_input = PORTE;

                 while ((PORTD & BIT7) == BIT7);

                 PORTD &= (0xFF ^ BIT2);       /* clear input */
                 PORTD |= BIT2;

                 TFLG2 = BIT5;
                 PACNT = 0xFF;
                 start = 0;

                 /*
                  * determine action to take
                  */
                  if ((temp_input & BIT1) == BIT1) {
                          up_button = 1;
                  }
                  if ((temp_input & BIT2) == BIT2) {
                          down_button = 1;
                  }

                     if ((temp_input & BIT3) == BIT3) {
                             mode_button = 1;
                     }

                     if ((temp_input & BIT4) == BIT4) {
                             set_button = 1;
                     }

        /*
         * turn lights back on if automatic mode
         */
                 if (sensor_set == 0) {
                          if (mode == 2) {
                                   light_counter = 9 - time[current_period];
                          }

                            DIGIT1   =   10;
                            DIGIT2   =   10;
                            DIGIT3   =   10;
                            DIGIT4   =   15;

                            show_time = 40;
                 }

                 /*
                  * show that someone in room
                  */
                 sensor_set = 600;
        }
}


/*
  * tic1_isr - light input
  */
interrupt tic1_isr()
{
          TOC3 = TIC1 + 100 + 2000 * light_counter;
          TFLG1 = BIT2;
          TCTL1 = 0x20; /* set to go low */
          TFLG1 = BIT5;
          TMSK1 = TMSK1 | BIT5;
}


/*
 * tic2_isr - sensor
 */
interrupt tic2_isr()
{
         TFLG1 = BIT1;
         ircount++;

         /*
          * disable further interrupts
          */
         TMSK1 ^= BIT1;

         /*
          * turn lights back on if automatic mode
          */
         if (sensor_set == 0) {
                  if (mode == 2) {
                           light_counter = 9 - time[current_period];
                  }

                    DIGIT1   =   10;
                    DIGIT2   =   10;
                    DIGIT3   =   10;
                    DIGIT4   =   15;

                    show_time = 40;
         }

         sensor_set = 600;
}


/*
  * toc3_isr - light output
  */
interrupt toc3_isr()
{
          TMSK1 = TMSK1 & 0xDF;
          TOC3 = TOC3 + 200;
          TCTL1 = 0x30;
}


/*
  * test_dimmer
  */
test_dimmer()
{
          if (light_counter == 9) {
                   light_counter = 1;
          }
          else {
                   light_counter++;
          }
}


/*
  * set_time
  */
set_time()
{
          /*
           * disable time from being updated by system
           */
          show_time = 0;
          TMSK1 = TMSK1 ^ BIT6;

         /*
          * clear   LCD
          */
         DIGIT1 =   0x0F;
         DIGIT2 =   0x0F;
         DIGIT3 =   0x0F;
         DIGIT4 =   0x05;

         /*
          * update low_minute
          */
         while (set_button == 0) {
                  DIGIT1 = low_minutes;
                  if (up_button == 1) {
                           if (low_minutes < 9) {
                                    low_minutes++;
                           }
                           else {
                                    low_minutes = 0;
                           }
                           up_button = 0;
                  }

                    if (down_button == 1) {
                  if (low_minutes > 0) {
                           low_minutes--;
                  }
                  else {
                           low_minutes = 9;
                  }
                  down_button = 0;
         }
}
set_button = 0;

/*
  * update high_minute
  */
while (set_button == 0) {
          DIGIT2 = high_minutes;
          if (up_button == 1) {
                   if (high_minutes < 5) {
                            high_minutes++;
                   }
                   else {
                            high_minutes = 0;
                   }
                   up_button = 0;
          }
          if (down_button == 1) {
                   if (high_minutes > 0) {
                            high_minutes--;
                   }
                   else {
                            high_minutes = 5;
                   }
                   down_button = 0;
          }
}
set_button = 0;

/*
 * update low_hours
 */
while (set_button == 0) {
         DIGIT3 = low_hours;
         DIGIT4 = high_hours;

         if (up_button == 1) {

                  low_hours++;

                  if (high_hours == 5) {
                           if (low_hours == 10) {
                                    low_hours = 0;
                                    high_hours = 7;
                           }
                  }
                  else if (high_hours == 11) {
                           if (low_hours == 10) {
                                    low_hours = 0;
                                    high_hours = 8;
                           }
                  }
                  else if (high_hours == 8) {
                           if (low_hours == 3) {
                                    low_hours = 1;
                                    high_hours = 11;
                           }
                           else if (low_hours == 2) {
                                    high_hours = 7;
                           }
                  }
                  else if (high_hours == 7) {
                           if (low_hours == 3) {
                                    low_hours = 1;
                                    high_hours = 5;
                           }
                           else if (low_hours == 2) {
                                    high_hours = 8;
                           }
                  }

                  up_button = 0;
         }

         if (down_button == 1) {
                  low_hours--;

                  if((low_hours > 9) || (low_hours < 2)) {

                           if (high_hours == 11) {
                                    if (low_hours == 0) {
                                             low_hours = 2;
                                                    high_hours = 8;
                                              }
                                   }
                                   if (high_hours == 5) {
                                            if (low_hours == 0) {
                                                     low_hours = 2;
                                                     high_hours = 7;
                                            }
                                   }
                                   else if (high_hours == 8) {
                                            if (low_hours == -1) {
                                                     low_hours = 9;
                                                     high_hours = 11;
                                            }
                                            if (low_hours == 1) {
                                                     high_hours = 7;
                                            }
                                   }
                                   else if (high_hours == 7) {
                                            if (low_hours == -1) {
                                                     low_hours = 9;
                                                     high_hours = 5;
                                            }
                                            if (low_hours == 1) {
                                                     high_hours = 8;
                                            }
                                   }
                           }

                           down_button = 0;
                 }
        }
        set_button = 0;
        mode_button = 0;
        seconds = 0;
        two_ms = 0;

        /*
          * determine current period
          */
        current_period = low_hours;
        if (high_hours == 8) {
                  current_period = current_period + 22;
                  if (low_hours == 2) {
                           current_period = 12;
                  }
        }
        if (high_hours == 11) {
                  current_period = current_period + 12;
        }
        if (high_hours == 7) {
                  current_period = current_period + 10;
                  if (low_hours == 2) {
                           current_period = 0;
                  }
        }

        /*
         * show time
         */
        show_time = 1;
        TMSK1 = TMSK1 ^ BIT6;

        /*
         * as time been set, enter learning mode
         */
        mode = 2; /* should be 1 ?????????? */

        /*
         * adjust lights correctly - no !!!!!!!!!!!   as learning mode
         */
        light_counter = 9 - time[current_period];
}


/*
  * set_mode -
  *
  * This procedure changes the operating mode of the system.
  * The modes are:        1 - learning
  *                       2 - auto
  *                       3 - test
  */
set_mode()
{
          while (set_button == 0) {
                   show_time = 0;
                   clear_lcd();
                   DIGIT2 = mode;
                   if (up_button == 1) {
                          if (mode == 3) {
                                   mode = 1;
                          }
                          else {
                                   mode++;
                          }
                          up_button = 0;
                 }
                 if (down_button == 1) {
                          if (mode > 1) {
                                   mode--;
                          }
                          else {
                                   mode = 3;
                          }
                          down_button = 0;
                 }
        }
        set_button = 0;
        show_time = 1;
}


/*
  * tent_roof -
  *
  * This updates the learning algorithm with the light intensity
  * for the relevant time period.
  */
tent_roof(int intensity, int time_period)
{
          /*
           * set parameters
           */
          w = 75;
          a = 25;
          r = 6;

        if (s1[time_period] == -111) {
                 s1[time_period] = intensity;
                 s2[time_period] = intensity;
        }
        else {
                 /*
                  * calculate smoothing coefficients
                  */
                 s1[time_period] = (a * intensity + w * s1[time_period]) / 100;
                 s2[time_period] = (a * s1[time_period] + w * s2[time_period])/ 100;
                 new_factor = a * 100;
                 new_factor = new_factor / w;
                 z = ((200 + new_factor) * s1[time_period] - (100 + new_factor) * s2[time_period]) /
                          100;
                 intensity_add = z;

                 /*
                   * apply smoothed value to tent roof algorithm
                   */
                 if (intensity_add < 0) {
                           intensity_add = 0;
                 }
                 if (intensity_add > 8) {
                           intensity_add = 8;
                 }

                 time[time_period] = intensity_add;

                 for (i = (time_period + 1); i < (time_period + r); i++) {
                          end_period = time_period + r;
                          if (end_period > 23) {
                                   end_period = end_period - 24;
                          }
                          if (i > 23) {
                                   time[i - 24] = intensity_add + ((time[end_period] - intensity_add)
                                            * (i - time_period) / r);
                          }
                          else {
                                   time[i] = intensity_add + ((time[end_period] - intensity_add) *
                                            (i - time_period) / r);
                          }
                 }

                 for (i = time_period - r; i < time_period; i++) {
                          start_period = time_period - r;
                          if (start_period < 0) {
                                   start_period = start_period + 24;
                          }
                          if (i < 0) {
                                   time[24 + i] = intensity_add + ((time[start_period] –
                                            intensity_add) * (time_period - i) / r);
                          }
                           else {
                                    time[i] = intensity_add + ((time[start_period] - intensity_add) *
                                             (time_period - i) / r);
                           }
                  }

                  /*
                    * check that all in range
                    */
                  for (i = 0; i < 24; i++) {
                            if (s1[i] > 8) {
                                     s1[i] = 8;
                            }
                            if (s1[i] < 0) {
                                     s1[i] = 0;
                            }
                            if (s2[i] > 8) {
                                     s2[i] = 8;
                            }
                            if (s2[i] < 0) {
                                     s2[i] = 0;
                            }
                            if (time[i] > 8) {
                                     time[i] = 8;
                            }
                            if (time[i] < 0) {
                                     time[i] = 0;
                            }
                  }
         }
}


/*
  * read_data()
  */
read_data()
{
          time[0] = 8;
          time[1] = 8;
          time[2] = 8;
          time[3] = 8;
          time[4] = 7;
          time[5] = 5;
          time[6] = 3;
          time[7] = 1;
          time[8] = 1;
          time[9] = 0;
          time[10] = 0;
          time[11] = 0;
          time[12] = 0;
          time[13] = 0;
          time[14] = 0;
          time[15] = 1;
          time[16] = 2;
          time[17] = 3;
          time[18] = 5;
          time[19] = 7;
          time[20] = 8;
          time[21] = 8;
          time[22] = 8;
          time[23] = 8;
}
Appendix E
Parameter Testing Results



The two parameters tested were the smoothing coefficient α and the tent roof radius r.


The following files show the input to the tests, the results for a variety of values for the
parameters and the expected results. The tests performed were under slowly changing
and rapidly changing operating conditions.


From these graphs, it was determined that the values should be α = 0.75 and r = 6;
Determination of the smoothing constant a


Slowly changing inputs

The input data was as follows:
888875311000000123578888
888875311000000123578888
888875311000000123578888
865521000000000001135666
865521000000000001135666
865521000000000001135666


The results obtained were as follows:


HOUR             SMOOTHING CONSTANT a                Expected
           0.7     0.75      0.8        0.85   0.9
   0        5        5           5       5     5        8
   1        4        4           4       4     4        6
   2        3        3           3       3     3        5
   3        2        2           2       2     2        5
   4        1        1           1       1     1        2
   5        1        0           0       0     0        1
   6        0        0           0       0     0        0
   7        0        0           0       0     0        0
   8        0        0           0       0     0        0
   9        0        0           0       0     0        0
  10        0        0           0       0     0        0
  11        0        0           0       0     0        0
  12        0        0           0       0     0        0
  13        0        0           0       0     0        0
  14        0        0           0       0     0        0
  15        1        1           1       1     1        0
  16        2        1           1       1     1        0
  17        4        4           4       3     3        1
  18        5        5           5       4     4        1
  19        5        5           5       5     5        3
  20        6        6           6       6     6        5
  21        6        6           6       6     6        6
  22        6        6           6       6     6        6
  23        6        6           6       6     6        6
Rapidly changing inputs

The input data was as follows:
888875311000000123578888
000123468888888865321000
000123468888888865321000
000123468888888865321000
000123468888888865321000
000123468888888865321000
000123468888888865321000


The results obtained were as follows:


HOUR             SMOOTHING CONSTANT a                Expected
           0.7     0.75      0.8        0.85   0.9
   0        2        1           1       0     2        0
   1        2        1           1       1     2        0
   2        2        1           1       1     2        0
   3        2        1           2       2     2        1
   4        3        2           3       1     1        2
   5        4        3           4       2     1        3
   6        4        4           4       3     0        4
   7        4        5           4       4     0        6
   8        4        6           4       4     0        8
   9        4        6           4       4     0        8
  10        4        6           4       4     0        8
  11        4        6           4       4     0        8
  12        4        6           4       4     0        8
  13        3        6           3       3     1        8
  14        2        6           2       2     2        8
  15        2        5           2       2     2        8
  16        2        4           2       2     2        6
  17        3        3           2       2     1        5
  18        2        2           1       1     2        3
  19        2        1           1       1     2        2
  20        2        1           1       0     2        1
  21        2        1           1       0     2        0
  22        2        1           1       0     2        0
  23        2        1           1       0     2        0
Determination of tent roof radius r


Slowly changing inputs

The input data was as follows:
888875311000000123578888
888875311000000123578888
888875311000000123578888
865521000000000001135666
865521000000000001135666
865521000000000001135666


The results obtained were as follows:


HOUR                        TENT ROOF RADIUS r           Expected
            2        3           4      5   6    7   8
   0        6        7           5      5   5    6   6      8
   1        6        6           4      4   4    5   5      6
   2        6        5           3      3   3    4   4      5
   3        3        4           2      2   2    3   3      5
   4        1        3           1      1   1    2   3      2
   5        1        2           0      0   0    1   2      1
   6        0        1           0      0   0    0   1      0
   7        0        0           0      0   0    0   0      0
   8        0        0           0      0   0    0   0      0
   9        0        0           0      0   0    0   0      0
  10        0        0           0      0   0    0   1      0
  11        0        0           0      0   0    1   1      0
  12        0        0           0      0   1    1   2      0
  13        0        0           0      0   1    2   3      0
  14        0        0           1      1   2    3   4      0
  15        0        1           2      2   3    4   4      0
  16        0        1           3      3   4    4   5      0
  17        1        1           4      4   4    5   5      1
  18        1        1           5      5   5    5   5      1
  19        3        3           5      6   5    5   5      3
  20        5        5           6      6   5    6   6      5
  21        6        6           6      6   6    6   6      6
  22        6        7           6      6   6    6   6      6
  23        6        7           6      6   6    6   6      6
Rapidly changing inputs

The input data was as follows:
888875311000000123578888
000123468888888865321000
000123468888888865321000
000123468888888865321000
000123468888888865321000
000123468888888865321000
000123468888888865321000


The results obtained were as follows:


HOUR                        TENT ROOF RADIUS r           Expected
            2        3           4      5   6    7   8
   0        1        1           1      1   1    0   0      0
   1        1        1           1      2   2    1   1      0
   2        1        1           1      2   3    2   2      0
   3        2        1           1      3   4    3   3      1
   4        3        2           2      4   5    4   4      2
   5        2        3           3      5   6    5   5      3
   6        4        4           4      6   6    6   6      4
   7        5        5           5      6   7    7   7      6
   8        6        6           6      6   8    8   8      8
   9        6        6           6      6   8    8   7      8
  10        6        6           6      6   8    7   7      8
  11        6        6           6      6   7    7   6      8
  12        6        6           6      6   7    6   5      8
  13        6        6           6      6   6    5   4      8
  14        6        6           6      5   5    4   3      8
  15        5        6           5      4   4    3   3      8
  16        3        4           4      3   3    2   2      6
  17        2        3           3      2   2    1   2      5
  18        2        3           2      1   1    1   1      3
  19        3        2           1      1   1    1   1      2
  20        2        1           1      1   1    0   1      1
  21        1        1           1      1   0    0   0      0
  22        1        1           1      1   0    0   0      0
  23        1        1           1      1   0    0   0      0
Appendix F
Double Exponential Smoothing Testing



The following data and graphs correspond to tests carried out on the final system which
used double exponential smoothing, in preference to single exponential smoothing, and
tent roof tensioning.


Firstly, the data generated from the tests, along with the test data, is supplied. The
graphs derived from this data are then presented.


The significance of these graphs is considerable. They show the capacity of the Smart
Lamp to learn under a number of different operating conditions.
Double Exponential
Smoothing


                                                                 HOUR OF DAY
                         0   1   2   3   4   5   6   7   8   9   10 11 12 13 14 15 16 17 18 19 20 21 22 23
Static inputs
Input 1 - 2              8   8   8   8   7   5   3   1   1   0   0   0   0   0   0   1   2   3   5   7   8   8   8   8
Output 1 - 2             7   6   5   4   3   2   1   0   0   0   0   0   1   2   3   4   5   6   7   7   7   8   8   8

Slowly varying inputs
Input 1 - 2              8   8   8   8   7   5   3   1   1   0   0   0   0   0   0   1   2   3   5   7   8   8   8   8
Input 3 - 5              8   8   8   7   6   3   1   0   0   0   0   0   0   1   2   5   6   8   8   8   8   8   8   8
Output 1 - 2             7   6   5   4   3   2   1   1   0   0   0   1   2   2   3   4   5   6   7   7   7   8   8   8
Output 3                 7   6   5   4   3   2   2   1   1   1   2   3   4   4   5   5   6   6   7   7   7   8   8   8
Output 4 - 5             7   6   5   4   3   2   1   0   0   0   1   2   3   4   5   5   6   6   7   7   7   8   8   8

Rapidly varying inputs
Input 1 - 2              8   8   8   8   7   5   3   1   1   0   0   0   0   0   0   1   2   3   5   7   8   8   8   8
Input 3 - 5              0   0   0   1   1   2   3   6   8   8   8   8   8   8   7   7   5   4   3   2   1   1   0   0
Output 1 - 2             7   6   5   4   3   2   1   1   0   0   0   1   2   2   3   4   5   6   7   7   7   8   8   8
Output 3                 4   4   3   3   3   2   2   2   2   2   2   1   2   2   2   3   4   4   4   4   4   4   4   4
Output 4                 1   2   2   3   3   4   4   4   4   4   4   3   2   2   2   2   1   1   1   1   1   1   1   1
Output 5                 1   2   3   4   5   6   6   6   6   6   6   6   6   6   6   6   5   4   3   2   2   1   0   0

Noise type inputs
Input 1 - 2              8   8   8   8   7   5   3   1   1   0   0   0   0   0   0   1   2   3   5   7   8   8   8   8
Input 3                  8   0   8   8   7   5   3   1   1   0   0   0   0   8   0   1   2   3   5   7   8   8   8   8
Output 1 - 2             7   6   5   4   3   2   1   1   0   0   0   1   2   2   3   4   5   6   7   7   7   8   8   8
Output 3                 7   6   5   4   3   2   1   0   1   0   0   0   0   1   2   3   4   5   6   6   7   7   8   8
                                                  Double Exponential Smoothing: Static Inputs

                  9


                  8


                  7


                  6
Light Intensity




                  5
                                                                                                                                        Input 1 - 2
                                                                                                                                        Output 1 - 2
                  4


                  3


                  2


                  1


                  0
                      1   2   3   4   5   6   7   8   9   10   11    12   13     14   15   16   17   18   19   20   21   22   23   24
                                                                    Time (hrs)
                                              Double Exponential Smoothing: Slowly Varying Inputs

                  9



                  8



                  7



                  6
Light Intensity




                                                                                                                                         Input 1   -2
                  5
                                                                                                                                         Input 3   -5
                                                                                                                                         O utput   1-2
                                                                                                                                         O utput   3
                  4
                                                                                                                                         O utput   4-5


                  3



                  2



                  1



                  0
                      1   2   3   4   5   6   7   8   9   10   11    12   13      14   15   16   17   18   19   20   21   22   23   24
                                                                    T ime (hrs)
                                                  Double Exponential Smoothing: Rapidly varying inputs


                  9



                  8



                  7



                  6

                                                                                                                                          Input 1 - 2
Light Intensity




                  5                                                                                                                       Input 3 - 5
                                                                                                                                          Output 1 - 2
                                                                                                                                          Output 3
                  4                                                                                                                       Output 4
                                                                                                                                          Output 5

                  3



                  2



                  1



                  0
                      1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25
                                                                    Time (hrs)
                                                  Double Exponential Smoothing: Noise type inputs

                  9



                  8



                  7



                  6
Light Intensity




                  5                                                                                                                   Input 1 - 2
                                                                                                                                      Input 3
                                                                                                                                      Output 1 - 2
                  4                                                                                                                   Output 3


                  3



                  2



                  1



                  0
                      1   2   3   4   5   6   7    8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24
                                                                 Time (Hours)

				
DOCUMENT INFO
Shared By:
Categories:
Tags: Smart, Lamp
Stats:
views:135
posted:5/5/2010
language:English
pages:101
Description: Smart Lamp