Skip to content

Commit

Permalink
pioneer 1 codefreeze (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
xgroleau authored Nov 24, 2021
1 parent 978d29f commit f98f375
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
62 changes: 33 additions & 29 deletions src/bittybuzz/buzz_scripts/behaviors/follow_leader.bzz
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,41 @@ function tick_follow_leader(stig){
log("Trying to get leader: ", leader)
leader_obj = neighbors.get(leader) # Global to be accessible in filter
if (istable(leader_obj)){

# Getting neighbors in LOS
var obstructing_neighbors = neighbors.filter(function(rid, data){
if(rid != leader and math.abs(data.azimuth) < MAX_LOS_ANGLE){
return true
}
return false

})

# Cummulating the avoidance vector
var avoidance_vec = obstructing_neighbors.reduce(function(rid, data, accum){
var vec_length = -1/math.pow(data.distance, 2)
var vec = math.vec2.newp(vec_length, data.azimuth)
return math.vec2.add(vec, accum);
},
math.vec2.new(0.0, 0.0))

# Goal to the leader and add the avoidance vector
var goal = math.vec2.newp(leader_obj.distance - 0.5, leader_obj.azimuth)

if(math.vec2.length(goal) > 1){
if(leader_obj.distance > 1.25){
# Getting neighbors in LOS
var obstructing_neighbors = neighbors.filter(function(rid, data){
if(rid != leader and data.distance < 1){
return true
}
return false

})

# Cummulating the avoidance vector
var avoidance_vec = obstructing_neighbors.reduce(function(rid, data, accum){
var vec_length = -1/math.pow(data.distance, 1.5)
var vec = math.vec2.newp(vec_length, data.azimuth)
return math.vec2.add(vec, accum);
},
math.vec2.new(0.0, 0.0))

# Goal to the leader and add the avoidance vector
var goal = math.vec2.newp(leader_obj.distance, leader_obj.azimuth)

if(math.vec2.length(goal) > 1){
goal = math.vec2.norm(goal)
}

goal = math.vec2.add(goal, avoidance_vec)
goal = math.vec2.norm(goal)
}

goal = math.vec2.add(goal, avoidance_vec)

log("Avoidance vector: X ", avoidance_vec.x, " Y: ", avoidance_vec.y)
log("Moving towards leader via: ", leader, " at x:", goal.x, " y:", goal.y)
call_host_function(id, "moveBy", {.0 = goal.x, .1 = goal.y})

log("Avoidance vector: X ", avoidance_vec.x, " Y: ", avoidance_vec.y)
log("Moving towards leader via: ", leader, " at x:", goal.x, " y:", goal.y)
call_host_function(id, "moveBy", {.0 = goal.x, .1 = goal.y})
}
else {
call_host_function(id, "moveBy", {.0 = 0.0, .1 = 0.0})
}
}
else{
log("Neighbor not found!")
Expand Down
2 changes: 1 addition & 1 deletion src/bittybuzz/buzz_scripts/main.bzz
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include "behaviors/follow_leader.bzz"

function init() {
exec = create_exec(500);
exec = create_exec(100);
}

function step() {
Expand Down

0 comments on commit f98f375

Please sign in to comment.