100 likes | 306 Views
29 Palms Demonstration. The TinyOS code behind the demo. Major application blocks. Data collection Data analysis Data sharing Time Synchronization Velocity calculation Task Flow/Use Data recording/querying. Data collection. Periodic events trigger sampling of ADC data
E N D
29 Palms Demonstration The TinyOS code behind the demo
Major application blocks • Data collection • Data analysis • Data sharing • Time Synchronization • Velocity calculation • Task Flow/Use • Data recording/querying
Data collection • Periodic events trigger sampling of ADC data • Events generated using the CLOCK.comp component. TOS_CALL_COMMAND(TRAFFIC_CLOCK_INIT)(128, 2); void TOS_EVENT(TRAFFIC_CLOCK_EVENT)(); • Collection is initiated by using ADC.comp TOS_CALL_COMMAND(TRAFFIC_GET_DATA)(MAG_CHANNEL1); char TOS_EVENT(TRAFFIC_CHANNEL1_DATA_EVENT) (int data);
Data Analysis • Raw sensor readings are filtered using IIR filters to detect anomalies (like a car passing) ch->first = ch->first - (ch->first >> 3); ch->first += ch->reading; Or first = (first * 7 / 8) + reading; Or Rn = 7*Rn-1 + READINGn where = first/8
Data sharing • Each device sends data to all surrounding nodes TOS_CALL_COMMAND(TRAFFIC_SUB_SEND_MSG)(TOS_BCAST_ADDR, AM_MSG(mags_msg), VAR(buffer); • Each node keeps a buffer of data points that have been collected for this “observation” • Each node check to make sure that an observation received isn’t duplicated for (i=0; i < n; i++) { if (VAR(node)[(int)i] == nid) { return; } } • All new readings are forwarded out again • CRC check used on all transmissions
Time Synchronization • Each node broadcasts out it’s version of the current time every 8 seconds • Any node that falls behind updated its clock to the current time • Nodes synchronized to +/- 1/32 s • Time stored in 32 bits of precision allowing for use of wall clock based timing
Velocity Calculation • Velocity calculated using least squared on data points collected • Least squares requires inversion of 2x2 matrix • Using 16 bit math requires careful choice of input data • Raw readings are shifted and scaled to prevent overflow/underflow • Lowest time reading set to 0 and lowest position estimation set to 0
Must Calculate….. • Matrix to invert: Requires n, x2, x • Matrix inversion requires determinant calculation, several multiplies and divides • Position estimation of each node. • Resulting calculation does not determine the actual speed, instead results in two numbers when divided result in the speed • Prevents underflow over larger range of vehicle speeds
Data Recording • Vehicle detection events are stored into the EPROM log CarEvent* foo = (CarEvent*)VAR(read_msg)[1].data; foo->speed = VAR(speed); foo->time = VAR(car_time); foo->det = VAR(det); foo->id = TOS_LOCAL_ADDRESS; TOS_CALL_COMMAND(TRAFFIC_SUB_SEND_MSG)(0xff,19,&VAR(read_msg)[1]); TOS_CALL_COMMAND(TRAFFIC_APPEND_LOG)(VAR(read_msg)[1].data); VAR(max_log) ++;
Data Retrieval • Data is simultaneously pulled out of the EEPROM and onto the radio. char TOS_EVENT(TRAFFIC_SUB_MSG_SEND_DONE)(TOS_MsgPtr msg){ if(msg == &(VAR(read_msg)[(int)VAR(read_msg_ptr)])) { VAR(entry)++; if(VAR(entry) <= VAR(max_log)){ TOS_CALL_COMMAND(TRAFFIC_READ_LOG)(VAR(entry), VAR(read_msg)[(int)VAR(read_msg_ptr)].data); VAR(read_msg_ptr) ^= 1; TOS_CALL_COMMAND(TRAFFIC_SUB_SEND_MSG)(TOS_BCAST_ADDR, AM_MSG(TRAFFIC_READ_MSG), &(VAR(read_msg)[(int)VAR(read_msg_ptr)])); ………