1 context the semantic gap control theoretical aspects
play

1 Context The semantic gap Control-theoretical aspects Compilation - PowerPoint PPT Presentation

1 Context The semantic gap Control-theoretical aspects Compilation aspects C code production 2 From real to floats Example of linear invariant system Numerical precision problems Machine representation of real numbers Alteration of constants


  1. 1 Context The semantic gap Control-theoretical aspects Compilation aspects C code production 2 From real to floats Example of linear invariant system Numerical precision problems Machine representation of real numbers Alteration of constants Rounding errors Other systems 3 Closing the loop Closed-loop system Proof scheme Vivien Maisonneuve From Reals to Floats November 23, 2012 1 / 24

  2. From Physics to Interrupt Handlers: The Real to Float Step Vivien Maisonneuve CRI, MINES ParisTech Presentation at Toccata November 23, 2012 Vivien Maisonneuve From Reals to Floats November 23, 2012 2 / 24

  3. Context The semantic gap Different levels of description In control engineering, work on different levels to design and build a control system: • Format/high-level aspects: system conception, modeling, possibly proof. • Concrete/low-level aspects: creation of an object implementing the system. Quadricopter, DRONE Project, MINES ParisTech & ECP. Vivien Maisonneuve From Reals to Floats November 23, 2012 3 / 24

  4. Context The semantic gap Formal aspect model object System definition: • Inputs: sensors [accelerometer, sonar. . . ] + references [operator instructions]. Outputs: actions to act on environment [rotors rotation speed]. • Modeling in the form of equations to express relations between inputs and outputs: differential equations/transfer functions between IOs. Vivien Maisonneuve From Reals to Floats November 23, 2012 4 / 24

  5. Context The semantic gap Formal aspect model object System definition: • Inputs: sensors [accelerometer, sonar. . . ] + references [operator instructions]. Outputs: actions to act on environment [rotors rotation speed]. • Modeling in the form of equations to express relations between inputs and outputs: differential equations/transfer functions between IOs. System requirements: • Stability conditions [bounded rotation speed]. • Pursuit of reference input [try to reach the ordered position]. • Perturbation rejection [wind]. Vivien Maisonneuve From Reals to Floats November 23, 2012 4 / 24

  6. Context The semantic gap Concrete aspect model object Creation of a real object implementing the system. • Electronic circuit that physically computes the transfer function. • With a microcontroller : a small system with processor, memory, I/O devices, that runs a program implementing the transfer function. [ATMEGA128 Frequency: 16 MHz RAM: 4 KB Prog. mem.: 128 KB] Vivien Maisonneuve From Reals to Floats November 23, 2012 5 / 24

  7. Context The semantic gap Semantic gap model C code µ C code Antagonism: • Abstract, mathematical model. • Microcontroller code: program written in C, then compiled. Long (thousands of LoC), low-level (elementary operations, hardware management, interruptions). Series of transformations to go from abstract model to microcontroller code. Vivien Maisonneuve From Reals to Floats November 23, 2012 6 / 24

  8. Context The semantic gap Semantic gap model C code µ C code Antagonism: • Abstract, mathematical model. • Microcontroller code: program written in C, then compiled. Series of transformations to go from abstract model to microcontroller code. Problem of proof transposition: Considering a model with correction proofs [stability], how to transpose down these proofs at the code level? Interest: formally check the code, not only the model. Difficulties: semantic gap, non-equivalent transformations ( ⇒ proofs must be checked). Vivien Maisonneuve From Reals to Floats November 23, 2012 6 / 24

  9. Context Control-theoretical aspects Control-theoretical aspects model pseudocode C code µ C code Produce a pseudocode from the abstract model: • Solve the model differential equation, get a transfer function. (Laplace transform/Z transform, initial conditions problem.) • If continuous-time model, discretization. (Problems with sampling, execution times.) while transposing the proof. Usual problems in control engineering. Once done, discrete-time system with a loop on the transfer function ⇒ pseudocode [in MATLAB]. Proof: invariants on this code. Vivien Maisonneuve From Reals to Floats November 23, 2012 7 / 24

  10. Context Compilation aspects Compilation aspects model pseudocode C code µ C code At the other end: compilation of C code to machine code. Risks of error: • Important changes in the code: elementary operations, management of registers and of memory stack, instruction jumps. • Possible optimizations. Solutions: • “Existing C compilers are reliable enough.” • Proof-preserving compilation [Barthe]. • Certified compilation [CompCert]. Vivien Maisonneuve From Reals to Floats November 23, 2012 8 / 24

  11. Context C code production What’s between? model pseudocode C code µ C code Opener question. Several challenges: 1 High level mathematical operations � series of elementary instructions [matrices, sinus]. 2 Real values � machine words with limited precision. 3 On a microcontroller, data/events acquisition raises interruptions (real-time answer, energy consumption) ⇒ particular code structure. Vivien Maisonneuve From Reals to Floats November 23, 2012 9 / 24

  12. From real to floats Example of linear invariant system Example system Very simple, open-loop, linear system [Feron]. Pseudocode: Ac = [0.4990, -0.0500; 0.0100, 1.0000]; state matrix (matrice de dynamique) input matrix (matrice de commande) Bc = [1;0]; Cc = [564.48, 0]; output matrix (matrice d’observation) feedthrough matrix (matrice d’action directe) Dc = -1280; � x c 1 � ∈ R 2 : controller state xc = zeros(2,1); x c = x c 2 receive(y,2); receive(yd,3); y ∈ R : reference input; y d ∈ R : real position while 1 yc = max(min(y - yd,1),-1); y c ∈ [ − 1 , 1 ] : bounded gap u ∈ R : action to be performed u = Cc*xc + Dc*yc; xc = Ac*xc + Bc*yc; send , receive : blocking, 2 nd arg. is channel id send(u,1); receive(y,2); receive(yd,3); end Vivien Maisonneuve From Reals to Floats November 23, 2012 10 / 24

  13. From real to floats Example of linear invariant system Lyapunov theory (Lyapunov) stability: all reachable states x c start near an equilibrium point x e and stay in a neighborhood V of x e forever. Lyapunov theory: NSC on V . On linear systems, provided as an equation that can be solved with LMIs, generally as an ellipsoid. � � x c 1 Here, show that x c = belongs to the ellipse: x c 2 � � 0 , 6742 0 , 0428 E P = { x ∈ R 2 | x T · P · x ≤ 1 } , P = 10 − 3 . 0 , 0428 2 , 4651 ⇒ 0 . 6742 x 2 c 1 + 0 . 0856 x c 1 x c 2 + 2 . 4651 x 2 x c ∈ E P ⇐ c 2 ≤ 1000 . 20 10 � 40 � 20 20 40 � 10 � 20 Vivien Maisonneuve From Reals to Floats November 23, 2012 11 / 24

  14. From real to floats Example of linear invariant system Stability proof Proof given as code xc = zeros(2,1); x c ∈ E P invariants. receive(y,2); receive(yd,3); x c ∈ E P Implication (weakening) if while 1 two consecutive invariants. x c ∈ E P yc = max(min(y - yd,1),-1); y 2 Most of them easy to check, x c ∈ E P , c ≤ 1 � µ P � x c � 0 2 × 1 � some depend on theorems. ∈ E Q µ | Q µ = , µ = 0 . 9991 y c 0 1 × 2 1 − µ u = Cc*xc + Dc*yc; Last implication: E ˜ P ⊆ E P � x c � ∈ E Q µ closes the loop. Validity y c xc = Ac*xc + Bc*yc; relies on parameters A c , B c , � T � − 1 P = �� ˜ � · Q − 1 · � x c ∈ E ˜ | A c B c A c B c P µ C c , D c , µ : algebric or send(u,1); x c ∈ E ˜ numerical verification P receive(y,2); needed. x c ∈ E ˜ P receive(yd,3); x c ∈ E ˜ P x c ∈ E P end Vivien Maisonneuve From Reals to Floats November 23, 2012 12 / 24

  15. From real to floats Example of linear invariant system Digression: with C instructions High level mathematical operations � series of scalar elementary instructions. Here, matrix operations are expanded: the instruction � x c � ∈ E Q µ y c xc = Ac*xc + Bc*yc; � T � − 1 P = �� ˜ � · Q − 1 · � x c ∈ E ˜ | A c B c A c B c P µ becomes: � x c � ∈ E Q µ y c xb[0] = xc[0]; xb : buffer xb[1] = xc[1]; xc[0] = Ac[0][0]*xb[0]+Ac[0][1]*xb[1]+yc; xc[1] = Ac[1][0]*xb[0]+Ac[1][1]*xb[1]; ??? Vivien Maisonneuve From Reals to Floats November 23, 2012 13 / 24

  16. From real to floats Example of linear invariant system Digression: with C instructions High level mathematical operations � series of scalar elementary instructions. Here, matrix operations are expanded: the instruction � x c � ∈ E Q µ y c xc = Ac*xc + Bc*yc; � T � − 1 P = �� ˜ � · Q − 1 · � x c ∈ E ˜ | A c B c A c B c P µ becomes: � x c � ∈ E Q µ y c xb[0] = xc[0]; xb : buffer xb[1] = xc[1]; xc[0] = Ac[0][0]*xb[0]+Ac[0][1]*xb[1]+yc; xc[1] = Ac[1][0]*xb[0]+Ac[1][1]*xb[1]; � T � − 1 P = �� ˜ � · Q − 1 · � x c ∈ E ˜ | A c B c A c B c P µ Same computation: output invariant can be found [Feron]. Vivien Maisonneuve From Reals to Floats November 23, 2012 13 / 24

  17. From real to floats Numerical precision problems Numerical precision problems To produce C code: real numbers � binary finite-length machine words (32 b. or 64 b.). ⇒ Loss in accuracy, two consequences: 1 Constant values are slightly altered. 2 Rounding errors during computations. Vivien Maisonneuve From Reals to Floats November 23, 2012 14 / 24

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend