add FindLeader function
parent
623c939094
commit
272060ec4e
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
#include "class_model/mission.h"
|
||||||
|
#include "class_model/choose_leader.h"
|
||||||
|
#include "class_model/PubInfo.h"
|
||||||
|
#include "class_model/FindLeader.h"
|
||||||
|
#include "yaml-cpp/yaml.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
// Init ROS node
|
||||||
|
ros::init(argc, argv, "drone1_node");
|
||||||
|
|
||||||
|
// reate Assync spiner
|
||||||
|
ros::AsyncSpinner spinner(0);
|
||||||
|
spinner.start();
|
||||||
|
// ros::Rate rate(5);
|
||||||
|
|
||||||
|
ModeClass mode_object;
|
||||||
|
ControlClass control_object;
|
||||||
|
ReceiverClass receiver_object;
|
||||||
|
RequestClass request_object;
|
||||||
|
MissionClass mission_object;
|
||||||
|
CommandClass command_object;
|
||||||
|
SelectClass select_formation;
|
||||||
|
PubInfoClass PubInfo_object;
|
||||||
|
|
||||||
|
// SelectionClass selection_object;
|
||||||
|
|
||||||
|
global_location target,self,M1,M2;
|
||||||
|
global_location pos[] = {target,self,M1,M2};
|
||||||
|
size_t index = sizeof(pos)/sizeof(pos[0]);
|
||||||
|
|
||||||
|
YAML::Node config = YAML::LoadFile("/home/dodo/ardupilot_ws/src/class_model/src/config.yaml"); //reading yaml parameter(target point)
|
||||||
|
target.lon = config["routh1"]["x"].as<float>();
|
||||||
|
target.lat = config["routh1"]["y"].as<float>();
|
||||||
|
|
||||||
|
self = request_object.get_self_GPS();
|
||||||
|
M1 = request_object.get_M1_GPS();
|
||||||
|
M2 = request_object.get_M2_GPS();
|
||||||
|
|
||||||
|
if(is_leader(pos,index) == 1){
|
||||||
|
//fly2target
|
||||||
|
}else{
|
||||||
|
//find reference drone
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mode_object.set_Mode("GUIDED");
|
||||||
|
control_object.arm();
|
||||||
|
control_object.takeoff(2);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,10 @@
|
|||||||
|
DroneParam:
|
||||||
|
ID: 1
|
||||||
routh1:
|
routh1:
|
||||||
x: 1.0
|
x: 1.0
|
||||||
y: 1.5
|
y: 1.5
|
||||||
z: 0.0
|
z: 0.0
|
||||||
|
formation:
|
||||||
|
distance: 4.0
|
||||||
|
angel: 45
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue