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