ROSBuzz_MISTLab/buzz_scripts/include/barrier.bzz
2017-08-30 17:22:37 -04:00

65 lines
1.1 KiB
Plaintext

########################################
#
# BARRIER-RELATED FUNCTIONS
#
########################################
#
# Constants
#
BARRIER_VSTIG = 11
BARRIER_TIMEOUT = 200 # in steps
#
# Sets a barrier
#
function barrier_set(threshold, transf, resumef, bdt) {
statef = function() {
barrier_wait(threshold, transf, resumef, bdt);
}
barrier = stigmergy.create(BARRIER_VSTIG)
}
#
# Make yourself ready
#
function barrier_ready() {
barrier.put(id, 1)
}
#
# Executes the barrier
#
timeW=0
function barrier_wait(threshold, transf, resumef, bdt) {
barrier.put(id, 1)
UAVSTATE = "BARRIERWAIT"
barrier.get(id)
if(barrier.size() >= threshold) {
# getlowest()
transf()
} else if(timeW >= BARRIER_TIMEOUT) {
barrier = nil
resumef()
timeW=0
} else if(bdt!=-1)
neighbors.broadcast("cmd", bdt)
timeW = timeW+1
}
# get the lowest id of the fleet, but requires too much bandwidth...
function getlowest(){
Lid = 15;
u=15
while(u>=0){
tab = barrier.get(u)
if(tab!=nil){
if(tab<Lid)
Lid=tab
}
u=u-1
}
log("--> LOWEST ID:",Lid)
}