From f8dc591efc8044fff080957ae6c59ea39a24c117 Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 20 Sep 2016 12:37:33 -0400 Subject: [PATCH] auto compile of buzz script --- src/buzzuav_closures.cpp | 6 +-- src/out.basm | 102 +++++++++++++++++++++++++++++++++------ src/out.bdbg | Bin 224 -> 4148 bytes src/out.bo | Bin 76 -> 341 bytes src/rosbuzz.cpp | 12 ++++- src/test.bzz | 20 ++++++++ 6 files changed, 121 insertions(+), 19 deletions(-) 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 92d9b2b80a3782850f19c2692fecbbede351dbba..59107bd188b1f83a7251a8b05a1e5ac4aba072c0 100644 GIT binary patch literal 4148 zcmb`Jy)Q#y6vnUktdCY`iAtocg`hXV!otGB;$s(WnrIrD^j0PJFR`$&SS&0S3kwU2 z#e&7c!oos4z21|Y^_=^@$<4jX^SjS;-jDO%IF8eSr#`y=UryF>x60cEw^pnbN^X9$ zS}N{r?0K$N$-9-Zm)rII;JaGzs@a_H-$F->sFIOwaGXA)?Nu^d#)vB!chFH5E#sas z5=tM_EX%l(@c>4S`wS~`MNPVn9I24kx4n`&<;{$q{(*eVhX8DAUdL*3zQpT4B#y1$W=e7NIAB;vk z^`Y%AKhTEt@yi(6o_zpD*er*P5y5wTNawZ@>y+w2eMZV?VvJPaLhj=TI;uyzl5xx! z+H*a^vZR$hPN1V+O?NwKO`{fk#2AClBB_s4mW9qDDI?B&j45lHV2nv69{sm9CE~ ZmWA%zQpPnHG^g5nj9ADr${5;n{SUB$Z>0bL literal 224 zcmeZZU|?VdVh~`2Pz*{8`WgATsrqG^WvSWvPNh{<-X13UNu`-NDf%U;#U*-4RaKrq Xwd_#!r0DYk>ft6spEpnsKN_uh>dLXKu^L|xJ|i9XPq<;UuI`# z$FF3aO=N3oF13w`oU!}E)`v((jK-0;o8&jqpTo{jQ>6nn*3sUiysI2sBu}&rzN&W> zN>0JLM8QPKn3#gU5EH)D6)1Qja@`a8Eb=SM7m?p0smJ({E&-Z-+(3Q+mNFObzu^D; z^I32ov*rOfX9ceBKq&_cm2>q 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() { } +