Question? Leave a message!




Embedded Control Systems

Embedded Control Systems 39
Embedded Control Systems ETH – Institute for Dynamic Systems and Control September 12 to 16 and 19 to 13, 2016 Jim Freudenberg jfrumich.edu Christoph Skrabel cskrabelstudent.ethz.ch Simone Guscetti simonegustudent.ethz.ch Stijn van Dooren stijnvaethz.ch Marianne Schmid marischmethz.ch Schedule •  Lecture 8:00 – 10:00 –  Sampling and aliasing, signal processing, dynamic systems, integration techniques, etc. •  Assisted Prelab: 10:00 – 12:00 –  Material specific to the lab exercise: pulsewidth modulation, quadrature decoding, A/D conversion, etc. –  I’ll present required information in the lecture room, then we’ll move to the lab Important Points •  No textbook –  www.idsc.ethz.ch/education/lectures/ embeddedcontrolsystems.html –  Lecture notes, microprocessor reference material, laboratory exercises, and other important information –  Day to day list of reference materials on website •  No required homework problems –  Matlab, Simulink, Stateflow Important Points •  Laboratory exercises –  8 laboratory exercises in 10 days using the Freescale MPC5553 microprocessor •  Most labs are “1day” •  First lab will be Monday and Tuesday •  Schedule posted –  33 registered students –  11 lab stations with 3 students (“self organize”) Important Points •  Laboratory exercises have 3 parts: –  Assisted Prelab (10AM12PM): questions that require you to read the microprocessor reference material and gather the information required to complete the lab exercise –  Assisted Inlab (14PM): the experiment –  Postlab (45PM) : questions that should reinforce what you learned in the lab exercise (due 10AM the next day) •  You must attend 8 lab sessions and hand in all 8 lab assignments (pre, in and postlab) to receive credit for the course Everyday Time Schedule Prof. R. Schedule Embedded Control Systems (Fall 2016) Prof. C. Onder 151059300 D'Andrea Lectures Week 1 in Room ML F 40 (8 to 10 a.m.) Lab in Room ML E 55 10 a.m. 11 12 a.m. 1 p.m. 2 3 4 5 p.m. No. Date Topic No. Topic Course introduction. Start on A/D conversion, sampling and aliasing; simple anti Familiarization and Digital I/O. Reading in 1 20160912 1 aliasing filter design MPC5553 Referense Manual, introduction Introduction PreLab InLab to hardware (oscilloscope, signal generator, etc.) Finish A/D conversion, sampling and aliasing; simple antialiasing filter design; Continue with Lab 1 2 20160913 1 introduction to Matlab and Simulink; demonstrate Simulink by doing "Problem InLab InLab PostLab set 1" filter design. Introduction to Stateflow, in particular, demonstrate problem set 2, building a Quadrature Decoding using the enhanced 3 20160914 2 Stateflow quadrature decode model. Introduction to DC motors; derive steady Time Processing Unit (eTPU) PreLab InLab PostLab state motor equations. Present lecture material on optical encoders, quadrature decoding, over/underflow and typecasting. Discuss motor control (speed control, torque control, power amplifiers); Pulse Queued AnalogToDigital Conversion 4 20160915 3 width modulation; virtual worlds, wall "chatter" and the virtual wall. (QADC) PreLab InLab PostLab Dynamic systems and transient specifications (review); develop dynamic motor Pulse Width Modulation (PWM) and Virtual 5 20160916 4 model block diagram and implement in Simulink (domonstrate problem set 3). Worlds without Time PreLab InLab PostLab Develop motor frequency response and demonstrate input PWM attenuation. Lectures Week 2 in Room ML H 43 (8 to 10 a.m.) Lab in Room ML E 55 10 a.m. 11 12 a.m. 1 p.m. 2 3 4 5 p.m. No. Date Topic No. Topic Develop Stateflow model of the virtual wall (demonstrate problem set 5). Interrupts, Timing, and Frequency Analysis 6 20160919 5 Develop virtual springmass system dynamics (harmonic oscillator). Introduce of PWM Signals PreLab InLab PostLab Euler Integration and pseudocode for the springmass system. Introduction to ztransforms and numerical instability. Develop the virtual spring Virtual Worlds with Time 7 20160920 6 massdamper (calculate how much damping is required to create a discrete PreLab InLab PostLab harmonic oscillator using Forward Euler). Introduce statespace notation. Discuss other numerical integration methods; discuss how Matlab does numerical integration Software architecture, realtime operating systems and scheduling algorithms. Code Generation with SIMULINK (RAppID 8 20160921 7 Rapid prototyping and automatic code generation. Toolbox) Mathwork Pre, In PostLab Pre, In PostLab (location TBA) Software architecture; presentation of MathWorks on Autocode generation with Continue with Lab 7, catch up with other 9 20160922 7 SIMULINK labs Pre, In PostLab Pre, In PostLab Introduction to CAN networks. Controller Area Network 10 20160923 8 PreLab InLab PostLab IMPORTANT: You must attend 8 lab sessions and hand in all 8 assignments (pre, in and postlab) to receive credit for the course. Prelabs are due at the start of the Inlabs, Postlabs are due at 5 p.m.What is an Embedded System •  Technology containing a microprocessor as a component –  cell phone –  digital camera •  Constraints not found in desktop applications –  cost –  power –  memory –  user interface ⇒ Embedded processor is often the performance and cost limiting component What is an Embedded Control System •  Technology containing a microprocessor as a component used for control: –  automobiles –  hospital beds –  laser printers –  aircraft – civil structures   –  household appliances – manufacturing   –  copy machines – ener  gy harvesters –  wind turbines –  medical devices Characteristics of Embedded Control Systems •  Interface with external environment –  sensors and actuators •  Real time critical –  performance and safety –  embedded software must execute in synchrony with physical system •  Hybrid behavior –  continuous dynamics –  state machines •  Distributed control –  networks of embedded microprocessors Prime Example: today’s automobile The Automobile in 1977 16 electrical systems •  spark timing •  air/fuel 1976 Chrysler •  analog control 1977 GM Olds Toronado 1978 Ford Lincoln Versailles •  microprocessor control IEEE Spectrum special issue on the Automobile, Nov 1977 The Future in 1977 Gas turbine engines 100 proposed electrical systems High end automobiles: as many as 8 microprocessors, one per cylinder (Aston Martin) 10K ROM: plenty unused capacity to control other engine functions Obstacles: high cost of sensors and actuators “the inability of the electrical engineer to characterize the mechanical system for microprocessor programmers” IEEE Spectrum special issue on the Automobile, Nov 1977 The Automobile in 2016 •  Drivetrain   Variable geometry turbochargers   Variable cam timing (intake, exhaust, dualequal, dual independent)   Variable valve timing   Variable compression ratio   Automatic transmission, continuously variable tranmission •  Chassis control   antilock brakes   traction control   stability control •  Body control   seats   windows   wipers   locks •  Infotainment/GPS systems •  Driver assistance active safety systems  è Cars today are safer, less polluting, more fuel efficient, and more convenient than in 1977 The Automobile in 2010 Harvard Business Review, 2010 Industry Hiring Needs   •  “The auto industry is … hiring a different breed of engineer to invent the next generation of complex software for m.p.g., clean emissions and crash avoidance technologies.” •  “GM's biggest engineering recruiting challenges are software and controls engineering” •  Ford: greatest hiring need is for software and electronics skills •  2012 SAE salary survey: EEs working in automotive sector earn 10K/year more than MEs •  Ford: “Across the autoengineering spectrum right now, there is a war for talent” Detroit Free Press, October 2012 USA Today, July 2013 www.sae.org/membership/salarysurvey/ “Detroit Battles for the Soul of Self Driving Machines”, June 2016 Wall Street Journal An Industry Request: 1998 Dr.  Ken  Bus:   • Ford  Research  (currently  Toyota)   • Founding  member,  MATHWORKS  AutomoEve  Advisory  Board  (1998)   “Why  can’t  I  hire  students  trained  to  do  embedded  control  so6ware  development”      “And  why  don’t  the  students  I  hire  know  how  to  talk  to  one  another”       Skills  required:   • Control  algorithms   • Computer  soNware   • Computer  hardware   • Electronics   • Mechanical  engineering        Outcome: Two Courses •  UofMichigan: EECS 461, Embedded Control Systems th –  17 year –  200 students/year –  Jeff Cook, formerly Ford Research –  Student body: •  EE and CE, seniors and masters •  Space permitting, grad students from other departments •  ETH Zurich: 151059300, Embedded Control Systems th –  9 year as two week block course –  33 students/year –  Mechanical Engineering Graduate Students Embedded  Control  Enrollment:  UM  and  ETH   220   200   180   160   140   Fall  (ETH)   120   Spring  (EECS  461)   100   Winter  (EECS461)   Fall  (EECS  461)     80   Fall  (EECS  498)   60   40   20   0    00­‐01    01­‐02    02­‐03    03­‐04    04­‐05    05­‐06    06­‐07    07­‐08    08­‐09    09­‐10    10­‐11    11­‐12    12­‐13  13­‐14  14­‐15  15­‐16  16­‐17   Academic  Year   Total Enrollment: 1949 students  Laboratory Overview •  MPC5553 Microcontroller (Freescale) •  Development Environment –  Debugger (PE Micro) –  Codewarrior C compiler (Freescale) •  Haptic Interface –  Force feedback system for human/computer interaction •  Rapid Prototyping Tools –  Matlab/Simulink/Stateflow, Embedded Coder (The Mathworks) –  RAppID Toolbox (Freescale) Freescale MPC5553 Microcontroller •  32 bit PPC core –  floating point –  132 MHz –  40 to +125 °C temperature range •  Programmable Time Processing Unit (eTPU) –  Additional, special purpose processor handles I/O that would otherwise require CPU interrupt service (or separate chip) –  Quadrature decoding –  Pulse Width Modulation •  Control Area Networking (CAN) modules nd •  2 member of the MPC55xx family –  real time control requiring computationally complex algorithms –  MPC5554 replaces MPC555 for powertrain control –  MPC5553 has onchip Ethernet for manufacturing applications MPC5553 EVB •Evaluation board (Freescale)    32 bit PPC core  floating point 128 MHz   • Interface board (UofM)   – buf  fering – dipswitches   –  LEDs –  rotary potentiometer Nexus Compliant Debugger (PE Micro) Haptic Interface •  Enables human/computer interaction through sense of touch –  force feedback –  virtual reality simulators (flight, driving) –  training (surgery, assembly) –  teleoperation (manufacturing, surgery) –  Xbywire cars •  Human visual sensor: 30 Hz •  Human haptic sensor: 500Hz1kHz •  Ideal pedagogical tool…. –  student satisfaction –  virtual reality algorithms easy to understand –  tricky to get right Force Feedback Haptic Wheel Lab Station •  Haptic Interface –  DC motor –  PWM amplifier w/ current controller –  optical encoder rd –  3 generation Lectures (I) •  Quantization •  Sampling •  Linear filtering •  Quadrature decoding •  DC motors •  Pulse Width Modulation (PWM) amplifiers •  Motor control: current (torque) vs. speed •  MPC5553 architecture. Peripherals: eMIOS, eTPU… •  Haptic interfaces. –  virtual wall –  virtual spring/mass/damper •  Simulink/Stateflow modeling of hybrid dynamical systems •  Numerical integration. Lectures (II) •  Networking: –  Control Area Network (CAN) protocol. –  Distributed control •  Interrupt routines: timing and shared data •  Software architecture –  Round robin –  Round robin with interrupts –  Real time operating systems (RTOS) –  Multitasking •  Shared data: semaphores, priority inheritance, priority ceiling •  Real time computation. Rate monotonic scheduling. •  Rapid prototyping. Autocode generation. •  Model based embedded control software development •  PID control design Laboratory Exercises •   Each teaches –  a peripheral on the MPC5553 –  a signals and systems concept –  Labs 16, 8: program in C –  Lab 7: autocode generation – Each lab reuses concepts (and code) from the previous labs   •  Lab 1: Familiarization and digital I/O •  Lab 2: Quadrature decoding using the eTimer •  Lab 3: Queued AD conversion •  Lab 4: Pulse Width Modulation and simple virtual worlds •  Lab 5: Interrupt timing and frequency analysis of PWM signals •  Lab 6: Virtual worlds with dynamics •  Lab 7: Rapid Prototyping •  Lab 8: Controller Area Network (CAN) Lab 1: Familiarization and Digital I/O •  Use General Purpose Input/Output (GPIO) on MPC5553 •  Use “union” command to write C code to perform bit manipulations •  Read two 4bit numbers set by dipswitches –  add and display on LEDS •  Write C header file to access various bits in a 16 bit register: typedef union SIUCONFIGUNION / This allows access to all 16bits in the register / unsigned short REG; / This structure allows access to the individual bytes of the register / struct unsigned short UPPER:8; / access to the top 8 bits / unsigned short LOWER:8; / access to the bottom 8 bits / BYTE; / This structure splits apart the different fields of the register / struct unsigned short :2; / indicates 2 unused bits in the register / unsigned short FIELD1:8; / access to the 8bit field named FIELD1 / unsigned short FIELD2:6; / access to the next 6bit field / FIELDS; EXAMPLEREGISTER; •  Remaining labs use Freescale supplied header files Lab 2: Quadrature Decoding •  Optical encoder attached to motor generates two 90° out of phase square waves: • QD function on MPC5553 eTPU:   decodes quadrature signal into counter • CPU must read counter before overflow   Issue: How fast can wheel turn before counter overflows Lab 3: A/D Conversion •  Uses QADC on the MPC5553 •  Acquire analog input from potentiometer or signal generator •  Measure time required for one conversion by toggling bit •  Investigate aliasing •  Software oscilloscope: Lab 4: Pulse Width Modulation •  Drive DC motor with a PWM signal –  Switching frequency 20 kHz –  Duty cycle 40 –  eMIOS peripheral on MPC5553 −3 duty cycle = 40 , switching frequency = 20000 Hz duty cycle = 40 , switching frequency = 20000 Hz x 10 4.5 4 1 3.5 0.8 3 2.5 0.6 2 0.4 1.5 1 0.2 0.5 0 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5−1−0.8−0.6−0.4−0.2 0 0.2 0.4 0.6 0.8 1 −4 5 time,seconds frequency, Hz x 10 x 10 PWM signalLab 4: Virtual Wall •  Software loop • Wall  chaer   –  read position from encoder – large  k  required  to  make  sEff   –  compute force F = 0 or F = kx wall   –  set PWM duty cycle – limit  cycle  due  to  sampling  and   •  Rotary motion quanEzaEon   –  degrees encoder count ⇔ –  torque PWM duty cycle ⇔   –  1 degree into wall 400 Nmm ⇔ torque Lab 5: Interrupt Timing and PWM Frequency Analysis •  Use interrupt timer to generate a time step for numerical differentiation and integration •  Periodically modulate duty cycle of a 20kHz PWM signal by writing an ISR that either –  Samples 100 hz sine wave. filtered PWM output –  Calls C sine function 0.5 0.4 –  Uses lookup table 0.3 •  Time ISR by toggling a bit 0.2 0.1 •  Filter PWM signal to remove 0 20kHz switching frequency. −0.1 −0.2 −0.3 −0.4 −0.5 0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01 time, secondsLab 6: Virtual SpringMass System •  Virtual springmass system: reaction force F = k(wz) •  Measure z, must obtain w by numerical integration •  Use interrupt timer to generate a time step k k  w+ w= z m m k k  θ +θ =θ w w z J J w w Design Specifications • Choose   k and J so that w – virtual wheel oscillates at 1Hz   – maximum torque in response to 45 degree step in wheel   position is 800Nmm •  Verify design in Simulink before testing on hardware Numerical Integration •  Forward  Euler:      –   easy  to  program  in  real  Eme     –   no  direct  feedthrough,  no  algebraic  loops   –   numerically  unstable   •  QuesEon:  Can  we  restore  stability  by  adding   virtual  damping   Ye                                          s      Can  compute  b  mathema5cally.  Autocode Generation (I) •  Derive a mathematical model of system to be controlled •  Develop a Simulink/Stateflow model of the system. •  Design and test a control algorithm using this model. •  Use Simulink Coder to generate Ccode. •  Eliminates coding errors. •  Rapid prototyping: Speeds product development as generated code can be tested in many design cycles •  Autocode in production: –  Nonconsumer market: NASA, aerospace –  Automotive: body control powertrain control Autocode Generation (II) •  Need Simulink blocks: –  device drivers –  processor and peripheral initialization •  Issues: –  efficiency of generated code –  structure of code •  Multitasking –  with RTOS, task states –  without RTOS, nested interrupts RAppID Toolbox (Freescale) •  Processor and peripheral initialization blocks •  Device driver blocks •  Enables multitasking with nested interrupts RA ppID M PC5554 Target Setup System Clock : 128 MHz Target : MPC5554 Compiler : m etrowerks Target Type : IntRAM Operating System : simpletarget RAppIDE CLab 7: Two virtual wheels Total reaction torque Multirate Simulation for Code Generation Fast and slow subsystems Fast  subsystem   Slow  subsystem  Device Drivers Read  encoder  and   translate  to  degrees   Convert  torque  to     duty  cycle  and  write   to  PWM  Lab 8: Controller Area Networking (CAN) •  Networking protocol used in timecritical applications •  Messages have unique identifiers: priorities •  Allows computation of worst case response time •  Lab exercises: –  implement virtual wall remotely –  estimate network utilization –  virtual “daisy chain” T =kθ−θ +kθ−θ ( ) ( ) i jUM Project: Adaptive Cruise Control •  Driving  simulator    •  Bicy cle  model  of  vehicle   •  6  vehicles  interacEng         over  CAN  network   •“   Lane  centering”   •  ACC  algorithm:  3  states    –  manual  (sliding  pot)    –   constant  speed   –  constant  distance     Controller Block Diagram Observations •  Multidisciplinary •  Multiple layers of abstraction •  Successful embedded engineers understand time –  Mechanical/electrical engineers: time in the application domain (physics) 10 –  Computer engineers: time on the microprocessor ( ) •  “pure” software engineers lack necessary background. •  Applications in many areas –  aerospace –  household appliances –  robotics –  civil engineering –  defense –  medical devices The Automobile and the Future More fuel efficient vehicles = lighter less survivable in an accident. Solution: avoid accidents by eliminating driver error. More jobs for embedded è control engineers Lino Guzzella ETH, IEEE Spectrum May 2014   Active Safety Systems   Video camera Ult ras onic AdapEve  cruise  control   s ens or Ult ras onic s ens or Video camera Collision  avoidance   L ongrangeLane  departure  warning   radar Lane  following   Shortrange radar Ult ras onic Cen t ral Ult ras onic s ens or c omput er s ens or IEEE  Spectrum  May  2014,  “The  Rise  of  the  Crash  Proof  Car”   Fully Autonomous Vehicles May  27,  2014   A Cautionary Note October  2013:  3  million  selement   Bookou                t  vs  Toyota                    unintended  acceleraEon     March  2014:  1.2  billion  selement   Wall Street Journal, December 2013: “Will tort law kill driverless cars” Fox News, March 2014: “Justice Department announces 1.2 billion settlement with Toyota” Testimony Expert  witnesses:     PhilKoopman  ,  CMU  ­‐  “Code  had  10,000  global  variables”     Michael  Barr,  Barr  Group  –  “Code  had  bugs  that  could  cause  unintended  acceleraEon”       Wall  Street  Journal:  “how  is  a  car  maker  supposed  to  defend  itself  when  it  can't  prove    that  its  soNware  behaves  safely  under  all  circumstances”     The  Google  car  has  been  driven  500K  miles  with  no  accident     Toyota  Camrys  were  driven  billions  of  miles  before  soNware  error  (if  it  was  that)  emerged   Jack  Ganssle  “A  Pox  on  Globals”,  embedded.com,  Oct.  2006   www.safetyresearch.net/2013/11/07/  National Science Foundation Research Cyber­‐physical  systems  (CPS):                          interacEon  between  computaEonal  elements  and  physical  world.      networks  of  embedded  control  systems     Since  comprehensive  tesEng  is  not  feasible…                    how  to  write  soNware  that  works  because  it  is  wrien  correctly       NSF  CPS  FronEer  Project  (UofM,  hp://www.dynamiccps.org):       “CorrectbyDesign Control Software Synthesis for Highly Dynamic Systems”       Pedagogical  Challenge:  CPS  requires  students  to  be  educated                                    “outside  the  tradiEonal  academic  stovepipes”    Impact on Pedagogy Michael Barr: Top 10 embedded software bugs The ones we learn about in EECS 461 are underlined Race Condition Memory leak Nonreentrant function Deadlock Missing volatile keyword Priority inversion Stack Overflow Incorrect priority assignment Heap Fragmentation Jitter www.embedded.com 2010 Cybersecurity Wired Magazine, July 21, 2015: Hackers Remotely Kill a Jeep on the Highway—With Me in It After the brakes were remotely disabled: Cybersecurity is beyond the scope of EECS 461, yet former EECS 461 students are working in industry on connected vehicles today www.wired.com/2015/07/hackersremotelykilljeephighway/ Another  SoNware  Issue   Exhaust system of a Volkswagen Golf Volkswagen has used two basic types of technology to reduce emissions of nitrogen oxides from diesel engines, by either trapping the pollutants or treating them with urea. The first type is shown here. Main computer Engine control module Diesel oxidation Muffler Oxygen sensor catalytic converter Oxygen sensor H2S catalytic converter Diesel particulate filter Exhaust valve Temperature sensors Nitrogen oxide trap This system traps nitrogen oxides, reducing toxic emissions. But the engine must regularly use more fuel to allow the trap to work. The car’s computer could save fuel by allowing more pollutants to pass through the exhaust system. Saving fuel is one potential reason that Volkswagen’s software could have been altered to make cars pollute more, according to researchers at the International Council on Clean Transportation. Conclusions Electronics and software in automobiles has been a roaring success cleaner safer more sustainable Many other application areas: aerospace defense medical appliances The future will require more embedded control systems Big questions: are we creating technology too complex to understand and maintain how do we train the workforce First step: Take Embedded Control Systems