add FindLeader function
This commit is contained in:
@@ -4,7 +4,7 @@ typedef struct DroneStatus
|
||||
{
|
||||
/* data */
|
||||
global_location init_location;
|
||||
int plane;
|
||||
int plane,ID;
|
||||
std::string leader;
|
||||
std::string DroneName;
|
||||
} DroneStatus;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "class_model/gps_location.h"
|
||||
#include "class_model/DroneStatus.h"
|
||||
#include <iterator>
|
||||
|
||||
bool is_leader(global_location data[], size_t index){
|
||||
|
||||
float d[index];
|
||||
int check_ID,leader_ID;
|
||||
|
||||
for(int i=1 ; i<index ; i++){
|
||||
|
||||
d[data[i].ID] = sqrt( pow((data[0].lat - data[i].lat),2) + pow((data[0].lon - data[i].lon),2) );
|
||||
|
||||
// std::cout << i<<"," <<d[data[i].ID] <<std::endl;
|
||||
}
|
||||
|
||||
std::vector<float> _d(d+1,d+index-1);
|
||||
|
||||
check_ID = std::distance(_d.begin(),std::min_element(_d.begin(),_d.end())); //get minimum value's index
|
||||
leader_ID = check_ID + 1;
|
||||
|
||||
std::cout <<"Drone " << leader_ID << " is leader " << std::endl;
|
||||
|
||||
if (data[1].ID == leader_ID){
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user