Presentation is loading. Please wait.

Presentation is loading. Please wait.

TinyOS: Radio, Concurrent Execution, and Power control

Similar presentations


Presentation on theme: "TinyOS: Radio, Concurrent Execution, and Power control"— Presentation transcript:

1 TinyOS: Radio, Concurrent Execution, and Power control
Class 7

2 Announcements Please email TA with group members
It is necessary to distribute sensors to the groups Phase 1 for your group projects due on October 12 th. Requirements posted on the course webpage

3 Agenda Review Quiz Radio module of TinyOS: Zigbee and Bluetooth
Implement a three bit counter Radio module of TinyOS: Zigbee and Bluetooth Concurrent execution: tasks and events Power management Communication scheduling

4 Implementing a Radio in TinyOS
Different interfaces for Zigbee and bluetooth In Zigbee – packet formation, radio buffer management has to be done by the user More flexibility of design In Bluetooth – The HPL abstraction for bluetooth abstracts out the packet details Can create an array and send it via radio

5 Zigbee interface #include "RadioSenseToLeds.h"
module RadioSenseToLedsC { uses { interface Receive; interface AMSend; interface Packet; interface SplitControl as RadioControl; } Declare the packet format Interface to Recieve Interface to Send Interface to build the packet Interface to start and stop a radio

6 Packet Format #ifndef RADIO_SENSE_TO_LEDS_H
#define RADIO_SENSE_TO_LEDS_H typedef nx_struct radio_sense_msg { nx_uint16_t error; nx_uint16_t data; } radio_sense_msg_t; enum { AM_RADIO_SENSE_MSG = 7, }; #endif Structure of the packet with two variables Maximum Number of bytes in the packet

7 Send command issues a SendDone event
Implementation implementation { message_t packet; bool locked = FALSE; event void Read.readDone(error_t result, uint16_t data) { if (locked) { return; } else { radio_sense_msg_t* rsm; rsm = (radio_sense_msg_t*)call Packet.getPayload(&packet, NULL); if (call Packet.maxPayloadLength() < sizeof(radio_sense_msg_t)) { rsm->error = result; rsm->data = data; if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(radio_sense_msg_t)) == SUCCESS) { locked = TRUE; TinyOS internal packet format Send command issues a SendDone event To check whether the radio is busy event void AMSend.sendDone(message_t* bufPtr, error_t error) { if (&packet == bufPtr) { locked = FALSE; } Create your own packet Broadcast to everybody

8 Reception of a packet event message_t* Receive.receive(message_t* bufPtr, void* payload, uint8_t len) { call Leds.led1Toggle(); if (len != sizeof(radio_sense_msg_t)) {return bufPtr;} else { radio_sense_msg_t* rsm = (radio_sense_msg_t*)payload; uint16_t val = rsm->data; return bufPtr; } Cast it into your own packet format Use data for computation

9 ZigBEE Wiring configuration RadioSenseToLedsAppC {} implementation {
components ActiveMessageC; components new AMSenderC(AM_RADIO_SENSE_MSG); components new AMReceiverC(AM_RADIO_SENSE_MSG); App.Receive -> AMReceiverC; App.AMSend -> AMSenderC; App.RadioControl -> ActiveMessageC; App.Packet -> AMSenderC; } HPL for the radio Send and Receive components

10 Bluetooth module RadioSenseToLedsC{ uses {
interface Init as BluetoothInit; interface StdControl as BTStdControl; interface Bluetooth; } Initiate bluetooth radio Starting and stopping Sending and recieving event void Boot.booted() { call BluetoothInit.init(); call Bluetooth.resetDefaults(); call Bluetooth.setRadioMode(SLAVE_MODE); call Bluetooth.setName("testUnit"); call BTStdControl.start(); } Master Slave Architecture

11 Bluetooth Send and Recieve
async event void Bluetooth.connectionMade(uint8_t status) { post startSensing(); } call Bluetooth.write(SendArray, 8); async event void Bluetooth.connectionClosed(uint8_t reason){ async event void Bluetooth.dataAvailable(uint8_t data){ event void Bluetooth.writeDone(){ async event void Bluetooth.commandModeEnded() { After bluetooth hand shaking This event is fired Send an array Closing of a bluetooth connection When data is available from The master On completion of a send When master has no more Data to transmit

12 Bluetooth wiring components RovingNetworksC;
AccelECGC.BluetoothInit -> RovingNetworksC.Init; AccelECGC.BTStdControl -> RovingNetworksC.StdControl; AccelECGC.Bluetooth -> RovingNetworksC;

13 Concurrent execution uint16_t Samples[SAMPLES]; Uint16_t i = 0;
event void ReadStream.readDone(error_t ok, uint32_t SensedVal) { if (ok == SUCCESS){ i++; Samples[i] = Val; if(i == SAMPLES-1){ i = 0; post calculateAvg(); } task void calculateAvg() { uint16_t i, avg, var; for (avg = 0, i = 0; i < SAMPLES; i++) avg += Samples[i]; avg /= SAMPLES; for (var = 0, i = 0; i < SAMPLES; i++) { int16_t diff = Samples[i] - avg; var += diff * diff; In readDone, we need to compute the variance of the sample. We defer this “computationally-intensive” operation to a separate task, using post. We then compute the variance

14 Exercise to understand concurrency
Lets have a loop in a task Increment a counter Have a timer fired event where at each fired event we send the counter value to the base station What values do we see at the base station ?

15 Using Low-power Listening
module RadioSenseToLeds... uses interface RadioControl; uses interface LowPowerListening; ... event void RadioControl.startDone(error_t ok) { if (ok == SUCCESS) { call CollectionControl.start(); call LowPowerListening.setLocalDutyCycle(200); } TinyOS supports power control of the Radio What is power management ? Why is it required ? We request that the radio use a 2% duty-cycle low-power listening strategy We wire the interface to the actual radio (not shown)

16 Power Management

17 Sources of Power Dissipation
Sensing + Computation + Communication Often more than computation Least Power consuming Most Power consuming Power consumption depends on the type of processing Sending < Receiving Communication energy more than 100 times greater than computation energy

18 Communication Duty Cycling
Low power listening for Radio Radio turn off Such strategies are however application dependent Cannot turn off radio when the sensor needs to send When an event occurs the radio has to wake up from low power state Example: Ayushman health monitoring application is considered as the workload Sensing Phase – Sensing of physiological values (Plethysmogram signals) from the sensors and storing it in the local memory Transmission Phase – Send the stored data to the base station in a single burst Security Phase – Perform network wide key agreement for secure inter-sensor. The Security phase occurs once in a day The Sensing phase and Transmission phase alternate forming a sleep cycle Sensor CPU Utilization Time Sensing Phase Transmission Phase Security Phase Sleep Cycle Ayushman Workload Enables Sleep Scheduling Frequency Throttling during security phase

19 Effects of Power Management
Periodic sensing and computation application in Ayushman Sender Side: Sensing + FFT + peak detection + quantization + polynomial evaluation + random number (chaff) generation + data transmission + acknowledgement of transmission Receiver Side: Sensing + FFT + peak detection + quantization + listen for packet + interpolation + transmit acknowledgement 1 2 3 4 5 6 7 8 9 0.01 0.02 0.03 0.04 0.05 0.06 Power Profile (Radio-ON) Receiver(Radio ON) Sender(Radio ON) Sensing FFT Peak + Quant Poly Gen + Eval Add Chaff Vault Tx/Rx Lagrangian Interpolation Ackn Tx/Rx 1 2 3 4 5 6 7 8 9 0.01 0.02 0.03 0.04 0.05 0.06 Power (mW) Power Profile (Radio-OFF) Receiver(Radio OFF) Sender(Radio OFF) Ackn Tx/Rx Lagrangian Interpolation Vault Tx/Rx Add Chaff Poly Gen + Eval Peak + Quant FFT Sensing

20 Reduction of data transmission
To further reduce communication power we may avoid data transmission Event based data transmission Example: Physiological data transmission (ECG) When ECG is normal and not changing don’t send samples On any expected change, send only the changed feature When an unexpected change occurs, default to periodic sending of data How to know what is normal ? What are expected changes ? What is an unexpected behavior ?

21 Electrocardiogram (ECG)
Represents electrical activity of the heart Consists of P, Q, R, S, T waves The beat morphology and R-R intervals in an ECG are considered important for diagnosis Visual representation is preferred by physicians

22 Diagnostic Features of ECG
hR R-R interval hQ hS Beat Morphology: Refers to visual appearance of an ECG beat Includes height, width, location and shape of peaks R-R intervals: Heart rate (HR) = 1/(R-R interval) HR varies over time, and is characterized using mean(HR), std(HR) and frequency domain parameter LF/HF ratio. These are called inter-beat features.

23 Normal, Expected and Unexpected
Expected Change Unexpected Change Morphology and inter beat features do not change Only inter beat features change Both morphology and inter beat features change No communication Use a generative model to represent ECG Send inter beat feature updates Send every sample

24 G Generative Models Input Parameters Output signal
Time Output signal Mathematical model to generate data from given input parameters Used in music, machine learning, wireless sensor networks and other areas Input parameters can be trained on given data Used for generating ECG in GeM-REM.

25 ECGSYN Model for ECG Generative model for ECG, proposed by McSharry et al. Each of P, Q, R, S, and T waves are represented by Gaussians Input parameters: Inter-beat: {hrmean, hrstd, lfhfratio} Correspond to mean heart rate, standard deviation of heart rate and LF/HF ratio respectively. Morphology: {aQ, bQ, ƟQ, aR, bR, ƟR, aS, bS, ƟS} ai, bi, Ɵi determine the height, width and location of peak i. Require curve fitting to learn from a given raw ECG. Remove kernels, unit circle, etc. just say the parameters used by the model. Say that a,b,theta are complex to learn When using models exact sample to sample match is not possible We aim for diagnostic equivalence

26 Diagnostically Equivalent ECG
Two ECGs are diagnostically equivalent if: Beat morphologies match Inter-beat features are equal ECG from MIT-BIH database Synthetic ECG waveform from ECGSYN

27 Base Station Module MBS
GeM-REM: Initialization Sensor Platform Mobile phone gateway ECG Leads G Model Learner Base Station Module MBS Sensor Module MLITE G Sensed ECG Base Station Architecture: Sensor module (MLITE) and Base station module (MBS) Initialization: Train G using Model Learner function in MBS Use patient’s real ECG as training data Store trained G in MBS and MLITE

28 GeM-REM: Regular Operation
Raw signal updates Feature updates MLITE G Sensed ECG Compare Match? G MBS Raw ECG samples Align Output ECG Two types of updates: Feature update: Single parameter value corresponding to feature of sensed ECG Raw Signal update: Samples of sensed ECG signal Sensor compares sensed ECG to output of G If (Signals match within threshold) Store signal in terms of model parameters Else Send updates to base station Switch to FU on top and RSU at the bottom .. All subsequent slides.

29 Sensor Module MLITE Sensed ECG Pre- process Inter-beat feature comparison Diff > threshold Transmit value Generated ECG G Direct signal comparison MSE > threshold Transmit raw data Pre-processing includes filtering, scaling and peak detection Morphology compared through mean squared error (MSE) between sensed and model-generated ECG Threshold values set by physician a priori or during regular operation

30 Base Station Module MBS
Raw signal updates Feature updates Raw signal updates Feature updates Model Learner MLITE G Sensed ECG Compare Match? G Temporal alignment G MBS Raw ECG samples Align Output ECG Model-generated ECG Raw ECG samples Final Output Feature updates used to update inputs of G Raw signal updates used as true ECG of patient Signals aligned using timestamps Raw signal used to re-train G. Overwrite the synthesized with raw BECAUSE RAW HAS NEW INFORMATION

31 Experimental Results Evaluation Criteria: Data: Implementation:
Feasibility of GeM-REM: TelosB, SHIMMER Diagnostic Accuracy of reported ECG Energy and memory savings Data: MIT-BIH database 30 patients’ data, sampled at 250 Hz Implementation: MLITE in TinyOS, MBS in MATLAB

32 Performance of GeM-REM
Compression Ratio: Performance vs. thresholds Comparison to state of the art Memory savings of 37.3:1 Criticial event detection Detected within 5 sec. through morphology comparison. Threshold Values CR Feature Error (hrmean, hrstd, lfhfratio) Morphology (MSE) MAX (%) MEAN (3,2,4) (MEDIUM) 0.07 (MEDIUM) 42.1:1 6.92 4.03 (2,1,3) (TIGHT) 40.1:1 6.32 3.24 (10,5,6) (LOOSE) 0.01 (TIGHT) 1.2:1 0.5 0.1 0.2 (LOOSE) 7892:1 14.3 8.64 Scheme/Algorithm Compression Ratio Wavelet and Huffman [2] 9.4 : 1 AZTEC [2] 10 : 1 DCT & arithmetic [2] 14.73 : 1 SPITH [3] 21.4 : 1 DWLT & MSVQ [3] 29.3 : 1 GeM-REM 42.1 : 1 Where did we get these numbers? Morphology -> Raw Signal Updates. Hrmean, etc. -> Feature updates. FU has less impact on CR. Morphology will not change much -> low RSUs. But when it does change, we want to capture it. Keep table and bring up the memory point. Threshold-based comparison first, then compare to other people. Look at the dataset of other people. Feature Updates Raw Signal Updates (Results for all schemes are based on data from MIT-BIH database)

33 Demo Video

34 Lessons Learned Communication more expensive than computation
Communication duty cycling is an useful tool Application dependent duty cycling Event based communication enables lot of energy savings Can only be applied to cases where the sensed signal has a definite pattern Next Class – Energy savings in computation


Download ppt "TinyOS: Radio, Concurrent Execution, and Power control"

Similar presentations


Ads by Google