FRP for Real Paul Hudak Yale University Department of Computer Science April 2001 Joint work with: Zhanyong Wan Walid Taha.

Slides:



Advertisements
Similar presentations
ECE 495: Integrated System Design I
Advertisements

Reliable Scripting Using Push Logic Push Logic David Greaves, Daniel Gordon University of Cambridge Computer Laboratory Reliable Scripting.
The need for AMS assertions Verify the analog/digital interfaces at block and SoC levels –Check properties involving voltages and currents –Check complex.
Lecture 8: Three-Level Architectures CS 344R: Robotics Benjamin Kuipers.
1.6 Behavioral Equivalence. 2 Two very important concepts in the study and analysis of programs –Equivalence between programs –Congruence between statements.
Model Checker In-The-Loop Flavio Lerda, Edmund M. Clarke Computer Science Department Jim Kapinski, Bruce H. Krogh Electrical & Computer Engineering MURI.
Functional Reactive Programming Lecture 6, Designing and Using Combinators John Hughes.
ECE 720T5 Fall 2012 Cyber-Physical Systems Rodolfo Pellizzoni.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
A Robotic Wheelchair for Crowded Public Environments Choi Jung-Yi EE887 Special Topics in Robotics Paper Review E. Prassler, J. Scholz, and.
Sept 4, 2001ICFP, Florence, Italy 1 Real-Time FRP Zhanyong Wan Yale University Department of Computer Science Joint work with: Walid Taha Paul Hudak.
Chapter 13 Embedded Systems
REAL-TIME SOFTWARE SYSTEMS DEVELOPMENT Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
Little Languages for Big Applications Paul Hudak Department of Computer Science Yale University Copyright © 2001, Paul Hudak, All rights reserved. Indiana.
7th Biennial Ptolemy Miniconference Berkeley, CA February 13, 2007 PTIDES: A Programming Model for Time- Synchronized Distributed Real-time Systems Yang.
November 18, 2004 Embedded System Design Flow Arkadeb Ghosal Alessandro Pinto Daniele Gasperini Alberto Sangiovanni-Vincentelli
Describing Syntax and Semantics
1 Chapter 13 Embedded Systems Embedded Systems Characteristics of Embedded Operating Systems.
Models of Computation Reading Assignment: L. Lavagno, A.S. Vincentelli and E. Sentovich, “Models of computation for Embedded System Design”
EMBEDDED SOFTWARE Team victorious Team Victorious.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 11 Slide 1 Architectural Design.
 Scheduling  Linux Scheduling  Linux Scheduling Policy  Classification Of Processes In Linux  Linux Scheduling Classes  Process States In Linux.
REAL-TIME SOFTWARE SYSTEMS DEVELOPMENT Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
ECE 720T5 Winter 2014 Cyber-Physical Systems Rodolfo Pellizzoni.
9/14/2015CS225B Kurt Konolige Locomotion of Wheeled Robots 3 wheels are sufficient and guarantee stability Differential drive (TurtleBot) Car drive (Ackerman.
Domain-Specific Languages: Challenges and Opportunities Zhanyong Wan Yale University.
Ruslan Masinjila Aida Militaru.  Nature of the Problem  Our Solution: The Roaming Security Robot  Functionalities  General System View  System Design.
Dynamic Choreographies Safe Runtime Updates of Distributed Applications Ivan Lanese Computer Science Department University of Bologna/INRIA Italy Joint.
Richard Patrick Samples Ph.D. Student, ECE Department 1.
Ranga Rodrigo. The purpose of software engineering is to find ways of building quality software.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Building Tools by Model Transformations in Eclipse Oskars Vilitis, Audris Kalnins, Edgars Celms, Elina Kalnina, Agris Sostaks, Janis Barzdins Institute.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
Implementing Codesign in Xilinx Virtex II Pro Betim Çiço, Hergys Rexha Department of Informatics Engineering Faculty of Information Technologies Polytechnic.
Ch. 2. Specification and Modeling 2.1 Requirements Describe requirements and approaches for specifying and modeling embedded systems. Specification for.
Boundary Assertion in Behavior-Based Robotics Stephen Cohorn - Dept. of Math, Physics & Engineering, Tarleton State University Mentor: Dr. Mircea Agapie.
REAL-TIME SOFTWARE SYSTEMS DEVELOPMENT Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
1 Distributed and Optimal Motion Planning for Multiple Mobile Robots Yi Guo and Lynne Parker Center for Engineering Science Advanced Research Computer.
Smart Sensor Node Impact  GPS leveraged for geo-referenced identity, and low power communications synchronization. Up to 100x communications power reduction.
University of Windsor School of Computer Science Topics in Artificial Intelligence Fall 2008 Sept 11, 2008.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Simultaneously Learning and Filtering Juan F. Mancilla-Caceres CS498EA - Fall 2011 Some slides from Connecting Learning and Logic, Eyal Amir 2006.
yG7s#t=15 yG7s#t=15.
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
CS4730 Real-Time Systems and Modeling Fall 2010 José M. Garrido Department of Computer Science & Information Systems Kennesaw State University.
Abstract A Structured Approach for Modular Design: A Plug and Play Middleware for Sensory Modules, Actuation Platforms, Task Descriptions and Implementations.
Verification & Validation By: Amir Masoud Gharehbaghi
City College of New York 1 John (Jizhong) Xiao Department of Electrical Engineering City College of New York Mobile Robot Control G3300:
Embedded Programming B. Furman 09MAY2011. Learning Objectives Distinguish between procedural programming and embedded programming Explain the Events and.
November 2013 Functional Reactive Programming Simplifying Interaction John Peterson Western State Colorado University Gunnison, CO.
10/23/2001Yale University1 Event-driven FRP Zhanyong Wan Joint work with Walid Taha and Paul Hudak Advisor: Paul Hudak O fficial G raduate S tudent T alk.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
From Use Cases to Implementation 1. Structural and Behavioral Aspects of Collaborations  Two aspects of Collaborations Structural – specifies the static.
Controller Synthesis For Timed Automata Authors : Eugene Asarin, Oded Maler, Amir Pnueli and Joseph Sifakis Yean-Ru Chen Embedded System Laboratory of.
Probabilistic Robotics Introduction. SA-1 2 Introduction  Robotics is the science of perceiving and manipulating the physical world through computer-controlled.
From Use Cases to Implementation 1. Mapping Requirements Directly to Design and Code  For many, if not most, of our requirements it is relatively easy.
Kalman Filter and Data Streaming Presented By :- Ankur Jain Department of Computer Science 7/21/03.
Simulations of Curve Tracking using Curvature Based Control Laws Graduate Student: Robert Sizemore Undergraduate Students: Marquet Barnes,Trevor Gilmore,
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
Finite State Machines ENGR 110 #7 2016
Automation as the Subject of Mechanical Engineer’s interest
Timing Model Start Simulation Delay Update Signals Execute Processes
Locomotion of Wheeled Robots
Autonomous Cyber-Physical Systems: Dynamical Systems
Threads and Memory Models Hal Perkins Autumn 2009
Software testing and configuration : Embedded software testing
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
Chapter 4 . Trajectory planning and Inverse kinematics
Presentation transcript:

FRP for Real Paul Hudak Yale University Department of Computer Science April 2001 Joint work with: Zhanyong Wan Walid Taha

FRP  Fran is a DSL for graphics and animation.  Frob is a DSL for robotics.  FranTk is a DSL for graphical user interfaces.  FRP (functional reactive programming) is the essence of Fran, Frob, and FranTk: Fran = FRP + graphics engine + library Frob = FRP + robot controller + library FranTk = FRP + Tk substrate + library  FRP has two key abstractions: Continuous time-varying behaviors. Discrete streams of events.

Domain-Specific Languages Functional Programming FRP Functions, types, etc. (Haskell) Continuous behaviors and discrete reactivity Specialized languages Fran FVision Graphics, Robotics, GUIs, VisionApplications FranTk Frob

Behaviors  Continuous behaviors capture any time-varying quantity, whether: input (sonar, temperature, video, etc.), output (actuator voltage, velocity vector, etc.), or intermediate values internal to a program.  Operations on behaviors include: Generic operations such as arithmetic, integration, differentiation, and time-transformation. Domain-specific operations such as edge-detection and filtering for vision, scaling and rotation for animation and graphics, etc.

Events  Discrete event streams include user input as well as domain-specific sensors, asynchronous messages, interrupts, etc.  They also include tests for dynamic constraints on behaviors (temperature too high, level too low, etc.)  Operations on event streams include: Mapping, filtering, reduction, etc. Reactive behavior modification (next slide).

Reactive Control of Continuous Values One animation example that demonstrates key aspects of FRP: growFlower = stretch size flower where size = 1 + integral bSign bSign = 0 `until` (lbp ==> -1 `until` lbr ==> bSign).|. (rbp ==> 1 `until` rbr ==> bSign)

Frob  Recall that: Frob = FRP + robot controller + robot/vision library  Programming robots is a lot like programming an animation!  … except that: The robot doesn’t always do what you want it to do. Error / anomalous conditions are more common. Real-time issues are more dominant. Sensor input is critically important, but unreliable. Robots have different response characteristics: Often must react more quickly. Often are slower than graphics hardware.

Robots with Vision

(our old robots) Nomadic Technologies SuperScout Computing: PC running Linux Hugs Radio Modem Vision 16 Sonars Bumpers Wheel Controls

Autonomous Coordinated Motion  Natural behavior amongst living animals: flocking, herding, schooling, swarming  Specific tasks of interest to us: congregation, navigation, “escortation”, formation motion, obstacle avoidance, dispersion, etc.  Key technologies of interest: computational vision and control FRP

Example of Coordinated Motion  Problem: Specify local control strategy for two differential-drive robots in interleaving trajectories, where each robot only knows the relative position of the other.  Can be achieved by two-step simplification: Non-holonomic constraint on differential-drive robot is eliminated by considering a moving frame of reference. Relative to that frame, each robot exhibits identical behavior: simply circle the other robot.  Frob permits abstract formulation of solution. Two independent critically-damped PI controllers. Local motion assumes holonomic vehicle; i.e. differential drive robot can be treated as omni-directional robot.

Local Behavior desired distance desired rotation vFrame vLat vRot moving frame of reference

Code Snippet interleaveC dist omega0 vFrame = let … distError = distOther - dist vLat = vector2Polar (kpDist * distError + kiDist * integralB distError) angOther vRot = vector2Polar (omega0*distOther/2) (angOther - pi/2) in velocityV (vFrame + vLat + vRot)

History of FRP Research  TBag, Active VRML: Conal Elliott, ’  Fran: Elliott & Hudak, ICFP ’97.  Various implementations: Eliiott, DSL ’97, PLILP ’99.  Semantics: Anthony Daniels, PhD Thesis ‘99.  Frob: Peterson, Hager, Hudak, Elliott, ICRA ‘99, PADL ’99. Used in robotics course at Yale in ‘99, ‘01.  Fvision: Peterson, Hager, Hudak, Reid, ICSE ’99, PADL ’01.  SOE’s “FAL”: Hudak, stream-based implementation of Fran-like language, ’00.  FranTk: Fran-based GUI, Meurig Sage, ICFP ’00.  Frappé: Java-based FRP, Antony Courtney, PADL ’01.  Yale FRP: core language + growing library of graphics, robotics, simulator, etc. code, ’00-01 (public release planned soon).  Semantics: Wan, Hudak, PLDI ’00, showed correspondence of denotational and operational semantics.

Real-Time FRP  How do we make FRP run fast?  How do we make guarantees about both time and space behavior?  How does FRP relate to other models of hybrid automata?  Can FRP be used for embedded systems?  And at a more abstract level: What is an operational semantics for FRP? Our goal: Real-Time FRP, an abstract, restricted subset of FRP, with guaranteed bounds on execution time and space, and deadlock free.

Syntax of RT-FRP  Syntax of lambda terms: (“lifted” terms are just “Maybe” type)  Syntax of values:  Syntax of signals: Note: “Event a” in FRP is isomorphic to “Behavior (Maybe a)”. In RT-FRP we just combine them and call them “signals”.

Types  Syntax of types:  Contexts:  Judgments: “e is a functional term of type g” “s is a signal carrying values of type g” Or in Haskell: e :: g, and s :: Behavior g

Some Typing Rules

More typing rules  Reactivity:  Non-recursive binding:  Recursive binding:

 Note: let signal x = s in ext x == s

Recursion  There are two “prototypical” kinds of recursion in FRP: (1) (2)  Using recursive signals these can be expressed as: (1) (2)

But what about integral?  Define using a delay in a recursive signal.  By way of example, here is the running maximum of a signal:

Definition of Integral … using the forward Euler method:

From FRP to RT-FRP

and more…

Operational Semantics  A program is executed in discrete steps, driven by time-stamped input values.  Given a time t and input i, a term s evaluates to a value v and transitions to a new term s ’.  We write this as: and or, more compactly as: where:

Program Execution  A proper RT-FRP program never terminates. Its meaning is the infinite sequence of values, or “observations” that it yields.  The sequence: s 0  s 1,v 1 ; s 1  s 2,v 2 ; s 2  s 3,v 3 ; … is abbreviated: s 0  v 1, s 1  v 2, s 2  v 3, s 3 …  Meta-comment: Program meaning depends on the time-stamped input pairs (t j,i j ). t 0,i 0 t 2,i 2 t 1,i 1 t 0,i 0 t 1,i 1 t 2,i 2

Some Eval Rules

More Eval Rules (ev-signal)

Some Transition Rules

More Transition Rules

and more… (tr-switch-occ) (tr-switch-noc)

Tail Signals  Recursive signals are nice, but we’d like something better:  With let-continuation, we can define tail-recursive signals that can also pass values.  Similar to standard model of hybrid automata.  Note: the syntax prevents unbounded term growth as in: letcont k x = s0 until x=ev then k x + 1 not possible

For Example  A simple model of a thermostat: let signal temp = let cont k1 () = until when (temp>t) => k2 k2 () = until when (temp k1 in t0 until startev => k1 in ext temp

Key Results Type safety / preservation thus no core dumps! Each step takes constant time thus no time leaks! Term size cannot grow thus no space leaks! In addition, with a notion of well-formed recursion, progress is guaranteed. thus no deadlock!

Preventing Deadlock  FRP programs are naturally “infinite” – signals are streams of values with unbounded extent. This is a good thing!  With recursion, however, terms can become “stuck”: let signal x = ext x in ext x  Solution: define notion of well-formed recursion that disallows “direct” recursions, and thus prevents deadlock.  Key idea: in “let signal x = s1 in s2”, we require that s1 is in W {x}, where: W x = input | time | ext e where e contains no X | delay v s | let signal y = W x in W x | W x switch on x = ev in W x | …  In other words, a delay must appear somewhere.

Future Work on RT-FRP  Enrich language for practical use.  Compile into lower-level code (C, etc.).  Examine sensor / behavior fusion.  Consider embedded systems.  Better formulation of well-formed recursion.  Test case: compile to PIC microcontroller on our “soccer-bots”.

How to Hide a Flock of Turkeys