Declarative Programming for Modular Robots AshleyRollman De Rosa
Declarative Programming for Modular Robots Ashley-Rollman, De Rosa, Srinivasa, Pillai, Goldstein, Campbell November 2, 2007
Locally Distributed Predicates (LDP) & Meld • Two very different approaches to declarative programming for modular robots – Meld - logic programming – LDP - distributed pattern matching • Both achieve higher goals – Dramatically shorter code – Automatically distributed – Automatic messaging 2 11/2/2007 Declarative Programming for Modular Robots
LDP Overview • Originated in Distributed Watchpoint system – Needed to describe and detect incorrect distributed state configurations • Locally Distributed Predicates – Locally Distributed: involving a bounded number of connected modules – Predicates: boolean expressions over state, temporal, and topological variables • An LDP program consists of a number of predicates, each with one or more attached actions – Every predicate/action pair is executed in parallel 3 11/2/2007 Declarative Programming for Modular Robots
Meld Overview • Logic programming language – Inspired by P 2 [Loo et. al. 2005] – Consists of facts and rules for deriving new facts • • • 4 When a fact changes, derived facts are automatically deleted Programs typically consider local neighborhoods Additional support for making non-local neighborhoods 11/2/2007 Declarative Programming for Modular Robots
LDP and Meld: A Comparison LDP Meld Predicate Matching Proof Search Concise Code (vs. C++/Java) Automatic Messaging count forall Approach Operations over all neighbors Quantified (Variably-Sized) Expressions Automatic Fact Retraction State Management 5 11/2/2007 Declarative Programming for Modular Robots By Programmer By System
Example: 3 D Shape Change Algorithm • <20 lines of Meld or LDP • Connectivity maintenance guaranteed by algorithm 6 11/2/2007 Declarative Programming for Modular Robots
Example 1: Setting Module State type state(module, min int). forall (a) state(A, FINAL) : - where (a. is. Seed) is. Seed(A). do a. state = FINAL; state(B, FINAL) : - forall (a, b) neighbor(A, B), where (a. state = FINAL) & (b. inside) do b. state = FINAL; state(A, FINAL), LDP • • If the module is the seed • • • For every module inside the target shape 7 Set the seed’s state to FINAL If it is next to a module in FINAL state Set the module’s state to FINAL 11/2/2007 Declarative Programming for Modular Robots Meld in(B).
LDP and Meld: A Comparison LDP Meld Predicate Matching Proof Search Concise Code (vs. C++/Java) Automatic Messaging count forall Approach Operations over all neighbors Quantified (Variably-Sized) Expressions Automatic Fact Retraction State Management 8 11/2/2007 Declarative Programming for Modular Robots By Programmer By System
Example 2: Evaluation Over all Neighbors forall(a, b) type deletable(module). where (b. parent != a. id) type not. Child(module, module). do a. $not. Child. add(b. id); not. Child(A, B) : - forall(a) neighbor(A, B), where size(a. $not. Child) parent(B, C), = size(a. $neighbors) A != C. deletable(A) : - do a. delete(); forall neighbor(A, B) LDP • • • 9 Meld not. Child(A, B). A module can only be deleted if none of its neighbors are children We first determine which neighbors are not children If there are no children, the module can be deleted 11/2/2007 Declarative Programming for Modular Robots
LDP and Meld: A Comparison LDP Meld Predicate Matching Proof Search Concise Code (vs. C++/Java) Automatic Messaging count forall Approach Operations over all neighbors Quantified (Variably-Sized) Expressions Automatic Fact Retraction State Management 10 11/2/2007 Declarative Programming for Modular Robots By Programmer By System
Example 3: Self-deleting Gradients 11 11/2/2007 Declarative Programming for Modular Robots
Example 3: Self-deleting Gradients forall (a, b) where (a. value > b. value) type gradient (module, min int). do a. value = b. value + 1; gradient(A, N) : - neighbor(A, B), forall (a, b[0, 6]) where gradient(B, M), count(a. value > b[i]. value) = 0 & N = M + 1. a. value != 0 do a. value = INF; • • • LDP Meld deletes all dependent facts when the root fact is deleted LDP directly manipulates state variables, so retraction must be manual LDP must specify the maximum number of neighbors 12 11/2/2007 Declarative Programming for Modular Robots
LDP and Meld: A Comparison LDP Meld Predicate Matching Proof Search Concise Code (vs. C++/Java) Automatic Messaging count forall Approach Operations over all neighbors Quantified (Variably-Sized) Expressions Automatic Fact Retraction State Management 13 11/2/2007 Declarative Programming for Modular Robots By Programmer By System
Example 4: Spanning Tree Creation 14 11/2/2007 Declarative Programming for Modular Robots
Example 4: Spanning Tree Creation forall (a) where (a. is. Root = 1) do a. parent = a. id; forall (a, b) where (a. parent != -1) & (b. parent = -1) do b. parent = a. id: type parent(module, first module). parent(A, A) : - root(A). parent(B, A) : - neighbor(B, A), parent(A, _). • Newer versions of Meld use the “first” aggregate to ensure uniqueness • This qualifier is not sufficient for more complex situations 15 11/2/2007 Declarative Programming for Modular Robots
Example 4 b: Spanning Tree Creation forall (a) where (a. is. Root = 1) do a. parent = a. id; forall (a, b) where (a. parent != -1) & (b. parent = -1) do b. parent = a. id: type possible. Parent(module, int). type best. Parent(module, min int). type parent(module, module). parent(A, A) : - root(A). possible. Parent(B, A, T) : - neighbor(A, B), parent(A, _) , T = local. Time. Stamp(). best. Parent(B, T) : - possible. Parent(B, _, T). parent(B, A) : - possible. Parent(B, A, T), best. Parent(B, T). • Without “first”, Meld must use timestamps to ensure exactly one unique parent • LDP uses a single state variable, and thus can never have more than one parent 16 11/2/2007 Declarative Programming for Modular Robots
LDP and Meld: A Comparison LDP Meld Predicate Matching Proof Search Concise Code (vs. C++/Java) Automatic Messaging count forall Approach Operations over all neighbors Quantified (Variably-Sized) Expressions Automatic Fact Retraction State Management 17 11/2/2007 Declarative Programming for Modular Robots By Programmer By System
Future Research • Performance enhancements/optimizations • Additional language features – Support transactions • Applicability to other application domains • Explore tradeoffs between automated and manual state control – Find a balance that allows programmers to maintain state while gaining some or all of the benefits of automated state Interested in Meld/LDP? Email [mderosa, mpa]@cs. cmu. edu 18 11/2/2007 Declarative Programming for Modular Robots
- Slides: 18