Functional Languages Meet Vision in addition to Robotics: FRP in Action Gregory D. Hager De

Functional Languages Meet Vision in addition to Robotics: FRP in Action Gregory D. Hager De

This Particular University is Related to this Particular Journal

Functions in addition to Types All of these examples are written in Haskell – a functional language. But Haskell isnt essential to our methodology. Parens not needed as long as function application: f x y Polymorphic types are an essential part of the system: f :: Integer -> Float -> Bool f is a function with two arguments, Integer in addition to Float, in addition to returning Bool Types may have parameters: g :: SF Integer Bool SF is a type with two arguments Type variables represent dependencies among parameters h :: a -> SF a a h is a function from a value of any type (a) to a value of type SF a a, where the as in the output must be the same type as the input FROB Basics Dynamics (time variation) is fundamental to interaction: s f d FROB Basics Dynamics (time variation) is fundamental to interaction: d

FROB Basics Dynamics (time variation) is fundamental to interaction: d FROB Basics Dynamics (time variation) is fundamental to interaction: d FROB Basics Dynamics (time variation) is fundamental to interaction: d

FROB Basics Dynamics (time variation) is fundamental to interaction: d Signal Functions Components are encapsulated as signal functions. Input Signals Output Signals Integer Float Integer Float Bool Signal Functions Components are encapsulated as signal functions. Input Signals Output Signals Integer Float Integer Float Bool Type signature as long as this component: f :: SF (Integer, Float, Integer) (Float, Bool)

Signal Functions Components are encapsulated as signal functions. Integer Float Integer Float Bool Type signature as long as this component: f :: SF (Integer, Float, Integer) (Float, Bool) f = proc (i, f, j) -> (g,b) where i f j g b Names as long as input in addition to output signals Signal Functions Components are encapsulated as signal functions. Integer Float Integer Float Bool Type signature as long as this component: f :: SF (Integer, Float, Integer) (Float, Bool) f = proc (i, f, j) -> (g,b) where b = i > j i f j g b Pointwise computations on instantaneous values > Signal Functions Components are encapsulated as signal functions. c2 c1 Integer Float Integer Float Bool Type signature as long as this component: f :: SF (Integer, Float, Integer) (Float, Bool) f = proc (i, f, j) -> (g,b) where b = i > j o1 <- c1 <- i1 o2 <- c2 <- i2 i f j g b Subcomponents i1 i2 o1 o2 Signal Functions c2 c1 Integer Float Integer Float Bool f = proc (i, f, j) -> (g,b) where b = i > j o1 <- c1 <- i1 o2 <- c2 <- i2 g = o1+o2 i1 = f i2 = f i f j g b i1 i2 o1 o2 Full definition of a signal function A FROB Wall Follower wallFollow :: Distance -> SF (Velocity, Distance, Distance) (Velocity, RotVel) wallFollow d-star = proc (v-curr, f, s) -> (v, omega) where v = limit v-max (f – d-star) s-dot <- derivative <- s omega = rerror - s-dot rerror = limit (v-curr sin theta-max) (d-star - s) Events An event is a signal that occurs only at some times. Events carry a value; we write Event a as the type of an event carrying type a. A signal function that uses an event has a type such as f :: SF (Event a) a Here f reads a signal of events carrying type a in addition to produces a continuous output also of type a Functions on events: .. :: Event a -> Event a -> Event a Merging of event streams tag :: Event a -> b -> Event b Changing the value of an event edge :: SF Bool (Event ()) Watch as long as an edge in a boolean signal. () = void.

Basic Signal Functions integral :: Fractional a => SF a a t t hold :: a -> SF (Event a) a t t hold 3 5 1 5 3 1 Switching Switching allows the network of components to be dynamically altered. until :: SF a b -> SF a (Event (SF a b)) -> SF a b Initial component Switching event defines a new component Overall circuit has type SF a b There are many different ways to do switching; AFRP contains a number of different switching constructs. But We Need More Turn Left No Wall Wall left Wall Follow Left Turn Right Blocked Free

But We Need More Turn Left No Wall Wall left Wall Follow Left Turn Right Blocked Free But We Need More Turn Left No Wall Wall left Wall Follow Left Turn Right Blocked Free But We Need More Turn Left No Wall Wall left Wall Follow Left Turn Right Blocked Free