adapted syc algo to robots
This commit is contained in:
parent
7261aabc40
commit
d3f0299b7e
|
@ -67,7 +67,7 @@ function barrier_wait(threshold, transf, resumef, bc) {
|
||||||
barrier = nil
|
barrier = nil
|
||||||
timeW = 0
|
timeW = 0
|
||||||
BVMSTATE = resumef
|
BVMSTATE = resumef
|
||||||
} else if(timeW % 10 == 0 and bc > 0)
|
} else if(timeW % 50 == 0 and bc > 0)
|
||||||
neighbors.broadcast("cmd", bc)
|
neighbors.broadcast("cmd", bc)
|
||||||
|
|
||||||
timeW = timeW+1
|
timeW = timeW+1
|
||||||
|
|
|
@ -5,7 +5,8 @@ logical_time = 0
|
||||||
# sync algo. constants
|
# sync algo. constants
|
||||||
TIME_JUMP_THR = 5
|
TIME_JUMP_THR = 5
|
||||||
TIME_TO_FORGET = 20
|
TIME_TO_FORGET = 20
|
||||||
TIME_TO_SYNC = 100
|
TIME_TO_SYNC = 200
|
||||||
|
COM_DELAY = 3
|
||||||
# table to store neighbor time data
|
# table to store neighbor time data
|
||||||
time_nei_table = {}
|
time_nei_table = {}
|
||||||
# Algo. global parameters
|
# Algo. global parameters
|
||||||
|
@ -18,20 +19,23 @@ sync_timer = 0
|
||||||
function init_time_sync(){
|
function init_time_sync(){
|
||||||
neighbors.listen("time_sync",
|
neighbors.listen("time_sync",
|
||||||
function(vid, value, rid) {
|
function(vid, value, rid) {
|
||||||
log(" TIME SYNC Got (", vid, ",", value, ") #", rid)
|
if(value != nil){
|
||||||
var msg = string.split(value,",")
|
log(" TIME SYNC Got (", vid, ",", value.time , " , ", value.max, ") #", rid)
|
||||||
var msg_time = string.toint(msg[0])
|
var msg_time = value.time
|
||||||
var msg_max = string.toint(msg[1])
|
var msg_max = value.max
|
||||||
#log("msg: 1: ", msg_time, " 2: ", msg_max )
|
#log("msg: 1: ", msg_time, " 2: ", msg_max )
|
||||||
diffMaxLogical = math.max(diffMaxLogical,msg_max-logical_time)
|
if(msg_time != nil and msg_max != nil){
|
||||||
var time_offset = msg_time - logical_time
|
diffMaxLogical = math.max(diffMaxLogical,msg_max-logical_time)
|
||||||
if(math.abs(time_offset) > math.abs(syncError)) syncError = time_offset
|
var time_offset = msg_time - logical_time
|
||||||
if(time_offset > TIME_JUMP_THR){
|
if(math.abs(time_offset) > math.abs(syncError)) syncError = time_offset
|
||||||
logical_time = logical_time + time_offset
|
if(time_offset > TIME_JUMP_THR){
|
||||||
diffMaxLogical = math.max(diffMaxLogical-time_offset,0)
|
logical_time = logical_time + time_offset
|
||||||
jumped = 1
|
diffMaxLogical = math.max(diffMaxLogical-time_offset,0)
|
||||||
|
jumped = 1
|
||||||
|
}
|
||||||
|
time_nei_table[rid] = { .time=msg_time, .age=0, .max=msg_max}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
time_nei_table[rid] = { .time=msg_time, .age=0, .max=msg_max}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -44,36 +48,39 @@ function step_time_sync(){
|
||||||
log(" SYNC ALGO ACTIVE time:", sync_timer)
|
log(" SYNC ALGO ACTIVE time:", sync_timer)
|
||||||
cnt = 0
|
cnt = 0
|
||||||
avg_offset = 0
|
avg_offset = 0
|
||||||
foreach(time_nei_table, function(key, value) {
|
if(size(time_nei_table) > 0){
|
||||||
if(value != nil){
|
foreach(time_nei_table, function(key, value) {
|
||||||
#log("ForEach neigh : id ", key, " time ", value.time, " , age ", value.age, " , diffmax ", value.max)
|
if(value.time != 0){
|
||||||
var local_offset = value.time - logical_time - value.age
|
#log("ForEach neigh : id ", key, " time ", value.time, " , age ", value.age, " , diffmax ", value.max)
|
||||||
if(local_offset > 0){
|
var local_offset = value.time - logical_time - value.age
|
||||||
avg_offset = avg_offset + 1 * local_offset
|
if(local_offset > 0){
|
||||||
cnt = cnt + 1
|
avg_offset = avg_offset + 1 * local_offset
|
||||||
}
|
cnt = cnt + 1
|
||||||
else{
|
}
|
||||||
if(math.abs(local_offset)<TIME_JUMP_THR){
|
else{
|
||||||
avg_offset = avg_offset + local_offset
|
if(math.abs(local_offset)<TIME_JUMP_THR){
|
||||||
cnt = cnt + 1
|
avg_offset = avg_offset + local_offset
|
||||||
}
|
cnt = cnt + 1
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(value.age > TIME_TO_FORGET)
|
if(value.age > TIME_TO_FORGET)
|
||||||
time_nei_table[key] = nil
|
value.time = 0
|
||||||
value.age = value.age + 1
|
|
||||||
|
value.age = value.age + 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if(cnt > 0 and jumped != 1){
|
||||||
|
var correction = math.ceil(avg_offset / (cnt + 1) )
|
||||||
|
if(math.abs(correction) < TIME_JUMP_THR){
|
||||||
|
logical_time = logical_time + correction
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
if(cnt > 0 and jumped != 1){
|
|
||||||
var correction = math.ceil(avg_offset / (cnt + 1) )
|
|
||||||
if(math.abs(correction) < TIME_JUMP_THR){
|
|
||||||
logical_time = logical_time + correction
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jumped = 0
|
jumped = 0
|
||||||
syncError=0
|
syncError=0
|
||||||
var mstr = string.concat(string.tostring(logical_time + 1),",",string.tostring(logical_time + 1 + diffMaxLogical))
|
var mstr = {.time = (logical_time + COM_DELAY) , .max = (logical_time + COM_DELAY + diffMaxLogical) }
|
||||||
|
#string.concat(string.tostring(logical_time + 1),",",string.tostring(logical_time + 1 + diffMaxLogical))
|
||||||
neighbors.broadcast("time_sync",mstr)
|
neighbors.broadcast("time_sync",mstr)
|
||||||
}
|
}
|
||||||
log("Logical time now ", logical_time)
|
log("Logical time now ", logical_time)
|
||||||
|
|
Loading…
Reference in New Issue