diff --git a/buzz_scripts/include/act/states.bzz b/buzz_scripts/include/act/states.bzz index 81f7a73..df51aa2 100644 --- a/buzz_scripts/include/act/states.bzz +++ b/buzz_scripts/include/act/states.bzz @@ -13,6 +13,7 @@ include "act/neighborcomm.bzz" TARGET_ALTITUDE = 15.0 # m. BVMSTATE = "TURNEDOFF" PICTURE_WAIT = 20 # steps +WP_STIG = 8 path_it = 0 pic_time = 0 @@ -100,7 +101,7 @@ firsttimeinwp = 1 wpreached = 1 function indiWP() { if(firsttimeinwp) { - v_wp = stigmergy.create(8) + v_wp = stigmergy.create(WP_STIG) storegoal(pose.position.latitude, pose.position.longitude, pose.position.altitude) firsttimeinwp = 0 } @@ -111,21 +112,27 @@ function indiWP() { storegoal(rc_goto.latitude, rc_goto.longitude, pose.position.altitude) return } else { - v_wp.put(rc_goto.id,{.lat=rc_goto.latitude, .lon=rc_goto.longitude, .pro=0}) + var ls = packWP2i(rc_goto.latitude, rc_goto.longitude, 0) + v_wp.put(rc_goto.id,ls) reset_rc() } } - wp = v_wp.get(id) - if(wp!=nil) { - #log(wp.pro,wpreached) - if(wp.pro == 0) { - wpreached = 0 - storegoal(wp.lat, wp.lon, pose.position.altitude) - v_wp.put(id,{.lat=wp.lat, .lon=wp.lon, .pro=1}) - return - } - } + #if(vstig_buzzy == 0) { + wpi = v_wp.get(id) + if(wpi!=nil) { + #log(wp.pro,wpreached) + wp = unpackWP2i(wpi) + table_print(wp) + if(wp.pro == 0) { + wpreached = 0 + storegoal(wp.lat, wp.lon, pose.position.altitude) + var ls = packWP2i(wp.lat, wp.lon, 1) + v_wp.put(id,ls) + return + } + } + #} if(wpreached!=1) goto_gps(indiWP_done) diff --git a/buzz_scripts/include/plan/mapmatrix.bzz b/buzz_scripts/include/plan/mapmatrix.bzz index c3d3393..209aed0 100644 --- a/buzz_scripts/include/plan/mapmatrix.bzz +++ b/buzz_scripts/include/plan/mapmatrix.bzz @@ -102,21 +102,6 @@ function is_in(dictionary, x, y){ return 0 } - -function table_print(t) { - foreach(t, function(key, value) { - log(key, " -> ", value) - }) -} - -function table_copy(t) { - var t2 = {} - foreach(t, function(key, value) { - t2[key] = value - }) - return t2 -} - function print_pos(t) { var ir=1 while(ir <= size(t)) { diff --git a/buzz_scripts/include/taskallocate/graphformGPS.bzz b/buzz_scripts/include/taskallocate/graphformGPS.bzz index f020e2e..b796a1f 100644 --- a/buzz_scripts/include/taskallocate/graphformGPS.bzz +++ b/buzz_scripts/include/taskallocate/graphformGPS.bzz @@ -6,6 +6,7 @@ include "taskallocate/graphs/shapes_P.bzz" include "taskallocate/graphs/shapes_O.bzz" include "taskallocate/graphs/shapes_L.bzz" include "taskallocate/graphs/shapes_Y.bzz" +#include "utils/table.bzz" ROBOT_RADIUS = 50 ROBOT_DIAMETER = 2.0*ROBOT_RADIUS @@ -82,60 +83,6 @@ m_lockstig = 1 # Lennard-Jones parameters, may need change EPSILON_GRAPH = 4000 #13.5 the LJ parameter for other robots -# -#return the number of value in table -# -function count(table,value){ - var number=0 - var i=0 - while(i ", value) + }) +} + +function table_copy(t) { + var t2 = {} + foreach(t, function(key, value) { + t2[key] = value + }) + return t2 +} + +# +#return the number of value in table +# +function count(table,value){ + var number=0 + var i=0 + while(i0) { - if(b_updating==0) { - u=0 - while(u0) { - if(b_updating==0) { - u=0 - while(u indoor wheeled vehicle V_TYPE = 0 -goal_list = { - .0={.x = 45.5088103899, .y = -73.1540826153, .z = 2.5} -} # Executed once at init time. function init() { @@ -53,7 +51,7 @@ function step() { rc_cmd_listen() # update the vstig (status/net/batt/...) - # uav_updatestig() + #uav_updatestig() # # State machine diff --git a/src/buzz_utility.cpp b/src/buzz_utility.cpp index d9a80ca..9e3ba5f 100644 --- a/src/buzz_utility.cpp +++ b/src/buzz_utility.cpp @@ -291,6 +291,12 @@ static int testing_buzz_register_hooks() buzzvm_pushs(VM, buzzvm_string_register(VM, "add_neighborStatus", 1)); buzzvm_pushcc(VM, buzzvm_function_register(VM, buzzuav_closures::dummy_closure)); buzzvm_gstore(VM); + buzzvm_pushs(VM, buzzvm_string_register(VM, "export_map", 1)); + buzzvm_pushcc(VM, buzzvm_function_register(VM, buzzuav_closures::dummy_closure)); + buzzvm_gstore(VM); + buzzvm_pushs(VM, buzzvm_string_register(VM, "reset_rc", 1)); + buzzvm_pushcc(VM, buzzvm_function_register(VM, buzzuav_closures::dummy_closure)); + buzzvm_gstore(VM); return VM->state; } diff --git a/src/buzzuav_closures.cpp b/src/buzzuav_closures.cpp index a18a093..60abf02 100644 --- a/src/buzzuav_closures.cpp +++ b/src/buzzuav_closures.cpp @@ -54,7 +54,7 @@ int buzzros_print(buzzvm_t vm) ----------------------------------------------------------- */ { std::ostringstream buffer(std::ostringstream::ate); - buffer << "[" << buzz_utility::get_robotid() << "] "; + buffer << std::fixed << std::setprecision(6) << "[" << buzz_utility::get_robotid() << "] "; for (uint32_t index = 1; index < buzzdarray_size(vm->lsyms->syms); ++index) { buzzvm_lload(vm, index); @@ -288,23 +288,42 @@ int buzzuav_addNeiStatus(buzzvm_t vm) / closure to add neighbors status to the BVM /----------------------------------------*/ { - buzzvm_lnum_assert(vm, 5); - buzzvm_lload(vm, 1); // fc - buzzvm_lload(vm, 2); // xbee - buzzvm_lload(vm, 3); // batt - buzzvm_lload(vm, 4); // gps - buzzvm_lload(vm, 5); // id - buzzvm_type_assert(vm, 5, BUZZTYPE_INT); - buzzvm_type_assert(vm, 4, BUZZTYPE_INT); - buzzvm_type_assert(vm, 3, BUZZTYPE_INT); - buzzvm_type_assert(vm, 2, BUZZTYPE_INT); - buzzvm_type_assert(vm, 1, BUZZTYPE_INT); + buzzvm_lnum_assert(vm, 1); + buzzvm_lload(vm, 1); // state table + buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE); + buzzobj_t t = buzzvm_stack_at(vm, 1); + if(buzzdict_size(t->t.value) != 5) { + ROS_WARN("Wrong neighbor status size."); + return vm->state; + } + buzz_utility::neighbors_status newRS; - uint8_t id = buzzvm_stack_at(vm, 5)->i.value; - newRS.gps_strenght = buzzvm_stack_at(vm, 4)->i.value; - newRS.batt_lvl = buzzvm_stack_at(vm, 3)->i.value; - newRS.xbee = buzzvm_stack_at(vm, 2)->i.value; + buzzvm_dup(vm); + buzzvm_pushs(vm, buzzvm_string_register(vm, "id", 1)); + buzzvm_tget(vm); + uint8_t id = buzzvm_stack_at(vm, 1)->i.value; + buzzvm_pop(vm); + buzzvm_dup(vm); + buzzvm_pushs(vm, buzzvm_string_register(vm, "ba", 1)); + buzzvm_tget(vm); + newRS.batt_lvl = buzzvm_stack_at(vm, 1)->i.value; + buzzvm_pop(vm); + buzzvm_dup(vm); + buzzvm_pushs(vm, buzzvm_string_register(vm, "gp", 1)); + buzzvm_tget(vm); + newRS.gps_strenght = buzzvm_stack_at(vm, 1)->i.value; + buzzvm_pop(vm); + buzzvm_dup(vm); + buzzvm_pushs(vm, buzzvm_string_register(vm, "xb", 1)); + buzzvm_tget(vm); + newRS.xbee = buzzvm_stack_at(vm, 1)->i.value; + buzzvm_pop(vm); + buzzvm_dup(vm); + buzzvm_pushs(vm, buzzvm_string_register(vm, "st", 1)); + buzzvm_tget(vm); newRS.flight_status = buzzvm_stack_at(vm, 1)->i.value; + buzzvm_pop(vm); + map::iterator it = neighbors_status_map.find(id); if (it != neighbors_status_map.end()) neighbors_status_map.erase(it); @@ -417,8 +436,10 @@ void set_gpsgoal(double goal[3]) rb_from_gps(goal, rb, cur_pos); if (fabs(rb[0]) < 150.0) { goto_gpsgoal[0] = goal[0];goto_gpsgoal[1] = goal[1];goto_gpsgoal[2] = goal[2]; - ROS_INFO("Set GPS GOAL TO ---- %f %f %f (%f %f, %f %f)", goal[0], goal[1], goal[2], cur_pos[0], cur_pos[1], rb[0], rb[1]); - } + ROS_INFO("[%i] Set GPS GOAL TO ---- %f %f %f (%f %f, %f %f)", buzz_utility::get_robotid(), goal[0], goal[1], goal[2], cur_pos[0], cur_pos[1], rb[0], rb[1]); + } else + ROS_WARN("[%i] GPS GOAL TOO FAR !!-- %f %f %f (%f %f, %f %f)", buzz_utility::get_robotid(), goal[0], goal[1], goal[2], cur_pos[0], cur_pos[1], rb[0], rb[1]); + } int buzzuav_arm(buzzvm_t vm)