ROSBuzz_MISTLab/buzz_scripts/include/barrier.bzz

87 lines
1.6 KiB
Plaintext
Raw Normal View History

2017-06-16 20:31:54 -03:00
########################################
#
# BARRIER-RELATED FUNCTIONS
#
########################################
#
# Constants
#
2017-09-11 19:01:56 -03:00
BARRIER_TIMEOUT = 1200 # in steps
BARRIER_VSTIG = 80
timeW = 0
barrier = nil
2017-06-16 20:31:54 -03:00
#
# Sets a barrier
#
function barrier_create() {
# reset
timeW = 0
# create barrier vstig
#log("---> Prev. br. ", barrier, " ", BARRIER_VSTIG)
if(barrier!=nil) {
barrier=nil
BARRIER_VSTIG = BARRIER_VSTIG +1
}
#log("---> New. br. ", barrier, " ", BARRIER_VSTIG)
barrier = stigmergy.create(BARRIER_VSTIG)
}
function barrier_set(threshold, transf, resumef, bdt) {
2017-06-16 20:31:54 -03:00
statef = function() {
2017-09-06 20:18:20 -03:00
barrier_wait(threshold, transf, resumef, bdt);
2017-06-16 20:31:54 -03:00
}
UAVSTATE = "BARRIERWAIT"
barrier_create()
2017-06-16 20:31:54 -03:00
}
#
# Make yourself ready
#
function barrier_ready() {
#log("BARRIER READY -------")
2017-06-16 20:31:54 -03:00
barrier.put(id, 1)
barrier.put("d", 0)
2017-06-16 20:31:54 -03:00
}
#
# Executes the barrier
#
function barrier_wait(threshold, transf, resumef, bdt) {
2017-06-16 20:31:54 -03:00
barrier.put(id, 1)
2017-08-30 18:22:37 -03:00
barrier.get(id)
#log("--->BS: ", barrier.size(), " (", BARRIER_VSTIG, ")")
if(barrier.size() - 1 >= threshold or barrier.get("d") == 1) {
barrier.put("d", 1)
timeW = 0
2017-06-16 20:31:54 -03:00
transf()
2017-08-30 15:58:44 -03:00
} else if(timeW >= BARRIER_TIMEOUT) {
log("------> Barrier Timeout !!!!")
2017-09-19 17:20:23 -03:00
barrier=nil
timeW = 0
2017-06-16 20:31:54 -03:00
resumef()
}
if(bdt!=-1)
neighbors.broadcast("cmd", bdt)
2017-08-30 18:22:37 -03:00
2017-06-16 20:31:54 -03:00
timeW = timeW+1
}
2017-08-30 18:22:37 -03:00
# get the lowest id of the fleet, but requires too much bandwidth...
function getlowest(){
2017-08-30 18:22:37 -03:00
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)
2017-09-11 19:01:56 -03:00
}