|
|
|
@ -48,15 +48,19 @@ void FollowerClass::plane(global_location* target, global_location* leader, glob
|
|
|
|
//calculate drone is locate on R/L plane
|
|
|
|
//calculate drone is locate on R/L plane
|
|
|
|
|
|
|
|
|
|
|
|
float phi = leader->heading/100 ;
|
|
|
|
float phi = leader->heading/100 ;
|
|
|
|
phi = phi*3.14/180;
|
|
|
|
// phi = phi*3.14/180;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (phi > 355 && phi < 5){
|
|
|
|
|
|
|
|
phi = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// float ref_y = leader->lat + 5000;
|
|
|
|
// float ref_y = leader->lat + 5000;
|
|
|
|
// float ref_x = leader->lon + 1;
|
|
|
|
// float ref_x = leader->lon + 1;
|
|
|
|
// ref_point.lon = (cos(-phi)*leader->lon + sin(-phi)*ref_y);
|
|
|
|
// ref_point.lon = (cos(-phi)*leader->lon + sin(-phi)*ref_y);
|
|
|
|
// ref_point.lat = (-sin(-phi)*leader->lon + cos(-phi)*ref_y);
|
|
|
|
// ref_point.lat = (-sin(-phi)*leader->lon + cos(-phi)*ref_y);
|
|
|
|
|
|
|
|
|
|
|
|
ref_point.lon = 5000*sin(phi) + leader->lon;
|
|
|
|
ref_point.lon = 5000*sin(phi*3.14/180) + leader->lon + 1;
|
|
|
|
ref_point.lat = 5000*cos(phi) + leader->lat;
|
|
|
|
ref_point.lat = 5000*cos(phi*3.14/180) + leader->lat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
slope = (ref_point.lat-leader->lat)/(ref_point.lon-leader->lon);
|
|
|
|
slope = (ref_point.lat-leader->lat)/(ref_point.lon-leader->lon);
|
|
|
|
@ -75,8 +79,8 @@ void FollowerClass::plane(global_location* target, global_location* leader, glob
|
|
|
|
// std::cout<< follower.ID << ","<< follower.lat <<","<< y <<std::endl;
|
|
|
|
// std::cout<< follower.ID << ","<< follower.lat <<","<< y <<std::endl;
|
|
|
|
std::cout<< "slope: " << slope <<std::endl;
|
|
|
|
std::cout<< "slope: " << slope <<std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
if((follower->lat <= y && slope>0) || (follower->lat > y && slope<0)){
|
|
|
|
if((follower->lat <= y && phi < 180) || (follower->lat > y && phi >= 180)){
|
|
|
|
std::cout <<"drone :"<<follower->ID <<", plane: 1" <<std::endl;
|
|
|
|
// std::cout <<"drone :"<<follower->ID <<", plane: 1" <<std::endl;
|
|
|
|
switch (follower->ID){
|
|
|
|
switch (follower->ID){
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
drone1.init_location.lat = follower->lat;
|
|
|
|
drone1.init_location.lat = follower->lat;
|
|
|
|
@ -109,8 +113,8 @@ void FollowerClass::plane(global_location* target, global_location* leader, glob
|
|
|
|
drone5.plane = 1;
|
|
|
|
drone5.plane = 1;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if((follower->lat > y && slope>0) || (follower->lat <= y && slope<0)){
|
|
|
|
}else if((follower->lat > y && phi < 180) || (follower->lat <= y && phi >= 180)){
|
|
|
|
std::cout <<"drone :"<<follower->ID <<", plane: -1" <<std::endl;
|
|
|
|
// std::cout <<"drone :"<<follower->ID <<", plane: -1" <<std::endl;
|
|
|
|
switch (follower->ID){
|
|
|
|
switch (follower->ID){
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
drone1.init_location.lat = follower->lat;
|
|
|
|
drone1.init_location.lat = follower->lat;
|
|
|
|
@ -195,7 +199,7 @@ int FollowerClass::direct(global_location* target, global_location* leader, Dron
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
cosTheta = k / (m*n);
|
|
|
|
cosTheta = k / (m*n);
|
|
|
|
std::cout <<"drone: "<<self.ID<<"memberID: "<<member.ID << " ,cosTheta:"<< cosTheta << std::endl;
|
|
|
|
// std::cout <<"drone: "<<self.ID<<"memberID: "<<member.ID << " ,cosTheta:"<< cosTheta << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
// std::cout <<"drone "<< self.ID <<"cosTheta: "<< cosTheta << std::endl;
|
|
|
|
// std::cout <<"drone "<< self.ID <<"cosTheta: "<< cosTheta << std::endl;
|
|
|
|
if(cosTheta >= 0){
|
|
|
|
if(cosTheta >= 0){
|
|
|
|
@ -313,7 +317,7 @@ int FollowerClass::find_ref_drone(global_location** data, size_t index, int lead
|
|
|
|
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;
|
|
|
|
std::cout <<"drone" <<samePlane[i].ID<<" ,d = "<<d[i] <<std::endl;
|
|
|
|
// std::cout <<"drone" <<samePlane[i].ID<<" ,d = "<<d[i] <<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<float> _d(d,d+s_index);
|
|
|
|
std::vector<float> _d(d,d+s_index);
|
|
|
|
@ -338,8 +342,14 @@ void FollowerClass::calculate_position(float k,float theta,int plane){
|
|
|
|
float heading = GPS_object.get_heading();
|
|
|
|
float heading = GPS_object.get_heading();
|
|
|
|
|
|
|
|
|
|
|
|
float phi = deg_phi*3.14/180; //degree-->radian
|
|
|
|
float phi = deg_phi*3.14/180; //degree-->radian
|
|
|
|
theta = plane*theta*3.14/180;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(deg_phi >= 180 && deg_phi < 350){
|
|
|
|
|
|
|
|
// plane = plane*-1;
|
|
|
|
|
|
|
|
// }else if((deg_phi >= 350 || deg_phi < 5) && pre_plane != 0){
|
|
|
|
|
|
|
|
// plane = pre_plane;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
theta = plane*theta*3.14/180;
|
|
|
|
|
|
|
|
pre_plane = plane;
|
|
|
|
double Pf[]={},Pl[]={refpos.lon ,refpos.lat}; //transfer maxtrix
|
|
|
|
double Pf[]={},Pl[]={refpos.lon ,refpos.lat}; //transfer maxtrix
|
|
|
|
float transfer[2][2]={
|
|
|
|
float transfer[2][2]={
|
|
|
|
cos(phi),-sin(phi),
|
|
|
|
cos(phi),-sin(phi),
|
|
|
|
|