From f8917cd39eb188a2c8e209ea000086b543cdb08b Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 9 May 2017 13:07:11 -0400 Subject: [PATCH] fix bzz compilation and moved scripts and include --- .gitignore | 4 + include/buzzuav_closures.h | 2 - include/roscontroller.h | 2 +- script/include/string.bzz | 92 +++++++++++++++ script/include/vec2.bzz | 107 +++++++++++++++++ script/stand_by.bdb | Bin 0 -> 7810 bytes script/stand_by.bo | Bin 0 -> 572 bytes {src => script}/stand_by.bzz | 0 {src => script}/test.bzz | 0 {src => script}/test1.bzz | 0 {src => script}/testalone.bzz | 0 {src => script}/testflockfev.bzz | 0 {src => script}/testflockfev_barrier.bzz | 0 {src => script}/testflocksim.bzz | 30 +++-- script/teststig.bdb | Bin 0 -> 9585 bytes script/teststig.bo | Bin 0 -> 678 bytes script/teststig.bzz | 38 ++++++ src/buzz_utility.cpp | 52 ++++---- src/buzzuav_closures.cpp | 39 +----- src/roscontroller.cpp | 51 ++++---- src/stand_by.basm | 144 ----------------------- src/stand_by.bdb | Bin 7560 -> 0 bytes src/stand_by.bdbg | Bin 6840 -> 0 bytes src/stand_by.bo | Bin 531 -> 0 bytes 24 files changed, 326 insertions(+), 235 deletions(-) create mode 100644 script/include/string.bzz create mode 100644 script/include/vec2.bzz create mode 100644 script/stand_by.bdb create mode 100644 script/stand_by.bo rename {src => script}/stand_by.bzz (100%) rename {src => script}/test.bzz (100%) rename {src => script}/test1.bzz (100%) rename {src => script}/testalone.bzz (100%) rename {src => script}/testflockfev.bzz (100%) rename {src => script}/testflockfev_barrier.bzz (100%) rename {src => script}/testflocksim.bzz (90%) create mode 100644 script/teststig.bdb create mode 100644 script/teststig.bo create mode 100644 script/teststig.bzz delete mode 100644 src/stand_by.basm delete mode 100644 src/stand_by.bdb delete mode 100644 src/stand_by.bdbg delete mode 100644 src/stand_by.bo diff --git a/.gitignore b/.gitignore index 7d62213..ae47e75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ src/test* .cproject .project +.basm +.bo +.bdb +.bdbg diff --git a/include/buzzuav_closures.h b/include/buzzuav_closures.h index 4a586ae..2e62d32 100644 --- a/include/buzzuav_closures.h +++ b/include/buzzuav_closures.h @@ -46,7 +46,6 @@ void rc_call(int rc_cmd); void set_battery(float voltage,float current,float remaining); /* sets current position */ void set_currentpos(double latitude, double longitude, double altitude); -void set_userspos(double latitude, double longitude, double altitude); /*retuns the current go to position */ double* getgoto(); /* updates flight status*/ @@ -85,7 +84,6 @@ int buzzuav_update_battery(buzzvm_t vm); * Updates current position in Buzz */ int buzzuav_update_currentpos(buzzvm_t vm); -buzzobj_t buzzuav_update_userspos(buzzvm_t vm); /* * Updates flight status and rc command in Buzz, put it in a tabel to acess it diff --git a/include/roscontroller.h b/include/roscontroller.h index e1e00c8..43cb117 100644 --- a/include/roscontroller.h +++ b/include/roscontroller.h @@ -137,7 +137,7 @@ private: void Rosparameters_get(ros::NodeHandle& n_c_priv); /*compiles buzz script from the specified .bzz file*/ - void Compile_bzz(); + std::string Compile_bzz(std::string bzzfile_name); /*Flight controller service call*/ void flight_controller_service_call(); diff --git a/script/include/string.bzz b/script/include/string.bzz new file mode 100644 index 0000000..4140a1b --- /dev/null +++ b/script/include/string.bzz @@ -0,0 +1,92 @@ +# +# Returns the string character at the given position. +# PARAM s: The string +# PARAM n: The position of the wanted character +# RETURN The character at the wanted position, or nil +# +string.charat = function(s, n) { + return string.sub(s, n, n+1) +} + +# +# Returns the index of the first occurrence of the given string m +# within another string s. If none is found, this function returns +# nil. +# PARAM s: The string +# PARAM m: The string to match +# RETURN: The position of the first match, or nil +# +string.indexoffirst = function(s, m) { + var ls = string.length(s) + var lm = string.length(m) + var i = 0 + while(i < ls-lm+1) { + if(string.sub(s, i, i+lm) == m) return i + i = i + 1 + } + return nil +} + +# +# Returns the index of the last occurrence of the given string m +# within another string s. If none is found, this function returns +# nil. +# PARAM s: The string +# PARAM m: The string to match +# RETURN: The position of the last match, or nil +# +string.indexoflast = function(s, m) { + var ls = string.length(s) + var lm = string.length(m) + var i = ls - lm + 1 + while(i >= 0) { + if(string.sub(s, i, i+lm) == m) return i + i = i - 1 + } + return nil +} + +# Splits a string s using the delimiters in d. The string list is +# returned in a table indexed by value (starting at 0). +# PARAM s: The string +# PARAM d: A string containing the delimiters +# RETURN: A table containing the tokens +string.split = function(s, d) { + var i1 = 0 # index to move along s (token start) + var i2 = 0 # index to move along s (token end) + var c = 0 # token count + var t = {} # token list + var ls = string.length(s) + var ld = string.length(d) + # Go through string s + while(i2 < ls) { + # Try every delimiter + var j = 0 # index to move along d + var f = nil # whether the delimiter was found or not + while(j < ld and (not f)) { + if(string.charat(s, i2) == string.charat(d, j)) { + # Delimiter found + f = 1 + # Is it worth adding a new token? + if(i2 > i1) { + t[c] = string.sub(s, i1, i2) + c = c + 1 + } + # Start new token + i1 = i2 + 1 + } + else { + # Next delimiter + j = j + 1 + } + } + # Next string character + i2 = i2 + 1 + } + # Is it worth adding a new token? + if(i2 > i1) { + t[c] = string.sub(s, i1, i2) + } + # Return token list + return t; +} diff --git a/script/include/vec2.bzz b/script/include/vec2.bzz new file mode 100644 index 0000000..e2fb9b0 --- /dev/null +++ b/script/include/vec2.bzz @@ -0,0 +1,107 @@ +# +# Create a new namespace for vector2 functions +# +math.vec2 = {} + +# +# Creates a new vector2. +# PARAM x: The x coordinate. +# PARAM y: The y coordinate. +# RETURN: A new vector2. +# +math.vec2.new = function(x, y) { + return { .x = x, .y = y } +} + +# +# Creates a new vector2 from polar coordinates. +# PARAM l: The length of the vector2. +# PARAM a: The angle of the vector2. +# RETURN: A new vector2. +# +math.vec2.newp = function(l, a) { + return { + .x = l * math.cos(a), + .y = l * math.sin(a) + } +} + +# +# Calculates the length of the given vector2. +# PARAM v: The vector2. +# RETURN: The length of the vector. +# +math.vec2.length = function(v) { + return math.sqrt(v.x * v.x + v.y * v.y) +} + +# +# Calculates the angle of the given vector2. +# PARAM v: The vector2. +# RETURN: The angle of the vector. +# +math.vec2.angle = function(v) { + return math.atan2(v.y, v.x) +} + +# +# Returns the normalized form of a vector2. +# PARAM v: The vector2. +# RETURN: The normalized form. +# +math.vec2.norm = function(v) { + var l = math.length(v) + return { + .x = v.x / l, + .y = v.y / l + } +} + +# +# Calculates v1 + v2. +# PARAM v1: A vector2. +# PARAM v2: A vector2. +# RETURN: v1 + v2 +# +math.vec2.add = function(v1, v2) { + return { + .x = v1.x + v2.x, + .y = v1.y + v2.y + } +} + +# +# Calculates v1 - v2. +# PARAM v1: A vector2. +# PARAM v2: A vector2. +# RETURN: v1 + v2 +# +math.vec2.sub = function(v1, v2) { + return { + .x = v1.x - v2.x, + .y = v1.y - v2.y + } +} + +# +# Scales a vector by a numeric constant. +# PARAM v: A vector2. +# PARAM s: A number (float or int). +# RETURN: s * v +# +math.vec2.scale = function(v, s) { + return { + .x = v.x * s, + .y = v.y * s + } +} + +# +# Calculates v1 . v2 (the dot product) +# PARAM v1: A vector2. +# PARAM v2: A vector2. +# RETURN: v1 . v2 +# +math.vec2.dot = function(v1, v2) { + return v1.x * v2.x + v1.y * v2.y +} diff --git a/script/stand_by.bdb b/script/stand_by.bdb new file mode 100644 index 0000000000000000000000000000000000000000..de2da98de2aaa76c5668d25c4392924ef77479a1 GIT binary patch literal 7810 zcmb`MJ8X?{7{*VFUX)&Fi=Mhv(st1HYm?HXh@=Y^5=SByM=vLF37Vd^IEjVDf`x^J zg~h_cf`x^Jfx#t&NJJPIbg9JS_}+Nt=Y9W6zvX@UJiqsU`@S<*k;$}V{*5I4JCI2Z zoj6uVCPrrq$)4T0{JvaLoErc8I5JZzCB^Zn!;{lVaeDOlM1Jga-&m>C51Fd8e5o#T z88VG&d9^Mx02wQ{ze1=hj`m}j(CnjIc^k>5X$C@;|xDQ4R@TH`52jQLfoq(o+reP zZR;R~a>zW6>C|ru#% zD`78wMs8N>p%S<;CXS2A5o&mc?xq?t#>89+Y>twfPTfsSjGO0>u`S)vslk{|)xyo9 zl!@c}%?rrbF}FZRypcjVwyjCHvDw?LyQz<1^9nN7XgrpOFpGy{*fdZmV#2| zcaX7*tmCV|8OYf58`49y#f1786Dmt?9N&vSksHU!a27HFh|fXBUVv;-2-9yJv9T|; zg3K3UW0yBU<~)UR{C3wF6Y4vKvh7O<)dd+_l8$ZbLJXUWkg=Nt9@TB@Cu(iKS)+f>|e( zIFQ45c4lY2&IK*YEO9Dp&PkHKuBj7j2ilvTPyoG}UK*(+2Wvqa) z^z|cehP*90?*Kz@#FFpxF0h``^zBLC-~rh>9}HzH-WPc&nVR bvAnupJ7S03(G5=jb`C{|0{_Fq`tslxS&C1c literal 0 HcmV?d00001 diff --git a/src/stand_by.bzz b/script/stand_by.bzz similarity index 100% rename from src/stand_by.bzz rename to script/stand_by.bzz diff --git a/src/test.bzz b/script/test.bzz similarity index 100% rename from src/test.bzz rename to script/test.bzz diff --git a/src/test1.bzz b/script/test1.bzz similarity index 100% rename from src/test1.bzz rename to script/test1.bzz diff --git a/src/testalone.bzz b/script/testalone.bzz similarity index 100% rename from src/testalone.bzz rename to script/testalone.bzz diff --git a/src/testflockfev.bzz b/script/testflockfev.bzz similarity index 100% rename from src/testflockfev.bzz rename to script/testflockfev.bzz diff --git a/src/testflockfev_barrier.bzz b/script/testflockfev_barrier.bzz similarity index 100% rename from src/testflockfev_barrier.bzz rename to script/testflockfev_barrier.bzz diff --git a/src/testflocksim.bzz b/script/testflocksim.bzz similarity index 90% rename from src/testflocksim.bzz rename to script/testflocksim.bzz index fa5f3f5..2dcca47 100644 --- a/src/testflocksim.bzz +++ b/script/testflocksim.bzz @@ -8,7 +8,7 @@ include "/home/ubuntu/buzz/src/include/vec2.bzz" updated="update_ack" update_no=0 function updated_neigh(){ -neighbors.broadcast(updated, update_no) + neighbors.broadcast(updated, update_no) } TARGET_ALTITUDE = 10.0 @@ -147,11 +147,20 @@ function table_print(t) { }) } +######################################## +# +# MAIN FUNCTIONS +# +######################################## + # Executed once at init time. function init() { s = swarm.create(1) -# s.select(1) s.join() + v = stigmergy.create(5) + t = {} + v.put("p",t) + v.put("u",1) statef=idle CURSTATE = "IDLE" } @@ -202,15 +211,22 @@ neighbors.listen("cmd", statef() log("Current state: ", CURSTATE) log("Swarm size: ",ROBOTS) - log("User position: ", users.range) + #log("User position: ", users.range) # Read a value from the structure - t = vt.get("p") - log(t) - table_print(t) + #t = v.get("p") + log(users) + table_print(users) + if(size(users)>0){ + tmp = {2 3} + v.put("p", tmp) + v.put("u",2) + } # Get the number of keys in the structure - log("The vstig has ", vt.size(), " elements") + log("The vstig has ", v.size(), " elements") + table_print(v.get("p")) + log(v.get("u")) } # Executed once when the robot (or the simulator) is reset. diff --git a/script/teststig.bdb b/script/teststig.bdb new file mode 100644 index 0000000000000000000000000000000000000000..cc42d708f7a9fee87df7cfb0952c29a7bd454329 GIT binary patch literal 9585 zcmb_gJ#39(6#l4It5w>n(jTcyZb|6pr%Oo?Q4%4gH&KHUy}i*ZsW!b|CGMbIT7w$Y zz@P@LfrZ6l!NOu;VPUbbu&@|#T<=Mq`8?-a?p@v|&(C?!d){~3k|?T-{(tH4yEBT1 zM@Mq;(D}=`xUV;Ju0InO#h%n4chOvmItmU{;6aRd$$L0JFjlGvH(KE+313fyF!QqRxUSEki>U z?-n+iko+xu2AD2cTN9R7*kSGnjMmL6JIo(}QBMeqvpyC_0@D=4EVqjq5}1~-ToW@S z)eT9lw6mG_N$MWJXz&J6t?|x@I`^C3oOd* zY^r@M9tDeuJ#`2yUSk(k1EPq)$3PSjcn^po=9`B;fjrqefjh-a>2`nZ8KjFjXq`+wP3bE2>sGFyd6j3*m zK1sFuSUe>#ZNZaec5m8%O@kfgluuI6ASq(n>IXJuc2Uzl7N>kHo&h$*$?)9A;!VP4 zU9gtuerF&l;_C52V6dOi_5{57yqj|>*ygusa%-U)&0S#Dr62W+bCJG@N1QBU-V z)xahOQN%OQFa)lbMFX2R5V*e78endN#e}Fzu$UNVyM)d95H!&!s)UX1C8DK|_$2k# zC#g%oMvpy1;O~HqKHM2#?)ubCHv~@1e)GVFfTl%aGK2pTPHm zD57m8AWC<-LDUC<(YJJB6u9qGHx0r@>xMX|7KF`)(ES9l^clQ407((IyG4OX@oXAJ zi5|K{FTNr$Iwlcq>!ZLp)Xf9&Ce3^E3D~GdhQNCuaJ_;UV48iBy6ThEVGyN>8AP>! zD59lL`iS~0Fe-+q;v?dX&V0n4ni4iT^XYtSu(%y8Ci=}6A8(HNc(V~i5lKyh#l#N( z3f{DazGF!0ICw*Bh8Yk=l;1Uh(P51!zqG)pwM0_iz~Xkh#eHBgar5l}QF_oA0{;%8 aQg%@p5T%E(fz7P2aR~ed!06OvVDlFoI_WL| literal 0 HcmV?d00001 diff --git a/script/teststig.bo b/script/teststig.bo new file mode 100644 index 0000000000000000000000000000000000000000..63e7db39574f1a5b89cc74026439d9ba2fbefdaa GIT binary patch literal 678 zcmZ`#%TmHX5NyQwexc$963uw>2RwQ72dEP6R3KX+N)jp?R6O}H`XTc@E?8(~1`5syHlkmQG-CR8|I~s*ICyY-(ghR>Q!r-QrFj+} z%dEgNOr527q$&2vP*;sm^s# z8>E`k64dz&uc)-)YobkEl?zZ4z;(L;__QVT*3y>HFH1wA9~)x06#6L?#1zB^mRUd~ zcfUcKd?@l517ctA5Yj#)9WW?zb{V{~A2RRw z)}!c%F997hlIY98KgAQ)UEXq;Q!&z+^ql|dadKN^$yap27}y7fq?kwY&q8uOXYs{C vKMA4Rkvc3Z%Ud_^oJw65I!y}ruv5Bg_7~5;`^)O?XRgVY=euNwp67i78Yx+$ literal 0 HcmV?d00001 diff --git a/script/teststig.bzz b/script/teststig.bzz new file mode 100644 index 0000000..0ef792e --- /dev/null +++ b/script/teststig.bzz @@ -0,0 +1,38 @@ +#################################################################################################### +# Updater related +# This should be here for the updater to work, changing position of code will crash the updater +#################################################################################################### +updated="update_ack" +update_no=0 +function updated_neigh(){ +neighbors.broadcast(updated, update_no) +} + +function init(){ + s = swarm.create(1) + s.join() + v = stigmergy.create(5) + #t= {} + #v.put("p",t) + v.put("u",1) +} + +function step() { + log("Swarm size: ",ROBOTS) + log("The vstig has ", v.size(), " elements") + log(v.get("u")) + if (id==1) { + #tmp = { .x=3 } + #v.put("p",tmp) + v.put("u",2) + } + #log(v.get("p")) +} + +# Executed once when the robot (or the simulator) is reset. +function reset() { +} + +# Executed once at the end of experiment. +function destroy() { +} \ No newline at end of file diff --git a/src/buzz_utility.cpp b/src/buzz_utility.cpp index 18201c7..dfe19d6 100644 --- a/src/buzz_utility.cpp +++ b/src/buzz_utility.cpp @@ -66,29 +66,29 @@ namespace buzz_utility{ //make_table(&t); if(VM->state != BUZZVM_STATE_READY) return VM->state; /* Register table as global symbol */ - buzzvm_pushs(VM, buzzvm_string_register(VM, "vt", 1)); + /*buzzvm_pushs(VM, buzzvm_string_register(VM, "vt", 1)); buzzvm_gload(VM); buzzvm_pushs(VM, buzzvm_string_register(VM, "put", 1)); - buzzvm_tget(VM); - buzzvm_pushs(VM, buzzvm_string_register(VM, "p", 1)); - //buzzvm_gload(VM); + buzzvm_tget(VM);*/ + buzzvm_pushs(VM, buzzvm_string_register(VM, "users", 1)); buzzvm_push(VM, t); - buzzvm_pushi(VM, 2); - buzzvm_callc(VM); + buzzvm_gstore(VM); + //buzzvm_pushi(VM, 2); + //buzzvm_callc(VM); return VM->state; } int buzzusers_add(int id, double latitude, double longitude, double altitude) { if(VM->state != BUZZVM_STATE_READY) return VM->state; /* Get users "p" table */ - buzzvm_pushs(VM, buzzvm_string_register(VM, "vt", 1)); + /*buzzvm_pushs(VM, buzzvm_string_register(VM, "vt", 1)); buzzvm_gload(VM); buzzvm_pushs(VM, buzzvm_string_register(VM, "get", 1)); - buzzvm_tget(VM); - buzzvm_pushs(VM, buzzvm_string_register(VM, "p", 1)); - //buzzvm_gload(VM); - buzzvm_pushi(VM, 1); - buzzvm_callc(VM); + buzzvm_tget(VM);*/ + buzzvm_pushs(VM, buzzvm_string_register(VM, "users", 1)); + buzzvm_gload(VM); + //buzzvm_pushi(VM, 1); + //buzzvm_callc(VM); buzzvm_type_assert(VM, 1, BUZZTYPE_TABLE); buzzobj_t nbr = buzzvm_stack_at(VM, 1); /* Get "data" field */ @@ -129,7 +129,7 @@ namespace buzz_utility{ buzzvm_tput(VM); ROS_INFO("Buzz_utility saved new user: %i (%f,%f,%f)", id, latitude, longitude, altitude); // forcing the new table into the stigmergy.... - buzzobj_t newt = buzzvm_stack_at(VM, 0); + /*buzzobj_t newt = buzzvm_stack_at(VM, 0); buzzvm_pushs(VM, buzzvm_string_register(VM, "vt", 1)); buzzvm_gload(VM); buzzvm_pushs(VM, buzzvm_string_register(VM, "put", 1)); @@ -137,7 +137,7 @@ namespace buzz_utility{ buzzvm_pushs(VM, buzzvm_string_register(VM, "p", 1)); buzzvm_push(VM, nbr); buzzvm_pushi(VM, 2); - buzzvm_callc(VM); + buzzvm_callc(VM);*/ //buzzvm_gstore(VM); return VM->state; } @@ -358,7 +358,6 @@ static int create_stig_tables() { // usersvstig = stigmergy.create(123) buzzvm_pushs(VM, buzzvm_string_register(VM, "vt", 1)); - //buzzvm_gstore(VM); // get the stigmergy table from the global scope buzzvm_pushs(VM, buzzvm_string_register(VM, "stigmergy", 1)); buzzvm_gload(VM); @@ -368,19 +367,23 @@ static int create_stig_tables() { // value of the stigmergy id buzzvm_pushi(VM, 5); // call the stigmergy.create() method + buzzvm_dump(VM); // buzzvm_closure_call(VM, 1); buzzvm_pushi(VM, 1); buzzvm_callc(VM); buzzvm_gstore(VM); + buzzvm_dump(VM); //buzzusers_reset(); buzzobj_t t = buzzheap_newobj(VM->heap, BUZZTYPE_TABLE); + buzzvm_pushs(VM, buzzvm_string_register(VM, "vt", 1)); buzzvm_gload(VM); buzzvm_pushs(VM, buzzvm_string_register(VM, "put", 1)); buzzvm_tget(VM); - buzzvm_pushs(VM, buzzvm_string_register(VM, "p", 1)); + buzzvm_pushs(VM, buzzvm_string_register(VM, "p", 1)); buzzvm_push(VM, t); + buzzvm_dump(VM); // buzzvm_closure_call(VM, 2); buzzvm_pushi(VM, 2); buzzvm_callc(VM); @@ -451,7 +454,7 @@ static int create_stig_tables() { ROS_ERROR("[%i] Error registering hooks", Robot_id); return 0; } - /* Create vstig tables */ + /* Create vstig tables if(create_stig_tables() != BUZZVM_STATE_READY) { buzzvm_destroy(&VM); buzzdebug_destroy(&DBG_INFO); @@ -459,7 +462,12 @@ static int create_stig_tables() { //cout << "ERROR!!!! ---------- " << VM->errormsg << endl; //cout << "ERROR!!!! ---------- " << buzzvm_strerror(VM) << endl; return 0; - } + }*/ + + buzzobj_t t = buzzheap_newobj(VM->heap, BUZZTYPE_TABLE); + buzzvm_pushs(VM, buzzvm_string_register(VM, "users", 1)); + buzzvm_push(VM, t); + buzzvm_gstore(VM); /* Save bytecode file name */ BO_FNAME = strdup(bo_filename); @@ -626,7 +634,6 @@ static int create_stig_tables() { buzzuav_closures::buzzuav_update_currentpos(VM); buzzuav_closures::update_neighbors(VM); update_users(); - buzzuav_closures::buzzuav_update_userspos(VM); buzzuav_closures::buzzuav_update_flight_status(VM); } @@ -645,13 +652,14 @@ static int create_stig_tables() { /* Process out messages */ buzzvm_process_outmsgs(VM); /*Print swarm*/ - buzzswarm_members_print(stdout, VM->swarmmembers, VM->robot); + //buzzswarm_members_print(stdout, VM->swarmmembers, VM->robot); //int SwarmSize = buzzdict_size(VM->swarmmembers)+1; //fprintf(stderr, "Real Swarm Size: %i\n",SwarmSize); + set_robot_var(buzzdict_size(VM->swarmmembers)+1); /* Check swarm state -- Not crashing thanks to test added in check_swarm_members */ - int status = 1; - buzzdict_foreach(VM->swarmmembers, check_swarm_members, &status); + //int status = 1; + //buzzdict_foreach(VM->swarmmembers, check_swarm_members, &status); } /****************************************/ diff --git a/src/buzzuav_closures.cpp b/src/buzzuav_closures.cpp index 2638f80..afaf1a9 100644 --- a/src/buzzuav_closures.cpp +++ b/src/buzzuav_closures.cpp @@ -19,7 +19,6 @@ namespace buzzuav_closures{ static float batt[3]; static float obst[5]={0,0,0,0,0}; static double cur_pos[3]; - static double users_pos[3]; static uint8_t status; static int cur_cmd = 0; static int rc_cmd=0; @@ -275,19 +274,7 @@ namespace buzzuav_closures{ (it->second).z); } } - void set_userspos(double latitude, double longitude, double altitude){ - /*buzz_utility::Pos_struct pos_arr; - pos_arr.x=latitude; - pos_arr.y=longitude; - pos_arr.z=altitude; - map< int, buzz_utility::Pos_struct >::iterator it = users_map.find(id); - if(it!=users_map.end()) - users_map.erase(it); - users_map.insert(make_pair(id, pos_arr));*/ - users_pos[0]=latitude; - users_pos[1]=longitude; - users_pos[2]=altitude; - } + /****************************************/ int buzzuav_update_currentpos(buzzvm_t vm) { buzzvm_pushs(vm, buzzvm_string_register(vm, "position", 1)); @@ -307,30 +294,6 @@ namespace buzzuav_closures{ buzzvm_gstore(vm); return vm->state; } - buzzobj_t buzzuav_update_userspos(buzzvm_t vm) { - /*map< int, buzz_utility::Pos_struct >::iterator it; - for (it=users_map.begin(); it!=users_map.end(); ++it){ - }*/ - buzzvm_pushs(vm, buzzvm_string_register(vm, "users", 1)); - buzzvm_pusht(vm); - buzzvm_dup(vm); - buzzvm_pushs(vm, buzzvm_string_register(vm, "range", 1)); - buzzvm_pushf(vm, users_pos[0]); - buzzvm_tput(vm); - buzzvm_dup(vm); - buzzvm_pushs(vm, buzzvm_string_register(vm, "bearing", 1)); - buzzvm_pushf(vm, users_pos[1]); - buzzvm_tput(vm); - buzzvm_dup(vm); - buzzvm_pushs(vm, buzzvm_string_register(vm, "height", 1)); - buzzvm_pushf(vm, users_pos[2]); - buzzvm_tput(vm); - buzzobj_t tbl = buzzvm_stack_at(vm, 0); - buzzvm_gstore(vm); - - return tbl; - //return vm->state; - } void flight_status_update(uint8_t state){ status=state; diff --git a/src/roscontroller.cpp b/src/roscontroller.cpp index 5691d58..e2e11f9 100644 --- a/src/roscontroller.cpp +++ b/src/roscontroller.cpp @@ -13,7 +13,9 @@ namespace rosbzz_node{ /*Initialize publishers, subscribers and client*/ Initialize_pub_sub(n_c); /*Compile the .bzz file to .basm, .bo and .bdbg*/ - Compile_bzz(); + std::string fname = Compile_bzz(bzzfile_name); + bcfname = fname + ".bo"; + dbgfname = fname + ".bdb"; set_bzz_file(bzzfile_name.c_str()); /*Initialize variables*/ // Solo things @@ -68,7 +70,8 @@ namespace rosbzz_node{ /* Set the Buzz bytecode */ if(buzz_utility::buzz_script_set(bcfname.c_str(), dbgfname.c_str(),robot_id)) { fprintf(stdout, "Bytecode file found and set\n"); - init_update_monitor(bcfname.c_str(),stand_by.c_str()); + std::string standby_bo = Compile_bzz(stand_by) + ".bo"; + init_update_monitor(bcfname.c_str(),standby_bo.c_str()); /////////////////////////////////////////////////////// // MAIN LOOP ////////////////////////////////////////////////////// @@ -95,7 +98,7 @@ namespace rosbzz_node{ //no_of_robots=get_number_of_robots(); get_number_of_robots(); //if(neighbours_pos_map.size() >0) no_of_robots =neighbours_pos_map.size()+1; - buzz_utility::set_robot_var(no_of_robots); + //buzz_utility::set_robot_var(no_of_robots); /*Set no of robots for updates*/ updates_set_robots(no_of_robots); /*run once*/ @@ -258,28 +261,35 @@ namespace rosbzz_node{ /*-------------------------------------------------------- / Create Buzz bytecode from the bzz script inputed /-------------------------------------------------------*/ - void roscontroller::Compile_bzz(){ + std::string roscontroller::Compile_bzz(std::string bzzfile_name){ /*TODO: change to bzzc instead of bzzparse and also add -I for includes*/ /*Compile the buzz code .bzz to .bo*/ stringstream bzzfile_in_compile; - std::string path = bzzfile_name.substr(0, bzzfile_name.find_last_of("\\/")); - bzzfile_in_compile<_{u+Vv z8=Q`8ey70cGrradoU6vyT7mNdbAd|7%IxXMdEVsHEpYn5Y0Bm=7dY2~@_7Rd%xArz z=Q<#*+5BdK^A>ZN%PN7h06nbdK7lg;PQ-fc1c$lcH65Nhyn)Hgxn1CVz+C1`e;z%% zpojY^FX(B2n27bt2XSr&=Bse_n0%C+Z<~BJ3pp2q^4V*ADd&Vc#@80XSF`b@^q;S0-IepkK9dj6Q=U4! z8rGWjU|aL)MR_t3L19vNRsAA4*#8=-A+c=Q}L`IMG0 zF3um!<$hQ4Ib!s533~np>3I^A^E~tvGC#am@T}KU=wUx?5b`-{a_$j03qih~Ll5g1 zuj%mQ^UvsEzxQw|CZAqG&+#D63BytTmtTStk#im#*0XXBA2GfXA?H`%@cW0?ba>Xi zV03jf2BF9uRyr1^Idx6tLxdsl;soWo)I&3ld z@IJ}I`DpUtJ%@*L+W1;6)M0y&uP??I`Or!t+ diff --git a/src/stand_by.bdbg b/src/stand_by.bdbg deleted file mode 100644 index cda97bcb64b2a515a24a8d21320eed0422c95f7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6840 zcmb`LJ8X?{7{e7}diINCD3=Aw5m&L+jarD#?&7qBRs^ugW78WclEG(8* zA`)?lNJQc;!JsTGEG!llgU8qZlf3i$y#J*6{>%Hz^F06Wy#Ke~^DN7z;_v@jF!{(f zW%-ezW0iblV5Cyb`}>Bg1B0c}dS0*f=e41F`9z~p?CZmQgNI7xQ|rr(#-*k#>qzx8 z1Wpc4YpP!;a5e;S-arHM=@#^CGf&2Tye&Q_Dp3V}0$TE5RpKHH3*UO~^NAU)TEa{dfG(~_SS!PgDwVLzQBaJHMA zR|}jksEzP-6M7aW9oQDjb6}Q^w+e|+5g+6vXD4%wthu^n6zG_B~GDm#`hv%i_JOR$~lrOf$^7!gN zF?BQxoKbN2`%>~b2@dBlh8=XPyq`UsyCxr{k99*2 z>y`WBOpvdK#uvZec=G8nzBs>lIA@J7-m4zYBlu#z%-h3RX?!X7;5p+<`5xYD^eFe> hd80@9{`|z`tlSrCj4$>@&v{)4^7Smp*To<`{{VNFf)xM& diff --git a/src/stand_by.bo b/src/stand_by.bo deleted file mode 100644 index 62e6638cfa6596f03a85929fa44263ac96d0a366..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 531 zcmZut%TB{E5ZnR|Z%TmTNL0$AM)VuF@&lECdz6P8EK(LqV%2es~;GSFIW93WPW!=-IjMB#Dquy}r=v}yr& z0pRwBAi@)-Un8ayroj$TK%#)8l1u``e2+%BM+XW5i2>nFtO#SCn?~N0xX(Hs5K3>v zoS)($VZUXVJL0+7J!Sj6NVpXqvz&0Ir<4EXa6Esfs2>dOKACbn5X1IUUh}6#UtloL z*z{$n^_VUa&;2|B$k{h{@~s7i-n}49NCmtki20>y-;u{;I2UyKPsA%0BH{n5?B5W- Dfn`a`