ROSBuzz_MISTLab/buzz_scripts/include/barrier.bzz

74 lines
1.2 KiB
Plaintext
Raw Normal View History

2017-06-16 20:31:54 -03:00
########################################
#
# BARRIER-RELATED FUNCTIONS
#
########################################
#
# Constants
#
2017-08-30 18:22:37 -03:00
BARRIER_TIMEOUT = 200 # in steps
timeW = 0
2017-06-16 20:31:54 -03:00
#
# Sets a barrier
#
function barrier_create(vstig_nb) {
# reset
timeW = 0
# create barrier vstig
barrier = stigmergy.create(vstig_nb)
}
function barrier_set(threshold, transf, resumef, vstig_nb) {
2017-06-16 20:31:54 -03:00
statef = function() {
barrier_wait(threshold, transf, resumef);
2017-06-16 20:31:54 -03:00
}
UAVSTATE = "BARRIERWAIT"
barrier_create(vstig_nb)
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) {
2017-06-16 20:31:54 -03:00
barrier.put(id, 1)
2017-08-30 18:22:37 -03:00
barrier.get(id)
if(barrier.size() >= threshold or barrier.get("d")==1) {
barrier.put("d", 1)
# barrier = nil
timeW = 0
2017-06-16 20:31:54 -03:00
transf()
2017-08-30 15:58:44 -03:00
} else if(timeW >= BARRIER_TIMEOUT) {
timeW = 0
# barrier = nil
2017-06-16 20:31:54 -03:00
resumef()
}
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-06-16 20:31:54 -03:00
}