Skip to content

Commit f98f375

Browse files
authored
pioneer 1 codefreeze (#175)
1 parent 978d29f commit f98f375

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

Diff for: src/bittybuzz/buzz_scripts/behaviors/follow_leader.bzz

+33-29
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,41 @@ function tick_follow_leader(stig){
1111
log("Trying to get leader: ", leader)
1212
leader_obj = neighbors.get(leader) # Global to be accessible in filter
1313
if (istable(leader_obj)){
14-
15-
# Getting neighbors in LOS
16-
var obstructing_neighbors = neighbors.filter(function(rid, data){
17-
if(rid != leader and math.abs(data.azimuth) < MAX_LOS_ANGLE){
18-
return true
19-
}
20-
return false
21-
22-
})
23-
24-
# Cummulating the avoidance vector
25-
var avoidance_vec = obstructing_neighbors.reduce(function(rid, data, accum){
26-
var vec_length = -1/math.pow(data.distance, 2)
27-
var vec = math.vec2.newp(vec_length, data.azimuth)
28-
return math.vec2.add(vec, accum);
29-
},
30-
math.vec2.new(0.0, 0.0))
31-
32-
# Goal to the leader and add the avoidance vector
33-
var goal = math.vec2.newp(leader_obj.distance - 0.5, leader_obj.azimuth)
34-
35-
if(math.vec2.length(goal) > 1){
14+
if(leader_obj.distance > 1.25){
15+
# Getting neighbors in LOS
16+
var obstructing_neighbors = neighbors.filter(function(rid, data){
17+
if(rid != leader and data.distance < 1){
18+
return true
19+
}
20+
return false
21+
22+
})
23+
24+
# Cummulating the avoidance vector
25+
var avoidance_vec = obstructing_neighbors.reduce(function(rid, data, accum){
26+
var vec_length = -1/math.pow(data.distance, 1.5)
27+
var vec = math.vec2.newp(vec_length, data.azimuth)
28+
return math.vec2.add(vec, accum);
29+
},
30+
math.vec2.new(0.0, 0.0))
31+
32+
# Goal to the leader and add the avoidance vector
33+
var goal = math.vec2.newp(leader_obj.distance, leader_obj.azimuth)
34+
35+
if(math.vec2.length(goal) > 1){
36+
goal = math.vec2.norm(goal)
37+
}
38+
39+
goal = math.vec2.add(goal, avoidance_vec)
3640
goal = math.vec2.norm(goal)
37-
}
38-
39-
goal = math.vec2.add(goal, avoidance_vec)
40-
41-
log("Avoidance vector: X ", avoidance_vec.x, " Y: ", avoidance_vec.y)
42-
log("Moving towards leader via: ", leader, " at x:", goal.x, " y:", goal.y)
43-
call_host_function(id, "moveBy", {.0 = goal.x, .1 = goal.y})
4441

42+
log("Avoidance vector: X ", avoidance_vec.x, " Y: ", avoidance_vec.y)
43+
log("Moving towards leader via: ", leader, " at x:", goal.x, " y:", goal.y)
44+
call_host_function(id, "moveBy", {.0 = goal.x, .1 = goal.y})
45+
}
46+
else {
47+
call_host_function(id, "moveBy", {.0 = 0.0, .1 = 0.0})
48+
}
4549
}
4650
else{
4751
log("Neighbor not found!")

Diff for: src/bittybuzz/buzz_scripts/main.bzz

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include "behaviors/follow_leader.bzz"
22

33
function init() {
4-
exec = create_exec(500);
4+
exec = create_exec(100);
55
}
66

77
function step() {

0 commit comments

Comments
 (0)