diff --git a/src/buzzuav_closures.cpp b/src/buzzuav_closures.cpp index e7499dd..729e1d3 100644 --- a/src/buzzuav_closures.cpp +++ b/src/buzzuav_closures.cpp @@ -25,10 +25,10 @@ int buzzros_print(buzzvm_t vm) { ROS_INFO("BUZZ - [nil]"); break; case BUZZTYPE_INT: - //fprintf(stdout, "%d", o->i.value); + fprintf(stdout, "%d", o->i.value); break; case BUZZTYPE_FLOAT: - //fprintf(stdout, "%f", o->f.value); + fprintf(stdout, "%f", o->f.value); break; case BUZZTYPE_TABLE: //fprintf(stdout, "[table with %d elems]", (buzzdict_size(o->t.value))); @@ -42,7 +42,7 @@ int buzzros_print(buzzvm_t vm) { //fprintf(stdout, "[c-closure @%d]", o->c.value.ref); break; case BUZZTYPE_STRING: - //fprintf(stdout, "%s", o->s.value.str); + fprintf(stdout, "%s", o->s.value.str); break; case BUZZTYPE_USERDATA: //fprintf(stdout, "[userdata @%p]", o->u.value); diff --git a/src/out.basm b/src/out.basm index 50bca23..37720c5 100644 --- a/src/out.basm +++ b/src/out.basm @@ -1,20 +1,31 @@ -!4 +!15 'init +'id +'mydist +'neighbors +'listen +'dist_to_source +'math +'min +'get +'distance 'step +'broadcast +'print 'reset 'destroy pushs 0 pushcn @__label_1 gstore - pushs 1 - pushcn @__label_2 + pushs 10 + pushcn @__label_5 gstore - pushs 2 - pushcn @__label_3 + pushs 13 + pushcn @__label_6 gstore - pushs 3 - pushcn @__label_4 + pushs 14 + pushcn @__label_7 gstore nop @@ -24,13 +35,74 @@ done @__label_1 - ret0 |3,1,/home/vivek/BuzzKH4/build/test.bzz - -@__label_2 - ret0 |7,1,/home/vivek/BuzzKH4/build/test.bzz - -@__label_3 - ret0 |11,1,/home/vivek/BuzzKH4/build/test.bzz + pushs 1 |3,6,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |3,6,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushi 0 |3,9,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + eq |3,10,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + jumpz @__label_2 |3,12,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 2 |5,11,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushf 0. |5,13,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gstore |5,15,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + jump @__label_3 |7,7,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz +@__label_2 |7,7,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 2 |9,11,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushf 1000. |9,13,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gstore |9,18,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 3 |11,13,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |11,13,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 4 |11,14,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + tget |11,20,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 5 |11,21,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushl @__label_4 |12,6,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushi 2 |16,8,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + callc |16,8,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz +@__label_3 |17,3,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + ret0 |18,1,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz @__label_4 - ret0 |15,1,/home/vivek/BuzzKH4/build/test.bzz + pushs 2 |13,15,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 6 |13,21,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |13,21,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 7 |13,22,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + tget |13,25,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 2 |14,16,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |14,16,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 3 |15,19,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |15,19,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 8 |15,20,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + tget |15,23,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + lload 3 |15,32,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushi 1 |15,33,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + callc |15,33,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 9 |15,34,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + tget |15,43,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + lload 2 |15,50,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + add |15,50,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushi 2 |15,51,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + callc |15,51,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gstore |15,51,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + ret0 |16,7,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + +@__label_5 + pushs 3 |22,9,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |22,9,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 11 |22,10,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + tget |22,19,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 5 |22,20,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 2 |22,44,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |22,44,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushi 2 |22,45,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + callc |22,45,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 12 |23,5,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |23,5,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushs 2 |23,12,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + gload |23,12,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + pushi 1 |23,13,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + callc |23,13,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + ret0 |26,1,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + +@__label_6 + ret0 |30,1,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz + +@__label_7 + ret0 |34,1,/home/vivek/catkin_ws/src/rosbuzz/src/test.bzz diff --git a/src/out.bdbg b/src/out.bdbg index 92d9b2b..59107bd 100644 Binary files a/src/out.bdbg and b/src/out.bdbg differ diff --git a/src/out.bo b/src/out.bo index 6c8c106..fd5d8cc 100644 Binary files a/src/out.bo and b/src/out.bo differ diff --git a/src/rosbuzz.cpp b/src/rosbuzz.cpp index 2ea18e2..3101b2b 100644 --- a/src/rosbuzz.cpp +++ b/src/rosbuzz.cpp @@ -28,6 +28,10 @@ #include #include +#include +#include +#include + static int done = 0; static double cur_pos [3]; @@ -35,6 +39,7 @@ double distance; double azimuth; double elevation; + /** * This tutorial demonstrates simple sending of messages over the ROS system. */ @@ -121,7 +126,11 @@ static void ctrlc_handler(int sig) { int main(int argc, char **argv) { - + + + system("bzzparse /home/vivek/catkin_ws/src/rosbuzz/src/test.bzz /home/vivek/catkin_ws/src/rosbuzz/src/out.basm"); + system("bzzasm /home/vivek/catkin_ws/src/rosbuzz/src/out.basm /home/vivek/catkin_ws/src/rosbuzz/src/out.bo /home/vivek/catkin_ws/src/rosbuzz/src/out.bdbg"); + // %Tag(INIT)% ros::init(argc, argv, "rosBuzz"); // %EndTag(INIT)% @@ -175,6 +184,7 @@ int main(int argc, char **argv) fprintf(stderr, "%s: invalid value %d for message size\n", argv[0], msg_sz); return 0; } */ + /* The bytecode filename */ char* bcfname = "/home/vivek/catkin_ws/src/rosbuzz/src/out.bo"; //argv[1]; /* The debugging information file name */ diff --git a/src/test.bzz b/src/test.bzz index 18f692f..2ae3a01 100644 --- a/src/test.bzz +++ b/src/test.bzz @@ -1,9 +1,28 @@ # Executed once at init time. function init() { +if(id == 0) { + # Source robot + mydist = 0. + } + else { + # Other robots + mydist = 1000. + # Listen to other robots' distances + neighbors.listen("dist_to_source", + function(value_id, value, robot_id) { + mydist = math.min( + mydist, + neighbors.get(robot_id).distance + value) + }) + } } # Executed at each time step. function step() { +neighbors.broadcast("dist_to_source", mydist) +print(mydist) + + } # Executed once when the robot (or the simulator) is reset. @@ -13,3 +32,4 @@ function reset() { # Executed once at the end of experiment. function destroy() { } +