|
|
|
@ -43,80 +43,80 @@ void FollowerClass::follower(global_location* member_data, size_t index, int ref
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FollowerClass::plane(global_location target, global_location leader, global_location follower){
|
|
|
|
void FollowerClass::plane(global_location* target, global_location* leader, global_location* follower){
|
|
|
|
|
|
|
|
|
|
|
|
//caculate drone is locate on R/L plane
|
|
|
|
//caculate drone is locate on R/L plane
|
|
|
|
float slope,c,y;
|
|
|
|
float slope,c,y;
|
|
|
|
slope = (target.lat-leader.lat)/(target.lon-leader.lon);
|
|
|
|
slope = (target->lat-leader->lat)/(target->lon-leader->lon);
|
|
|
|
c = leader.lat - slope*leader.lon;
|
|
|
|
c = leader->lat - slope*leader->lon;
|
|
|
|
y = slope * follower.lon + c;
|
|
|
|
y = slope * follower->lon + c;
|
|
|
|
// std::cout<< follower.ID << ","<< follower.lat <<","<< y <<std::endl;
|
|
|
|
// std::cout<< follower.ID << ","<< follower.lat <<","<< y <<std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
if(follower.lat <= y){
|
|
|
|
if(follower->lat <= y){
|
|
|
|
// std::cout<< follower.lat <<","<< y <<std::endl;
|
|
|
|
// std::cout<< follower.lat <<","<< y <<std::endl;
|
|
|
|
switch (follower.ID){
|
|
|
|
switch (follower->ID){
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
drone1.init_location.lat = follower.lat;
|
|
|
|
drone1.init_location.lat = follower->lat;
|
|
|
|
drone1.init_location.lon = follower.lon;
|
|
|
|
drone1.init_location.lon = follower->lon;
|
|
|
|
drone1.ID = follower.ID;
|
|
|
|
drone1.ID = follower->ID;
|
|
|
|
drone1.plane = 1; //right plane
|
|
|
|
drone1.plane = 1; //right plane
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
drone2.init_location.lat = follower.lat;
|
|
|
|
drone2.init_location.lat = follower->lat;
|
|
|
|
drone2.init_location.lon = follower.lon;
|
|
|
|
drone2.init_location.lon = follower->lon;
|
|
|
|
drone2.ID = follower.ID;
|
|
|
|
drone2.ID = follower->ID;
|
|
|
|
drone2.plane = 1;
|
|
|
|
drone2.plane = 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 3:
|
|
|
|
drone3.init_location.lat = follower.lat;
|
|
|
|
drone3.init_location.lat = follower->lat;
|
|
|
|
drone3.init_location.lon = follower.lon;
|
|
|
|
drone3.init_location.lon = follower->lon;
|
|
|
|
drone3.ID = follower.ID;
|
|
|
|
drone3.ID = follower->ID;
|
|
|
|
drone3.plane = 1;
|
|
|
|
drone3.plane = 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
drone4.init_location.lat = follower.lat;
|
|
|
|
drone4.init_location.lat = follower->lat;
|
|
|
|
drone4.init_location.lon = follower.lon;
|
|
|
|
drone4.init_location.lon = follower->lon;
|
|
|
|
drone4.ID = follower.ID;
|
|
|
|
drone4.ID = follower->ID;
|
|
|
|
drone4.plane = 1;
|
|
|
|
drone4.plane = 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
case 5:
|
|
|
|
drone5.init_location.lat = follower.lat;
|
|
|
|
drone5.init_location.lat = follower->lat;
|
|
|
|
drone5.init_location.lon = follower.lon;
|
|
|
|
drone5.init_location.lon = follower->lon;
|
|
|
|
drone5.ID = follower.ID;
|
|
|
|
drone5.ID = follower->ID;
|
|
|
|
drone5.plane = 1;
|
|
|
|
drone5.plane = 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if(follower.lat > y){
|
|
|
|
}else if(follower->lat > y){
|
|
|
|
// std::cout<< follower.lat <<","<< y <<std::endl;
|
|
|
|
// std::cout<< follower.lat <<","<< y <<std::endl;
|
|
|
|
switch (follower.ID){
|
|
|
|
switch (follower->ID){
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
drone1.init_location.lat = follower.lat;
|
|
|
|
drone1.init_location.lat = follower->lat;
|
|
|
|
drone1.init_location.lon = follower.lon;
|
|
|
|
drone1.init_location.lon = follower->lon;
|
|
|
|
drone1.ID = follower.ID;
|
|
|
|
drone1.ID = follower->ID;
|
|
|
|
drone1.plane = -1; //left plane
|
|
|
|
drone1.plane = -1; //left plane
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
drone2.init_location.lat = follower.lat;
|
|
|
|
drone2.init_location.lat = follower->lat;
|
|
|
|
drone2.init_location.lon = follower.lon;
|
|
|
|
drone2.init_location.lon = follower->lon;
|
|
|
|
drone2.ID = follower.ID;
|
|
|
|
drone2.ID = follower->ID;
|
|
|
|
drone2.plane = -1;
|
|
|
|
drone2.plane = -1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 3:
|
|
|
|
drone3.init_location.lat = follower.lat;
|
|
|
|
drone3.init_location.lat = follower->lat;
|
|
|
|
drone3.init_location.lon = follower.lon;
|
|
|
|
drone3.init_location.lon = follower->lon;
|
|
|
|
drone3.ID = follower.ID;
|
|
|
|
drone3.ID = follower->ID;
|
|
|
|
drone3.plane = -1;
|
|
|
|
drone3.plane = -1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
drone4.init_location.lat = follower.lat;
|
|
|
|
drone4.init_location.lat = follower->lat;
|
|
|
|
drone4.init_location.lon = follower.lon;
|
|
|
|
drone4.init_location.lon = follower->lon;
|
|
|
|
drone4.ID = follower.ID;
|
|
|
|
drone4.ID = follower->ID;
|
|
|
|
drone4.plane = -1;
|
|
|
|
drone4.plane = -1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
case 5:
|
|
|
|
drone5.init_location.lat = follower.lat;
|
|
|
|
drone5.init_location.lat = follower->lat;
|
|
|
|
drone5.init_location.lon = follower.lon;
|
|
|
|
drone5.init_location.lon = follower->lon;
|
|
|
|
drone5.ID = follower.ID;
|
|
|
|
drone5.ID = follower->ID;
|
|
|
|
drone5.plane = -1;
|
|
|
|
drone5.plane = -1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -125,12 +125,12 @@ void FollowerClass::plane(global_location target, global_location leader, global
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FollowerClass::direct(global_location target, global_location leader, DroneStatus self, DroneStatus member){
|
|
|
|
int FollowerClass::direct(global_location* target, global_location* leader, DroneStatus self, DroneStatus member){
|
|
|
|
|
|
|
|
|
|
|
|
global_location vector_LT,vector_SM;
|
|
|
|
global_location vector_LT,vector_SM;
|
|
|
|
float m,n,k,cosTheta;
|
|
|
|
float m,n,k,cosTheta;
|
|
|
|
vector_LT.lon = target.lon - leader.lon; //vector_LT (leader->target)
|
|
|
|
vector_LT.lon = target->lon - leader->lon; //vector_LT (leader->target)
|
|
|
|
vector_LT.lat = target.lat - leader.lat;
|
|
|
|
vector_LT.lat = target->lat - leader->lat;
|
|
|
|
vector_SM.lon = member.init_location.lon - self.init_location.lon; //vector_SM (self->member)
|
|
|
|
vector_SM.lon = member.init_location.lon - self.init_location.lon; //vector_SM (self->member)
|
|
|
|
vector_SM.lat = member.init_location.lat - self.init_location.lat;
|
|
|
|
vector_SM.lat = member.init_location.lat - self.init_location.lat;
|
|
|
|
k = (vector_LT.lon*vector_SM.lon)+(vector_LT.lat*vector_SM.lat); //k = vector_LT dot vector_SM
|
|
|
|
k = (vector_LT.lon*vector_SM.lon)+(vector_LT.lat*vector_SM.lat); //k = vector_LT dot vector_SM
|
|
|
|
@ -146,40 +146,40 @@ int FollowerClass::direct(global_location target, global_location leader, DroneS
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FollowerClass::find_ref_drone(global_location data[], size_t index, int leaderID){
|
|
|
|
int FollowerClass::find_ref_drone(global_location* data[], size_t index, int leaderID){
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=1 ; i<index ; i++){ //check leader drone
|
|
|
|
for(int i=1 ; i<index ; i++){ //check leader drone
|
|
|
|
if(leaderID == data[i].ID){
|
|
|
|
if(leaderID == data[i]->ID){
|
|
|
|
leader_drone = data[i];
|
|
|
|
leader_drone = *data[i];
|
|
|
|
switch(leaderID){
|
|
|
|
switch(leaderID){
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
drone1.init_location.lat = data[i].lat;
|
|
|
|
drone1.init_location.lat = data[i]->lat;
|
|
|
|
drone1.init_location.lon = data[i].lon;
|
|
|
|
drone1.init_location.lon = data[i]->lon;
|
|
|
|
drone1.ID = data[i].ID;
|
|
|
|
drone1.ID = data[i]->ID;
|
|
|
|
drone1.plane = 0; //center
|
|
|
|
drone1.plane = 0; //center
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
drone2.init_location.lat = data[i].lat;
|
|
|
|
drone2.init_location.lat = data[i]->lat;
|
|
|
|
drone2.init_location.lon = data[i].lon;
|
|
|
|
drone2.init_location.lon = data[i]->lon;
|
|
|
|
drone2.ID = data[i].ID;
|
|
|
|
drone2.ID = data[i]->ID;
|
|
|
|
drone2.plane = 0;
|
|
|
|
drone2.plane = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 3:
|
|
|
|
drone3.init_location.lat = data[i].lat;
|
|
|
|
drone3.init_location.lat = data[i]->lat;
|
|
|
|
drone3.init_location.lon = data[i].lon;
|
|
|
|
drone3.init_location.lon = data[i]->lon;
|
|
|
|
drone3.ID = data[i].ID;
|
|
|
|
drone3.ID = data[i]->ID;
|
|
|
|
drone3.plane = 0;
|
|
|
|
drone3.plane = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
drone4.init_location.lat = data[i].lat;
|
|
|
|
drone4.init_location.lat = data[i]->lat;
|
|
|
|
drone4.init_location.lon = data[i].lon;
|
|
|
|
drone4.init_location.lon = data[i]->lon;
|
|
|
|
drone4.ID = data[i].ID;
|
|
|
|
drone4.ID = data[i]->ID;
|
|
|
|
drone4.plane = 0;
|
|
|
|
drone4.plane = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
case 5:
|
|
|
|
drone5.init_location.lat = data[i].lat;
|
|
|
|
drone5.init_location.lat = data[i]->lat;
|
|
|
|
drone5.init_location.lon = data[i].lon;
|
|
|
|
drone5.init_location.lon = data[i]->lon;
|
|
|
|
drone5.ID = data[i].ID;
|
|
|
|
drone5.ID = data[i]->ID;
|
|
|
|
drone5.plane = 0;
|
|
|
|
drone5.plane = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
@ -189,41 +189,41 @@ int FollowerClass::find_ref_drone(global_location data[], size_t index, int lead
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=1 ; i<index ; i++){
|
|
|
|
for(int i=1 ; i<index ; i++){
|
|
|
|
if(data[i].ID != leader_drone.ID){ //caculate the plane of each drone
|
|
|
|
if(data[i]->ID != leader_drone.ID){ //caculate the plane of each drone
|
|
|
|
plane(data[0],leader_drone,data[i]);
|
|
|
|
plane(data[0],&leader_drone,data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int j=0,s_index=0;
|
|
|
|
int j=0,s_index=0;
|
|
|
|
if(drone1.ID == data[1].ID){ //seperate self and other
|
|
|
|
if(drone1.ID == data[1]->ID){ //seperate self and other
|
|
|
|
self = drone1; //problem
|
|
|
|
self = drone1; //problem
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
memberDrone[j] = drone1;
|
|
|
|
memberDrone[j] = drone1;
|
|
|
|
j+=1;
|
|
|
|
j+=1;
|
|
|
|
// std::cout << "drone1" <<std::endl;
|
|
|
|
// std::cout << "drone1" <<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(drone2.ID == data[1].ID){
|
|
|
|
if(drone2.ID == data[1]->ID){
|
|
|
|
self = drone2;
|
|
|
|
self = drone2;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
memberDrone[j] = drone2;
|
|
|
|
memberDrone[j] = drone2;
|
|
|
|
j+=1;
|
|
|
|
j+=1;
|
|
|
|
// std::cout << "drone2" <<std::endl;
|
|
|
|
// std::cout << "drone2" <<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(drone3.ID == data[1].ID){
|
|
|
|
if(drone3.ID == data[1]->ID){
|
|
|
|
self = drone3;
|
|
|
|
self = drone3;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
memberDrone[j] = drone3;
|
|
|
|
memberDrone[j] = drone3;
|
|
|
|
j+=1;
|
|
|
|
j+=1;
|
|
|
|
// std::cout << "drone3" <<std::endl;
|
|
|
|
// std::cout << "drone3" <<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(drone4.ID == data[1].ID){
|
|
|
|
if(drone4.ID == data[1]->ID){
|
|
|
|
self = drone4;
|
|
|
|
self = drone4;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
memberDrone[j] = drone4;
|
|
|
|
memberDrone[j] = drone4;
|
|
|
|
j+=1;
|
|
|
|
j+=1;
|
|
|
|
// std::cout << "drone4" <<std::endl;
|
|
|
|
// std::cout << "drone4" <<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(drone5.ID == data[1].ID){
|
|
|
|
if(drone5.ID == data[1]->ID){
|
|
|
|
self = drone5;
|
|
|
|
self = drone5;
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
memberDrone[j] = drone5;
|
|
|
|
memberDrone[j] = drone5;
|
|
|
|
@ -249,7 +249,7 @@ int FollowerClass::find_ref_drone(global_location data[], size_t index, int lead
|
|
|
|
// std::cout <<"s_index " <<s_index <<std::endl;
|
|
|
|
// std::cout <<"s_index " <<s_index <<std::endl;
|
|
|
|
for(int i=0 ; i<s_index ; i++){ //caculate each same plane mamber's distance
|
|
|
|
for(int i=0 ; i<s_index ; i++){ //caculate each same plane mamber's distance
|
|
|
|
|
|
|
|
|
|
|
|
dir = direct(data[0],leader_drone,self,samePlane[i]);
|
|
|
|
dir = direct(data[0],&leader_drone,self,samePlane[i]);
|
|
|
|
d[i] = dir * sqrt( pow((self.init_location.lat - samePlane[i].init_location.lat ),2) + pow((self.init_location.lon - samePlane[i].init_location.lon),2) );
|
|
|
|
d[i] = dir * sqrt( pow((self.init_location.lat - samePlane[i].init_location.lat ),2) + pow((self.init_location.lon - samePlane[i].init_location.lon),2) );
|
|
|
|
|
|
|
|
|
|
|
|
// std::cout << i<<"," <<d[i] <<std::endl;
|
|
|
|
// std::cout << i<<"," <<d[i] <<std::endl;
|
|
|
|
|