ROSBuzz_MISTLab/buzz_scripts/include/barrier.bzz

64 lines
1.1 KiB
Plaintext
Raw Normal View History

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