######################################## # # FLEET V.STIGMERGY-RELATED FUNCTIONS # ######################################## # # Constants # STATUS_VSTIG = 20 GROUND_VSTIG = 21 HIGHEST_ROBOTID = 14 WAIT4STEP = 10 # # Init var # var v_status = {} var v_ground = {} b_updating = 0 counter=WAIT4STEP function uav_initstig() { v_status = stigmergy.create(STATUS_VSTIG) v_ground = stigmergy.create(GROUND_VSTIG) } function uav_updatestig() { # TODO: Push values on update only. if(counter<=0) { b_updating=1 #var ls={.1=0,.2=battery.capacity,.3=xbee_status.rssi,.4=flight.status} ls = 50*1000000 + battery.capacity*1000 + xbee_status.rssi*10 + flight.status log("Pushing ", ls, "on vstig with id:", id) v_status.put(id, ls) counter=WAIT4STEP } else { b_updating=0 counter=counter-1 } } function unpackstatus(recv_value){ gps=(recv_value-recv_value%1000000)/1000000 recv_value=recv_value-gps*1000000 batt=(recv_value-recv_value%1000)/1000 recv_value=recv_value-batt*1000 xbee=(recv_value-recv_value%10)/10 recv_value=recv_value-xbee*10 fc=recv_value log("- GPS ", gps) log("- Battery ", batt) log("- Xbee ", xbee) log("- Status ", fc) } function checkusers() { # Read a value from the structure if(size(users)>0) log("Got a user!") # log(users) # users_print(users.dataG) # if(size(users.dataG)>0) # vt.put("p", users.dataG) # Get the number of keys in the structure # log("The vstig has ", vt.size(), " elements") # users_save(vt.get("p")) # table_print(users.dataL) } function users_save(t) { if(size(t)>0) { foreach(t, function(id, tab) { #log("id: ",id," Latitude ", tab.la, "Longitude ", tab.lo) add_user_rb(id,tab.la,tab.lo) }) } } # printing the contents of a table: a custom function function usertab_print(t) { if(size(t)>0) { foreach(t, function(u, tab) { log("id: ",u," Range ", tab.r, "Bearing ", tab.b) }) } } function stattab_print() { if(v_status.size()>0) { if(b_updating==0) { u=0 while(u0) { if(b_updating==0) { u=0 while(u