|
|
|
@ -62,22 +62,28 @@ void FollowerClass::plane(global_location* target, global_location* leader, glob
|
|
|
|
ref_point.lon = 5000*sin(phi*3.14/180) + leader->lon + 1;
|
|
|
|
ref_point.lon = 5000*sin(phi*3.14/180) + leader->lon + 1;
|
|
|
|
ref_point.lat = 5000*cos(phi*3.14/180) + leader->lat;
|
|
|
|
ref_point.lat = 5000*cos(phi*3.14/180) + leader->lat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NoChangeLeader
|
|
|
|
|
|
|
|
slope = (ref_point.lat-leader->lat)/(ref_point.lon-leader->lon); // Leader-Ref
|
|
|
|
|
|
|
|
c = leader->lat - slope*leader->lon;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef changeLeader
|
|
|
|
|
|
|
|
if((target->lat != pre_target.lat) || (target->lon != pre_target.lon)){ // Leader-Target
|
|
|
|
|
|
|
|
face2target(target,leader);
|
|
|
|
|
|
|
|
// slope = (target->lat-leader->lat)/(target->lon-leader->lon+1);
|
|
|
|
|
|
|
|
// c = leader->lat - slope*leader->lon;
|
|
|
|
|
|
|
|
pre_target.lat = target->lat;
|
|
|
|
|
|
|
|
pre_target.lon = target->lon;
|
|
|
|
|
|
|
|
ROS_INFO("plane");
|
|
|
|
|
|
|
|
}
|
|
|
|
slope = (ref_point.lat-leader->lat)/(ref_point.lon-leader->lon);
|
|
|
|
slope = (ref_point.lat-leader->lat)/(ref_point.lon-leader->lon);
|
|
|
|
c = leader->lat - slope*leader->lon;
|
|
|
|
c = leader->lat - slope*leader->lon;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// if((target->lat != pre_target.lat) || (target->lon != pre_target.lon)){
|
|
|
|
|
|
|
|
// slope = (target->lat-leader->lat)/(target->lon-leader->lon);
|
|
|
|
|
|
|
|
// c = leader->lat - slope*leader->lon;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y = slope * follower->lon + c;
|
|
|
|
y = slope * follower->lon + c;
|
|
|
|
|
|
|
|
|
|
|
|
pre_target.lat = target->lat;
|
|
|
|
|
|
|
|
pre_target.lon = target->lon;
|
|
|
|
|
|
|
|
// 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 && phi < 180) || (follower->lat > y && phi >= 180)){
|
|
|
|
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;
|
|
|
|
@ -162,41 +168,53 @@ int FollowerClass::direct(global_location* target, global_location* leader, Dron
|
|
|
|
|
|
|
|
|
|
|
|
// 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 = 5000*sin(phi) + leader->lon;
|
|
|
|
ref_point.lon = 5000*sin(phi) + leader->lon;
|
|
|
|
ref_point.lat = 5000*cos(phi) + leader->lat;
|
|
|
|
ref_point.lat = 5000*cos(phi) + leader->lat;
|
|
|
|
|
|
|
|
|
|
|
|
// vector_LT.lon = target->lon - leader->lon; //vector_LT (leader->target)
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NoChangeLeader
|
|
|
|
|
|
|
|
/**************Leader-Ref*****************/
|
|
|
|
vector_LR.lon = ref_point.lon - leader->lon; //vector_LR (leader->Ref)
|
|
|
|
vector_LR.lon = ref_point.lon - leader->lon; //vector_LR (leader->Ref)
|
|
|
|
vector_LR.lat = ref_point.lat - leader->lat;
|
|
|
|
vector_LR.lat = ref_point.lat - leader->lat;
|
|
|
|
|
|
|
|
|
|
|
|
k = (vector_LR.lon*vector_SM.lon)+(vector_LR.lat*vector_SM.lat); //k = vector_LT dot vector_SM
|
|
|
|
k = (vector_LR.lon*vector_SM.lon)+(vector_LR.lat*vector_SM.lat); //k = vector_LR dot vector_SM
|
|
|
|
m = sqrt(pow(vector_LR.lon,2)+pow(vector_LR.lat,2)); //m = |vector_LT|
|
|
|
|
m = sqrt(pow(vector_LR.lon,2)+pow(vector_LR.lat,2)); //m = |vector_LR|
|
|
|
|
|
|
|
|
n = sqrt(pow(vector_SM.lon,2)+pow(vector_SM.lat,2)); //n = |vector_SM|
|
|
|
|
|
|
|
|
/*******************************************/
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef changeLeader
|
|
|
|
|
|
|
|
/**********Leader-Target***********/
|
|
|
|
|
|
|
|
vector_LT.lon = target->lon - leader->lon; //vector_LT (leader->target)
|
|
|
|
|
|
|
|
vector_LT.lat = target->lat - leader->lat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k = (vector_LT.lon*vector_SM.lon)+(vector_LT.lat*vector_SM.lat); //k = vector_LT dot vector_SM
|
|
|
|
|
|
|
|
m = sqrt(pow(vector_LT.lon,2)+pow(vector_LT.lat,2)); //m = |vector_LT|
|
|
|
|
n = sqrt(pow(vector_SM.lon,2)+pow(vector_SM.lat,2)); //n = |vector_SM|
|
|
|
|
n = sqrt(pow(vector_SM.lon,2)+pow(vector_SM.lat,2)); //n = |vector_SM|
|
|
|
|
|
|
|
|
|
|
|
|
// pre_m = sqrt(pow(pre_LT.lon,2)+pow(pre_LT.lat,2));
|
|
|
|
pre_m = sqrt(pow(pre_LT.lon,2)+pow(pre_LT.lat,2));
|
|
|
|
// pre_k = (pre_LT.lon*vector_SM.lon)+(pre_LT.lat*vector_SM.lat);
|
|
|
|
pre_k = (pre_LT.lon*vector_SM.lon)+(pre_LT.lat*vector_SM.lat);
|
|
|
|
// if(pre_m != 0 && ((target->lat == pre_tar.lat) && (target->lon == pre_tar.lon))){
|
|
|
|
if(pre_m != 0 && ((target->lat == pre_tar.lat) && (target->lon == pre_tar.lon))){
|
|
|
|
|
|
|
|
|
|
|
|
// u = (vector_LT.lon*pre_LT.lon)+(vector_LT.lat*pre_LT.lat);
|
|
|
|
u = (vector_LT.lon*pre_LT.lon)+(vector_LT.lat*pre_LT.lat);
|
|
|
|
// LTcos = u / (m*pre_m);
|
|
|
|
LTcos = u / (m*pre_m);
|
|
|
|
// if (LTcos < 0){
|
|
|
|
if (LTcos < 0){
|
|
|
|
// m = pre_m;
|
|
|
|
m = pre_m;
|
|
|
|
// k = pre_k;
|
|
|
|
k = pre_k;
|
|
|
|
// std::cout <<"memberID: "<<member.ID << " fix" << std::endl;
|
|
|
|
// std::cout <<"memberID: "<<member.ID << " fix" << std::endl;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// std::cout <<"dir_test "<< std::endl;
|
|
|
|
// std::cout <<"dir_test "<< std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
// }else{
|
|
|
|
}else{
|
|
|
|
// pre_LT = vector_LT;
|
|
|
|
pre_LT = vector_LT;
|
|
|
|
// pre_tar.lat = target->lat;
|
|
|
|
pre_tar.lat = target->lat;
|
|
|
|
// pre_tar.lon = target->lon;
|
|
|
|
pre_tar.lon = target->lon;
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************/
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
@ -280,20 +298,20 @@ int FollowerClass::find_ref_drone(global_location** data, size_t index, int lead
|
|
|
|
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;
|
|
|
|
j+=1;
|
|
|
|
// j+=1;
|
|
|
|
// std::cout << "drone4" <<std::endl;
|
|
|
|
// // std::cout << "drone4" <<std::endl;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<index-2;i++){
|
|
|
|
for(int i=0;i<index-2;i++){
|
|
|
|
@ -325,7 +343,7 @@ int FollowerClass::find_ref_drone(global_location** data, size_t index, int lead
|
|
|
|
check_index = std::distance(_d.begin(),std::min_element(_d.begin(),_d.end())); //get minimum value's index
|
|
|
|
check_index = std::distance(_d.begin(),std::min_element(_d.begin(),_d.end())); //get minimum value's index
|
|
|
|
ref_ID = samePlane[check_index].ID;
|
|
|
|
ref_ID = samePlane[check_index].ID;
|
|
|
|
|
|
|
|
|
|
|
|
// std::cout <<"drone "<< self.ID <<",plane: "<< self.plane <<",refID: " << ref_ID << ",mem_index: "<< s_index << std::endl;
|
|
|
|
std::cout <<"drone "<< self.ID <<",plane: "<< self.plane <<",refID: " << ref_ID << ",mem_index: "<< s_index << std::endl;
|
|
|
|
// std::cout <<"\n"<< std::endl;
|
|
|
|
// std::cout <<"\n"<< std::endl;
|
|
|
|
return ref_ID;
|
|
|
|
return ref_ID;
|
|
|
|
|
|
|
|
|
|
|
|
@ -361,15 +379,15 @@ void FollowerClass::calculate_position(float k,float theta,int plane){
|
|
|
|
Pf[0]=(transfer[0][0]*Q[0]+transfer[0][1]*Q[1])*T[0]+Pl[0]/100;
|
|
|
|
Pf[0]=(transfer[0][0]*Q[0]+transfer[0][1]*Q[1])*T[0]+Pl[0]/100;
|
|
|
|
Pf[1]=(transfer[1][0]*Q[0]+transfer[1][1]*Q[1])*T[1]+Pl[1]/100;
|
|
|
|
Pf[1]=(transfer[1][0]*Q[0]+transfer[1][1]*Q[1])*T[1]+Pl[1]/100;
|
|
|
|
|
|
|
|
|
|
|
|
error_lon = PID_x.update(follower_location.lon*1e5 , Pf[0] ,follower_pid); //caculate error (PID)
|
|
|
|
// error_lon = PID_x.update(follower_location.lon*1e5 , Pf[0] ,follower_pid); //caculate error (PID)
|
|
|
|
error_lat = PID_y.update(follower_location.lat*1e5 , Pf[1] ,follower_pid);
|
|
|
|
// error_lat = PID_y.update(follower_location.lat*1e5 , Pf[1] ,follower_pid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// float error_x = PID_x.update1(follower_location.lon*1e5 , Pf[0] ); //caculate error
|
|
|
|
// float error_x = PID_x.update1(follower_location.lon*1e5 , Pf[0] ); //caculate error
|
|
|
|
// float error_y = PID_y.update1(follower_location.lat*1e5 , Pf[1] );
|
|
|
|
// float error_y = PID_y.update1(follower_location.lat*1e5 , Pf[1] );
|
|
|
|
|
|
|
|
|
|
|
|
// error_lon = Pf[0] - (follower_location.lon*1e+5); //caculate error
|
|
|
|
error_lon = Pf[0] - (follower_location.lon*1e+5); //caculate error
|
|
|
|
// error_lat = Pf[1] - (follower_location.lat*1e+5);
|
|
|
|
error_lat = Pf[1] - (follower_location.lat*1e+5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float error_degree = deg_phi - heading;
|
|
|
|
float error_degree = deg_phi - heading;
|
|
|
|
@ -425,3 +443,35 @@ void FollowerClass::calculate_position(float k,float theta,int plane){
|
|
|
|
command_object.set_velocity(error_lon,error_lat,0,error_yaw,0.1);
|
|
|
|
command_object.set_velocity(error_lon,error_lat,0,error_yaw,0.1);
|
|
|
|
// command_object.set_global_position(Pf[0]/1e5,Pf[1]/1e5,2,deg_phi);
|
|
|
|
// command_object.set_global_position(Pf[0]/1e5,Pf[1]/1e5,2,deg_phi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FollowerClass::face2target(global_location* target, global_location* leader){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float x,y,target_heading;
|
|
|
|
|
|
|
|
float heading = GPS_object.get_heading();
|
|
|
|
|
|
|
|
heading_status = 0;
|
|
|
|
|
|
|
|
error_yaw = 0.2;
|
|
|
|
|
|
|
|
x = (target->lon/100) - (leader->lon/100);
|
|
|
|
|
|
|
|
y = (target->lat/100) - (leader->lat/100);
|
|
|
|
|
|
|
|
target_heading = ConvertDeg(x,y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error_heading = target_heading - heading;
|
|
|
|
|
|
|
|
error_yaw = check_direction(error_heading)*error_yaw*0.5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(error_heading < -355 || error_heading > 355){
|
|
|
|
|
|
|
|
error_heading = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ROS_INFO("x:%f,y:%f,target_heading:%f,error_heading:%f",x,y,target_heading,error_heading);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(heading_status != 1){
|
|
|
|
|
|
|
|
heading = GPS_object.get_heading();
|
|
|
|
|
|
|
|
error_heading = target_heading - heading;
|
|
|
|
|
|
|
|
if (error_heading < 3 && error_heading > -3 ){
|
|
|
|
|
|
|
|
error_yaw = 0;
|
|
|
|
|
|
|
|
heading_status = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
command_object.set_velocity(0 ,0 ,0,error_yaw,0.1);
|
|
|
|
|
|
|
|
// ROS_INFO("error_yaw:%f",error_yaw);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|