Question? Leave a message!




Introduction to Information Engineering

Introduction to Information Engineering 22
Introduction to Information Engineering Stephen RobertsLecture 1 A gentle introductionAims • To provide you with an overview of what B4 and information engineering in general is concerned with • To make explicit links between information engineering and the core syllabus especially A1, A2 and A3 • To give you some sense of how central information engineering is to the engineer’s career and to our every day lives.Course Outcomes At the end of this 4 lecture course you should • be able to deconstruct overall data capture / analysis / control system into components and understand how they interact • appreciate the role of the computer as a general purpose information processing tool • understand the role of the operating system and how both sensors and actuators can be interfaced to a computer at the hardware and software level • understand the role of probability as the mathematical tool for modelling uncertainty in sensors, and how to use Bayes rule as a means to combine sensor measurements or prior information • understand the consequences of sampling and ZOH, and how to discretize continuous controllers • be able to analyse the components of a fastsampled feedback system both in isolation and in the context of the complete systemThe Information Engineering Domain Inference and Analysis Estimation Data Processing Modelling and Control Operating System Data Acquisition Output Hardware Sensors Actuators Real WorldThe Role of Feedback • Note the presence of a feedback loop in the previous architecture. + C(s) G(s) H(s) • The control system block diagrams you manipulate in A3 are powerful mathematical abstractions for devising control strategies for systems • To actually instantiate/embed this control system in a real vehicle, the controller design and analysis, is only part of the story. Information engineering (inc B4) is much more than control theory.What is C(s) + C(s) G(s) H(s) A controller that is implemented in all likelihood on a C(s) computer Issues: •What does the software of the controller look like •What speed must it run at •Computers are discrete devices but the world is continuous so how does one link the two •Does using a discrete controller have stability implications •What design tools are available for the discrete domain •Do familiar continuous domain analysis tools have discrete time dualsWhat is H + C G H A transfer function between a sensed plant output and the H quantity we wish to control Issues: •How does one sample the plant output •How does one transmit measurements to the CPU running the controller •How does one guarantee that measurements will always be processed •What does one do if the sensed output is not what we wish to control e.g sensing color but wanting to control flow rate •How does one deal with noisy sensor data •How does one fuse multiple measurementsInformation Systems Exemplar • The “Segway” robot shown here is a container of many of the central concerns of the information engineer (and as it happens, electrical engineers) • Sensing (accelerometers, gyro) • Actuation Control (varying payload) • Computing – IO from sensors – Output to actuators – Controllers in software – Estimation of state by processing sensor dataNote: •Duplication of electronics (safety) •Requires interfacing of sensors and motors to computation •Requires control to be implemented on a computer •Control laws are non trivial : to stop you have to first speed up •Requires interpretation of sensor data •Requires an internal modelInfo Eng. Components of the Segway • Sensors 5 Corriolis (interesting) gyros How do you combine the information from 5 noisy sensors in a principled way (B4…)Computation Hardware • Data Acquisition : The PIC16F87x Flash microcontrollers process sensor data from the inertial monitoring unit and communicate information to the control module. • Control Module is a 100 MIPS Digital Signal Processor TMS320C2000 from Texas Instruments. • Communication is via CAN and I2C bus • Two boards acting in duplicate for safety • Some interesting stories on redundancy here….Exemplar II – a 3D laser System •Issues – synchronisation of disparate data streams •Estimation of system latencies3D ReconstructionCompelling Cross Discipline Problems Engine Management Building climate control Medical imaging Abnormality detection Very uncertain Plant Imprecise sensor data Machine Learning Large unknown lags Deformable structure Complex 3D reconstruction Diagnosis from measurementsAnd Some More Network analysis Car design National Grid Complex optimisation task Complicated nonlinear coupled Active suspension dynamics Traction control, slip estimation Plant identificationLecture II –The Role of the Computer • IO sensor interfaces – Serial ports – Ethernet – PCI – Firewire • Microcontrollers – PICs – embedded systems, – pic diagram ref segway • OS – device drivers • Processes and IPC (inter process communication)Motivation • If we are to design a complete information engineering system we may need to consider of how data is or should be marshalled • Data transfer technology is ubiquitous and 5 Engineers should be able to say something sensible about every day equipmentSensor/Actuator Interfacing • How to get data from sensor to processor Common choices – Direct to bus (PCI) – External serial protocols RS232, firewire, USB – CAN bus (controller area network) – All need hardware/software to transport data Flight surface control and Vehicle control Seismic sensing networks anomaly detectionStraight to PC Bus Example Engberg PCIDAS6035 •16 channels of 16bit A/D board Instrumentation Rig •two 12bit analog outputs •8 digital I/O lines, two 16bit counter Analog/digital data Control signal PCI BUS High power amplifier PCI Bus (Peripheral Component Interface Bus) •33Mhz Clock •Generally 32 bits wide (specification allows for 64 bits) •Allows plug and play – BIOS configures interrupts /address space •Allows burst mode transfers Offline analysis and inferenceInterDevice Serial Protocols Can be very simple to implement at its simplest one wire for Tx one for Rx and one for Gnd between two devices varying electrical and data protocols dictate complexity and performance Slow speed RS232, RS485, RS422 – the COM Ports on your PC, long distance, simple hardware, simple data protocol USB (universal serial bus) faster now ubiquitous, short distances, 12 Mbits/s or 480Mbits/s (USBII) Firewire (a.k.a IEEE 1394, iLink) very fast, short distance 800 Mbits/s CAN bus – very robust, multiple devices, slow, an industrial favourite. Very common in cars (invented by BMW)RS232/RS422 •Very common found on almost every nonlaptop PC (“COM ports”) •Generally slow data rates 115kBaud. Asynchronous – no clock •Sends / receives data in packets serially •At its most basic, RS232 needs only 3 signal wires Tx/Rx and Gnd (pins 2,3 and 5 on a 9 pin connector) •RS422 is a differential signal – instead of raising and lowing one wire at a time TXA goes up while TXB goes down •Depending on Baud rate can transmit many 10s of meters •Data protocol described using a triplet : •Data packet sizeParity BitNumStopBits •8N1 and 8N2is common – 8 data bits, no parity bit with one or two stop bits. •Voltage levels for RS232 and RS422 are typically large +/ 12V is common, but you can get away with 0 and 5V much of the time. •Note RS232 and RS422 are both electrical specifications of simple serial protocols •A special chip called a UART Universal Asynchronous Receive Transmit is used to manage the serial link and produce bytes of data from the serial stream This is 8E1 (even parity s.t ones is even) Image from www.bestmicrocontrollerprojects.comThe Microcontroller • Include hardware for common IO tasks – PWM (Pulse width modulation) – A2D D2A – Serial Ports (TTL not usually RS232 etc) – Digital IO • When deployed, typically only runs one program burnt into EEPROM. (ie no OS just a while(1)…) • On board RAM • Self contained – little external interfacing required • Can sometimes be programmed with high level languages like C using manufacturer’s compilers • Very cheap (almost free)PIC’s • PICS (Programmable Intelligent Computers) are very common brand of microcontrollers and you’ll find them everywhere • Typically slow clock rates (40MHz) • Very cheap (from a few pence) • Easy to program very few instructions • small number of pins very easy to interface • Typically little on board RAM (perhaps a few K of data space) • Ideal for dedicated processing unit for a single device for example interpreting keyboard interaction. Image ex wikepediaExample PIC16F87 (used in Segway) Typical applications of uControllers •Household appliances (washing machines) •Keyboards •Printers •Engine management systems •Any application that is IO intensive but requires little number crunchingDigital Signal Processors (DSP) • MAC (multiply and accumulate instruction) (recent PICS have MAC) • Hardware support for looping • Blindingly fast at common sigprocessing operations • Often not optimised for fast logic operations • Texas Instruments have a very popular range of DSP’s called the TMS320 series • DSP’s come in native integer and floating point varieties (in contrast with uControllers which are almost always just integer based) Around 8 Billion market for DSPs in 2006 These chips and the algorithms they support are truly important •Mobile phones •Digital TV boxes •Satellite comms •CD players/ MP3 players •(Segway robots…) The algorithms that support these applications are the domain of the information engineer.Why is MAC so Important • In B4 and C4 (if you take it) you’ll learn that the continuous transfer functions you are now familiar with (e.g C(s)) are in reality almost always implemented in discrete form on a computing device. • If C(s) is a continuous function you’ll soon learn how to map this to a discrete time controller C’(z) where z is the discrete time analogue of s • The upshot of all of this is that time and time again we’ll come across expressions like: Constant “filter” coefficients Output now Previous outputs Current input Previous inputs At each cycle a number of multiply and accumulates have to occur Many DSP can implement the above in a single clock cycle….Discrete Filter Design • Digital filters are ubiquitous and many sophisticated tools exist to design fitlers with required frequency characterstics. For example a notch filter to remove contamination at a given frequency…. 0 50 100 150 200 250 More on this later in B4 300 350 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fraction of nyquist frequency 100 50 0 50 100 150 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fraction of nyquist frequency Phase (degrees) Magnitude (dB)Micro Processors • Close approximation to what you’ll find in your PC – general purpose computation devices • No onboard IO like serial ports A2D etc • Often large word size • Little speed optimised hardware although recent x86’s have made inroads • Covered in A2From Hardware to main() Thread Additional execution streams Thread Multiple Running programs written User User User rd by users/3 parties Process Process Process Complicated program which abstracts Operating System hardware and provides process control “firmware” which glues motherboard BIOS – Basic input / output system together, sets up interrupts and eventually loads OS Hardware Hardisk, keyboard, graphics card Play with WinXP Profiler….The Role of the Operating System • Provides a hardware abstraction layer (HAL) – Provides an application programmers interface (API) for all kinds of hardware – e.g all keyboards look the same to programmers, all files on disk can be accessed in the same way (not a function of manufacturer) – Vendors of hardware write drivers which plug into one side of the HAL API and the writers of processes use the HAL API HAL API is a set of function like User Process WriteFile(), ReadFile, GetMouse() HAL OS Driver hardwareInterlude: Units of Execution Processes • A process is a fundamental concept to computing. • It represents a single instance of a running computer program – a sequence of serially executing instructions. • A process is allocated memory which is not (generally) seen by other processes • The times at which processes are run are scheduled by the operating systemInterlude: Units of Execution Threads • Threads are independent threads of execution within a single process. • Thread scheduling by the OS gives the appearance of concurrent execution • All threads within a given process can see (read and write) the same memory – that owned by the process. • For example a process might have a user interface thread (drawing, handling button presses) a computation thread and a sensor IO thread. • Operating systems provide system calls that start new threads from thread0 (the thread started by the OS when a process is started.)The Role of the Operating System • Provides a mechanism for scheduling / interleaving the execution of processes – Gives the appearance of concurrent process execution on a serial processor – Manages the context switching between processes. (switching relevant data in and out of processor registers) – Running processes “see” uninterrupted execution and need not (usually) be written to yield execution to siblings.The Role of the Operating System • Provides Memory Management – Running processes can request allocation of memory at run time – The physical memory is abstracted away from running processes – Memory may be a combination of physical RAM and disk spaceHandling Interrupts • More often than not interrupts are intercepted by the OS and mapped to calls into a relevant device driver • For example a UART may raise an interrupt when its Rx buffer is 50 full: – The interrupt calls a function in the serial port driver. – The driver extracts data from the hardware and places it a software buffer(array) provided by the OS – Processes granted access to the serial port read from this abstracted serial port when “reading” from the serial port.Interprocess Communication Communication mechanism Image Image Grabbing Understanding Producer Consumer We need to consider how data could be shared between producer and consumerShared Memory Process A Process B Shared Memory •Processes can make special system calls to the operating system which return a chunk of memory that can be shared between processes. •The OS also provides a mechanism by which a process can ask to have already allocated shared memory inserted into its own address space (Process B needs to be able to ask to see the shared memory segment already created by Process A) Q: What happens if the producer writes as the consumer tries to readThe need for Synchronisation write read Shared Memory write The consumer was reading as the producer executed the second write. The result is corrupted data. We need someway to synchronise the processes to protect resourcesBinary Semaphores Initialise a semaphore (which is a signal between threads or processes) to the number of times a protected resource can be shared (1) Call when access to the resource is required.This blocks (halts) execution until completion.When s0 is detected next line must complete before thread is rescheduled – it must be “atomic” (functionality provided by OS) Call when finished with resourceBinary Semaphore Example Process A (Producer) Read and writes are to shared memory Process B (Consumer) •Between P S privacy is guaranteed. •OS needs to provide Semaphore functionality and a mechanism to allow both processes to share the semaphore SLecture III The role of probability Theory • Sensor models • The Role of Bayes’ rule – Recursive estimation – Tracking – Plant models – FilteringRevision of Probability Product Rule Marginalisation If a b are continuous If a b are discrete If you can remember and use these two rules then so much is within your reach….(including exams)Probabilistic Models • We can think of sensor measurements, z, as samples from a conditional distribution (conditioned on the state of the world, x) Laser range finder (theodolite) True distance x Measured distance z = x + random noise p(zx) xSensor Models Cont – Gaussian Noise p(zx) Here we have elected to model noise as samples from a Gaussian which is a very common practice p(zx) explains the measurement in terms of the underlying stateEstimating x from p(zx) Estimation Engine Data Estimate Prior BeliefsMaximum Likelihood N.B Multivariate Gaussian Understood Find a value of x(state) that best explains z (data)Maximum Likelihood We are given a value for z and view p(zx) = f(x,z) as a function of x p(zx) x x ml ML does not incorporate prior knowledge C4B Mobile RobotsIncorporating Prior Knowledge What if we knew something abut the state of the world before we took the measurement – could we incorporate that information We can use a probability distribution over x to capture our prior belief in the p(x) value of x So how can we combine p(zx) and p(x) to yield p(xz) Bayes’ Rule A “joint distribution” A A \ B B A “conditional distribution” A “marginal distribution”Should we bother with Bayes Yes, you should be. Bayes’ rule lies at the very heart of swathes of information engineering: •Medical imaging •Tracking •Estimation •Sensor processing signal recovery •Machine learning Bayes’ Rule lets you invert conditionals expressing p(ab) in terms of p(ba)Consider Our Laser Example p(zx)Apply Bayes’ Rule The x which maximises p(xz) is called the “maximum a posteriori” estimateMaximum A Posteriori Estimation Note denominator is not a function of x – it is a normaliser M.A.P does incorporate prior knowledgeExample Cont… Mean VarianceHow does the mean change Old (prior) mean Difference between measurement and priorVisually… Remember the variance of posterior is smaller than the prior – why because the measurement adds information. This notion will be formalised later in the courseDiscrete Time Recursive Bayesian Estimation Subscript is time Sequence of data (measurements) We want the conditional distribution State at time k Sequence of measurements up (think position) until time k (think list of ranges) Question: Can we iteratively calculate this – ie every time a new measurement comes in update our estimate – (Answer :yes, see next slide) posterior prior measurement We are looking for a distribution over state at time k given all measurements up until time kRecursive (online) Bayes’Key Result At time k Explains data at time k At time k1 as function of x at time k C4B Mobile RobotsIncorporating Plant Models We should have used a k subscript on x to indicate that we are referring to x at time k Now the last term on the numerator looks like a prediction. Previous state new state F Uncertain Plant Model controlIncorporating Plant Uncertainty Probabilistic plant model Last estimate Here we have used the assumptions •that given the state at k1 and control at time k, the state at time k is independent of the observations •The state at time k1 is independent of the control at time k (which is in the future)Applications The previous few slides have indicated the existence of a probabilistic framework which can handle uncertainty in measurements and plant models Note that at no point were we restricted by the form of the p.d.f’s or what the physical interpretation of x,z or u might be. •x: rate of inflation, z: the price of a car, u: intervention from the world bank •x: strain on a beam, z: measured voltage •x: car velocity, z police radar time of flight •x: sheet metal thickness, z:XRay energy, u: roller pressure •x: tumour state, z: PET scan, u:motion of patients head during scan Probabilistic methods are a natural way to handle uncertainty in measurement and state evolution. The techniques they give rise find application across all domains of engineeringThe Role of the Gaussian It is common to find that the functional form of the pdfs in the previous slides is that of a Gaussian. Of course we may have distribution over a vector (for example position and velocity). In which case we shall be dealing with the multidimensional Normal distribution. A “joint” distribution over x and yThe structure of Σ . You can read the marginal distribution variance off the diagonals of the covariance of the jointThe Gaussian is a common functional form If Gaussians are used in the pdfs of the recursive Bayes formulation and in the equations we derived for propagating plant uncertainty one ends up with something called a Kalman Filter (covered in detail in C4) The Kalman filter is a very common tool in estimation applications. For example • in car navigation systems • Hawkeye • Economic models. • Hospital delivery systems • Port automationState Vector Hawkeye Camera 2 (observer) Flight Parameters Camera 1 (observer) Image coordinates Sequential Images from a single cameraExtracting the Observations… Is a hard information engineering problem in itself Again it turns out that solutions to this problem are underpinned by probability theory More of this kind of problem (and solutions) in B4 and C4Lecture IV Computer Based Feedback Control and Actuation • You are already familiar with continuous time control systems plant controller r(t) e(t) y(t) u(t) + D(s) G(s) 1 sensorsIn Practice: Using A Digital Computer • We implement the controller in software running on a digital conputer • We need to convert twixt digital and analog… controller plant y(t) Sample DAC e(kt) u(kt) u(t) r(t) + D G(s) ADC Hold r(kt) Sample 1 ADC sensors Digital, sampled system •The signals e(kT) u(kT) and r(kT) are “discrete” •T is the sample period,k is an integer •A discrete signal is constant over the sample period Notation: for a discrete signal y, constant T: y(kT) = y(k) = y kDiscrete Signals sample y(t) y(kT) • The quantity y(kT) is a discrete sampled signal • T is the sample period (assumed constant) • k is an integer • A discrete signal is representative of the continuous signal over the sample period • Think of y(kT) as a number. Its precision is dictated by the precision of the sampling hardware (e.g 8 or 16 bits)How do we implement a discrete time controller Imagine we have been given the desired controller transfer function D(s) , how might we construct a discrete time version Writing D(s) as a quotient of two polynomials in s Last step renormalises by dividing both sides by a oApproximating the derivative operator • You know from A1 that • So we could substitute these discrete derivative approximations intoExample control at time k is function of previous control and previous and current inputExample Continued Note how easy this is to implement. In general requires variables to be stored across iterations Note how the constants are dependent on sample time. If we keep sample time constant computation is simplified even further. Are we free to choose any T (even if we keep it constant) We can imagine that the answer is no – whyThe Effect of Sample and Hold x(t) Zero order hold introduces a lag of T/2 x(kT) Or equivalently a phase lag ofImpact of sample on Closed Loop Stability Unit circle 1 Phase lag can rotate Nyquist diagram to encircle 1,0 causing instability (from A3) Increasing D(jw)G(jw)Example Using Simulink Continuous Controller Discrete controllerSimulation Results 1.5 1 Blue: continuous Good performance 0.5 system response 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 1.5 Red: sampled system response 1 0.5 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 1.5 1 0.5 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 4 2 instability 0 2 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 time (s) As sample rate falls performance degrades – dynamics of plant dictate sample rate and ultimately speed of controller iteration Sample rate 10 Hz 20 Hz 80 Hz 5 HzSummary • If you sample fast enough a digital controller can be a fine approximation to continuous system. • General rule of thumb is to sample at more than 30 times plant band width. • If you can’t sample this fast then you need to know more information engineering and come to the Computer Controlled Systems Lectures….Course Conclusion • This was a very brief tour over just some of the areas that concern and interest information engineers and the domains that information engineering has a role to play • In places we have given a few samples of the kind of mathematics you shall see more of in B4 and if you get hooked C4A and C4B • Hopefully you’ll now be aware that B4 is not just the “control paper” although it does contain a wholesome amount of that important information engineering topic. • Hopefully you’ll have had your interest piqued and have the sense that if you are going to a financier or an engineer that at some point needs to process data (so that’s pretty much all of them) then information engineering has a great deal to offer you After all, it brought you Google…