FUNC: FRP for Control Applications

David Snowdon


Functional Reactive Programming (FRP) was developed for use in Functional Reactive ANimation (FRAN). Functional Robotics (FROB) was developed as a Domain Specific Language (DSL) to demonstrate the use of declarative languages in robotics. As such, it is an interesting venture from the traditional applications of functional programming languages to that of embedded systems, which is traditionally dominated by second and third generation programming environments.


It is proposed that either FROB be modified or FRP extended in order to generalise to more traditional control systems.

Advantages of functionally programmed control systems should be investigated and could include:

Motivating Problem

The UNSW solar powered car has, for a number of years, relied on a human driver for control of speed. While this is undoubtedly the simplest possible solution, a "Cruise control" system is desireable for the a number of reasons: It is suggested that the above problem form a platform for the investigation of functional control systems.

The control problem very closely resembles the problems encountered within the robotics domain, and could, in fact, be considered a subset of such. Both applications are likely to have similar processing constraints, and have similar sensors, effectors and transducers. This makes (a slightly modified) FROB very suitable for implementing control systems.

This project will investigate the implementation of an EDSL for control systems to be used in the Sunswift II solar powered car.

Project Outline

Core Goal 1: Port NHC98 to PLEB

The NHC98 Haskell compiler should be ported to PLEB to provide a foundation on which to develop. This should be a relatively trivial task, since NHC98 is capable of generating ANSI compatible C code as its object, which can then be compiled using GCC for the StrongARM (as PLEB would require). This port must support the Foreign Function Interfaces such that the programs can be interfaced to the PLEB's functions (including hardware drivers).

Core Goal 2: Develop a set of Foreign Function Interfaces (FFI)

In order to become a physical controller, Haskell programs need some method of communicating with that physical layer. This is extremely difficult using Haskell alone, is made possible using the FFI extensions to Haskell 98. Thus the C routines interact with the hardware, and throught the FFI, Haskell programs call the C.

So, a set of interfaces from Haskell to the proposed PLEB/Sunswift hardware should be developed. Initially the implementation of these routines will result in simulation of the solar car. These "simulation" routines/stubs will be replaced with an interface to the physical motor controller following the development of the overlying control framework. These interfaces will be to the basic hardware, any "wrapping" that is required should be written in the lower levels of the functional program.

Example data structure:

These data are given with the foreign function definitions in mind. They will be sufficient for the initial applications, but will be expanded for any comprehensive control solution. Functions to set outgoing values, and read incoming values will form the FFIs.

Core Goal 3: Develop a control framework

Using FROB as a basis, develop a generic framework for control applications. FROB is inherently suitable for use as a control EDSL. Functional reactive programming, and the use of continuous time behaviours in particular, allows very neat expression of classic control equations.

Any modifications such that FROB can run on NHC98 (rather than HUGS) should be made. Robot-specific code should be removed and replaced with a generic control framework (For example, references to the "Robot" state should be removed).

An adaption should be made such that the new framework can operate over the the Sunswift FFIs, and any wrapper code necessary to adapt the function of the sensors and actuators present to the format required by the framework should be written.

The definition of the DSL will be extremely similar to that of FROB and so is omitted here.

An assessment of the adaptability to new control systems should be made via modification of the lower level interfaces to include driver controls and network derived information (such as GPS information and array power).

A demonstration application should be developed using the above framework and mentioned lower level interfaces/simulation. This will be a speed control loop running on the car's speed, and controlling the motor setpoint.

Bonus Goal 1: Investigate real time properties of Haskell and the control framework

Haskell would seem not well suited to real time tasks due to garbage collection, etc. There is, however an RT-FRP development.

The properties of control systems should be developed and the necessity of real-time control should be investigated with respect to the developed framework.

Bonus Goal 2: Implement a simple control system on real hardware

The hardware specified above is owned by the UNSW solar racing team. Motor, motor controller, current controlled power supply, and PLEB are all available for use in the development of this application.

A simple control loop should be actualised. This would be in two forms: a speed control loop and a power control loop (both of which are invaluable to a solar car team for different strategic purposes).

Bonus Goal 3: Investigate and implement intelligent control systems for Sunswift II

Following the implementation of a simple control loop as outlined above, a complete control solution could be arrived at, taking into account driver inputs, the verification of the validity of those inputs (for example, ramp-rate control) and the appropriate use of cruise control could be investigated.

Furthermore, a second control loop could be run outside either the power or speed control loops to make intelligent strategic decisions. This would be implemented in the FRP framework via the use of behaviours as the setpoints. This would be an extremely neat solution to the problem. Solar car strategy is essentially a reasoning problem, and therefore highly suited to declarative languages.


A very large project has been described in the above goals. It is unlikely that the bonus parts will be possible within the nine weeks available, but are outlined as future work if nothing else.

A real world application of functional programming languages will be investigated and implemented.


Model-Relative Control of Autonomous Vehicles
Reactive Switching Strategies for the Control of Uninhabited Air Vehicles
Functional Reactive Animation
Functional Robotics: FROB