# Assignment and arithmetic operations a = 3 + 7 # Looping i = 0 while(i < a) i = i + 1 # Branching if(a == 10) i = 0 # Tables t = {} t.b = 9 # Function definition function f(a) { return a } # Function call x = f(9)
Programming robot swarms is difficult.
Existing languages force developers to choose: should one focus on individual robots, or treat the swarm as a whole?
Buzz is designed to allow both approaches. Buzz is an extension language with dynamic typing. Its syntax is inspired to JavaScript, Lua, and Python.
# Print own id print("My id is '", id, "'") # Process sensor data t = temperature.get() maxt = math.max(t, maxt) # Motion set_wheels(5, 5)
By default, every Buzz statement is executed by each robot individually.
Specific commands exist to permit swarm-level programming.
# Creation of a swarm with identifier 1 s = swarm.create(1) # Join swarm if robot id is even s.select(id % 2 == 0) # Leave swarm if id is greater than 5 s.unselect(id > 5) # Assign a task to a swarm s.exec(function() { ... }) # Create new swarm with robots belonging # to both swarms a and b i = swarm.intersection(100, a, b)
A swarm in Buzz is a set of robots.
Different swarms can be assigned different tasks.
Swarms can be created, disbanded, joined, intersected, and subtracted.
# Calculate interaction with nearby robots var dir = neighbors.reduce(force_sum_kin, { x = 0, y = 0}) dir.x = dir.x / neighbors.count() dir.y = dir.y / neighbors.count() # Broadcast / listen to data neighbors.broadcast("dist_to_source", mydist) neighbors.listen("dist_to_source", function(vid, value, rid) { mydist = math.min(mydist, neighbors.get(rid).distance + value) })
The Buzz run-time automatically collects data about nearby robots.
Spatial data permits motion-based behaviors such as pattern formation and leader following.
Communication permits broadcast and aggregation of data.
# Create a new virtual stigmergy v = stigmergy.create(1) # Write a (key,value) entry v.put("a", 6) # Read a value x = v.get("a")
Buzz includes a data structure that allows a swarm to
agree on a set of (key,value)
pairs.
This structure is called virtual stigmergy, after the environment-mediated communication modality used by nest-building social insects.
buzzvm_pusht(vm); buzzobj_t pt = buzzvm_stack_at(vm, 1); buzzvm_pop(vm); /* Store the readings in the table */ for(int i = 0; i < 8; ++i) { buzzvm_push(pt); buzzvm_pushi(vm, i); buzzvm_pushi(vm, prox[i]); buzzvm_tput(vm); } /* Export table as global symbol "prox" */ buzzvm_pushs( vm, buzzvm_string_register(vm, "prox")); buzzvm_push(pt); buzzvm_gstore(pt);
Buzz can be extended with new commands and data structures.
In this way, you can integrate Buzz with other robotics frameworks, such as ROS.
You can also support your own robot.