context-oriented adaptation in cyber-physical systems mikhail afanasov*, luca mottola*† and carlo...

23
Context-Oriented Adaptation in Cyber- Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish ICT

Upload: lawrence-curtis

Post on 22-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Context-Oriented Adaptation in Cyber-Physical Systems

Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi**Politecnico di Milano (Italy), †SICS Swedish ICT

Page 2: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

CPS Platforms

Page 3: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Problem

• CPSs are intimately tied to the real world– Multiple environment dimensions at hand– Continuously changing environment

• The software must adapt • Missing design and

programming support

Page 4: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Example: Wildlife Tracking

Page 5: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Problemmodule ReportLogs{ uses interface Collection; uses interface DataStore;} implementation {

int base_station_reachable = 0;

event msg_t Beacon.receive(msg_t msg) { if (!acceleromenter_detects_activity()) return; if (call Battery.energy() <= THRESHOLD) return; base_station_reachable = 1; call GPS.stop() call BaseStationReset.stop(); call BaseStationReset.startOneShot(TIMEOUT); }

event void BaseStationReset.fired() { base_station_reachable = 0; }

event void ReportPeriod.fired() { switch (base_station_reachable){ case 0: call DataStore.deposit(msg); case 1: call Collection.send(msg);} } }

Page 6: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Solution

• Context• Context-Oriented Programming (COP)• Language-independent design concepts • Programming support

Page 7: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Solution

context Unreachable { uses interface DataStore; } implementation { layered command void report(msg_t msg){ call DataStore.deposit(msg);}}

context group BaseStationG { layered command void report(msg_t msg); } implementation { contexts Reachable, Unreachable is default, MyErrorC is error; components Routing, Logging; Reachable.Collection -> Routing;Unreachable.DataStore -> Logging;}

context Reachable { uses interface Collection; } implementation { layered command void report(msg_t msg){ call Collection.send(msg);}}

Functionality are decoupled;

implementations are individually simpler

Page 8: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Context-oriented Programming

• Layered functions change the behavior depending on the context

Page 9: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Context-oriented Programming

Java PythonErlang

Lisp

Objective-C

• Layered functions change the behavior depending on the context

Page 10: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Design Concepts• Context represents a single environmental

situation• Context group as collection of environmental

situations sharing the same characteristics

Context group

Context Context

Page 11: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Patterns: Behavior control

Provides a context-dependent functionality

send(Msg* msg)

Page 12: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Grevecom

https://github.com/muxanasov/Grevecom

Page 13: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Grevecom: Model Verification

Editor

Source-code

Translator

Binary

Model

Model-checker

Page 14: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Verification: Initial Model

• Simple transition: S0={…, …, …, i, …} -> S1={…, …, …, j, …}• Dependency: S0={…, n, … , i, …} -> S1={…, n, … , j, …}

Page 15: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Grevecom: Source-Code Generation

Editor

Source-code

Translator

Binary

Model

Model-checker

Page 16: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

ConesC

• Context-Oriented extension of nesC• Enable layered functions (commands) in nesC• Redefine component and configuration

Core features:• Define context group• Layered function• Implementation variations in contexts

https://github.com/muxanasov/ConesC

Page 17: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Evaluation: Coupling

W. Stevens et al. Classics in software engineering. Chapter Structured Design. 1979.

Easier to maintain

Strongest Weakest

Page 18: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Evaluation: Complexity

Easier to understand

Page 19: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Evaluation: Run-time OverheadMCU Overhead

Memory Overhead

Turning an LED on is 8 MCU cycles Max 2.5%!

Negligible Overhead

Page 20: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Conclusions and Ongoing Work

• Context as a CPS programming concept:– Language independent design– Programming support: ConesC, IDE, Model-checker

• Key results:– Easier to maintain and to understand– Verification against environment evolutions– Negligible performance overhead

• Current work:– Extending on micro & nano aerial drones

Page 21: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Other Activities @POLIMI

• Programming Systems for Coordinating Drones• Example:– L. Mottola et al. “Team-level

programming of drone sensor networks”, in ACM SENSYS 2014

– Real-deployment for aerial photogrammetry in archaeological sites (Aquileia, Italy)

– Currently being extended to indoor scenarios for tiny devices

“Domus dei putti

danzanti”

youtu.be/PPDGO-jc0It

Page 22: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Other Activities @POLIMI

• Integration and remote control– Mission-level

service-oriented interfaces (REST)

– Remote-control service oriented interfaces (CoAP)

• Flight control loops– Reactive programming techniques– Testing and verification

Page 23: Context-Oriented Adaptation in Cyber-Physical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish

Questions?