From 4c1c3dff4329e1936fd8f5c6d46e0c3dccd68e93 Mon Sep 17 00:00:00 2001 From: vivek-shankar Date: Sun, 2 Apr 2017 15:06:36 -0400 Subject: [PATCH] addition of robots variable inside BVM and for updates barrier --- include/buzz_update.h | 4 +++- include/buzz_utility.h | 2 ++ src/buzz_update.cpp | 9 +++++++-- src/buzz_utility.cpp | 5 +++++ src/roscontroller.cpp | 7 ++++++- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/buzz_update.h b/include/buzz_update.h index 34355f7..c8bbaf0 100644 --- a/include/buzz_update.h +++ b/include/buzz_update.h @@ -73,7 +73,7 @@ void update_routine(const char* bcfname, /************************************************/ /*Initalizes the updater */ /************************************************/ -void init_update_monitor(const char* bo_filename,const char* stand_by_script,int barrier); +void init_update_monitor(const char* bo_filename,const char* stand_by_script); /*********************************************************/ @@ -129,4 +129,6 @@ int get_update_status(); void set_read_update_status(); +void updates_set_robots(int robots); + #endif diff --git a/include/buzz_utility.h b/include/buzz_utility.h index 2675e8b..6b2a1aa 100644 --- a/include/buzz_utility.h +++ b/include/buzz_utility.h @@ -52,4 +52,6 @@ int update_step_test(); uint16_t get_robotid(); buzzvm_t get_vm(); + +void set_robot_var(int ROBOTS); } diff --git a/src/buzz_update.cpp b/src/buzz_update.cpp index 82d785c..be9d43e 100644 --- a/src/buzz_update.cpp +++ b/src/buzz_update.cpp @@ -27,7 +27,7 @@ static int neigh=-1; static int updater_msg_ready ; static int updated=0; -void init_update_monitor(const char* bo_filename, const char* stand_by_script,int barrier){ +void init_update_monitor(const char* bo_filename, const char* stand_by_script){ fprintf(stdout,"intiialized file monitor.\n"); fd=inotify_init1(IN_NONBLOCK); if ( fd < 0 ) { @@ -91,7 +91,7 @@ void init_update_monitor(const char* bo_filename, const char* stand_by_script,in *(size_t*)(updater->standby_bcode_size)=stdby_bcode_size; updater->mode=(int*)malloc(sizeof(int)); *(int*)(updater->mode)=CODE_RUNNING; - no_of_robot=barrier; + //no_of_robot=barrier; updater_msg_ready=0; //neigh = 0; //updater->outmsg_queue= @@ -444,6 +444,11 @@ close(fd); void set_bzz_file(const char* in_bzz_file){ bzz_file=in_bzz_file; } + +void updates_set_robots(int robots){ +no_of_robot=robots; +} + void collect_data(){ //fprintf(stdout,"start and end time in data collection Info : %f,%f",(double)begin,(double)end); double time_spent = (t2.tv_sec - t1.tv_sec) * 1000.0; //(double)(end - begin) / CLOCKS_PER_SEC; diff --git a/src/buzz_utility.cpp b/src/buzz_utility.cpp index 245bf8e..905e1a9 100644 --- a/src/buzz_utility.cpp +++ b/src/buzz_utility.cpp @@ -548,6 +548,11 @@ buzzvm_t get_vm(){ return VM; } +void set_robot_var(int ROBOTS){ + buzzvm_pushs(VM, buzzvm_string_register(VM, "ROBOTS", 1)); + buzzvm_pushi(VM, ROBOTS); + buzzvm_gstore(VM); +} } diff --git a/src/roscontroller.cpp b/src/roscontroller.cpp index 27aa2a5..2347878 100644 --- a/src/roscontroller.cpp +++ b/src/roscontroller.cpp @@ -52,7 +52,7 @@ 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(),barrier); + init_update_monitor(bcfname.c_str(),stand_by.c_str()); while (ros::ok() && !buzz_utility::buzz_script_done()) { /*Update neighbors position inside Buzz*/ @@ -72,6 +72,10 @@ namespace rosbzz_node{ set_read_update_status(); multi_msg=true; } + /*Set ROBOTS variable for barrier in .bzz from neighbours count*/ + buzz_utility::set_robot_var(neighbours_pos_map.size()); + /*Set no of robots for updates*/ + updates_set_robots(neighbours_pos_map.size()); /*run once*/ ros::spinOnce(); /*loop rate of ros*/ @@ -81,6 +85,7 @@ namespace rosbzz_node{ timer_step+=1; maintain_pos(timer_step); + } /* Destroy updater and Cleanup */ //update_routine(bcfname.c_str(), dbgfname.c_str(),1);