|
|
|
|
@ -20,49 +20,49 @@ FormationClass::~FormationClass() { ros::shutdown(); }
|
|
|
|
|
|
|
|
|
|
void FormationClass::leader(){
|
|
|
|
|
|
|
|
|
|
int counter=0;
|
|
|
|
|
std::string command = "",pre_command = "";
|
|
|
|
|
// int counter=0;
|
|
|
|
|
// std::string command = "",pre_command = "";
|
|
|
|
|
|
|
|
|
|
while(true){
|
|
|
|
|
if(flag==0){
|
|
|
|
|
command_object.set_velocity(0,0,0,0.1,1);
|
|
|
|
|
sleep(5);
|
|
|
|
|
while(counter<=5){
|
|
|
|
|
command_object.set_velocity(-1,1,0,0,1);
|
|
|
|
|
command = receiver_object.check_command();
|
|
|
|
|
// while(true){
|
|
|
|
|
// if(flag==0){
|
|
|
|
|
// command_object.set_velocity(0,0,0,0.1,1);
|
|
|
|
|
// sleep(5);
|
|
|
|
|
// while(counter<=5){
|
|
|
|
|
// command_object.set_velocity(-1,1,0,0,1);
|
|
|
|
|
// command = receiver_object.check_command();
|
|
|
|
|
|
|
|
|
|
while(command =="stop" || command == "land"){
|
|
|
|
|
command_object.set_velocity(0,0,0,0,1);
|
|
|
|
|
command = receiver_object.check_command();
|
|
|
|
|
// while(command =="stop" || command == "land"){
|
|
|
|
|
// command_object.set_velocity(0,0,0,0,1);
|
|
|
|
|
// command = receiver_object.check_command();
|
|
|
|
|
|
|
|
|
|
if(command == "land"){
|
|
|
|
|
mode_object.set_Mode("LAND");
|
|
|
|
|
}else if(command != "stop"){
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// if(command == "land"){
|
|
|
|
|
// mode_object.set_Mode("LAND");
|
|
|
|
|
// }else if(command != "stop"){
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
|
std::cout << command <<std::endl;
|
|
|
|
|
}
|
|
|
|
|
if(counter>=5){
|
|
|
|
|
flag = 1;
|
|
|
|
|
}
|
|
|
|
|
command = receiver_object.check_command();
|
|
|
|
|
// command_object.set_velocity(-1,1,0,0,10);
|
|
|
|
|
// // sleep(5);
|
|
|
|
|
// command_object.set_velocity(0,0,0,0,10);
|
|
|
|
|
// command_object.set_velocity(1,-1,0,0,10);
|
|
|
|
|
// command_object.set_velocity(1,-1,0,0,10);
|
|
|
|
|
// sleep(2);
|
|
|
|
|
}
|
|
|
|
|
if(command == "land"){
|
|
|
|
|
mode_object.set_Mode("LAND");
|
|
|
|
|
ROS_INFO("xxxx");
|
|
|
|
|
}
|
|
|
|
|
// counter++;
|
|
|
|
|
// std::cout << command <<std::endl;
|
|
|
|
|
// }
|
|
|
|
|
// if(counter>=5){
|
|
|
|
|
// flag = 1;
|
|
|
|
|
// }
|
|
|
|
|
// command = receiver_object.check_command();
|
|
|
|
|
// // command_object.set_velocity(-1,1,0,0,10);
|
|
|
|
|
// // // sleep(5);
|
|
|
|
|
// // command_object.set_velocity(0,0,0,0,10);
|
|
|
|
|
// // command_object.set_velocity(1,-1,0,0,10);
|
|
|
|
|
// // command_object.set_velocity(1,-1,0,0,10);
|
|
|
|
|
// // sleep(2);
|
|
|
|
|
// }
|
|
|
|
|
// if(command == "land"){
|
|
|
|
|
// mode_object.set_Mode("LAND");
|
|
|
|
|
// ROS_INFO("xxxx");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormationClass::leader1(float x,float y){
|
|
|
|
|
@ -479,6 +479,10 @@ void FormationClass::calculate_position(float k,float theta,int direction){
|
|
|
|
|
theta = theta*3.14/180;
|
|
|
|
|
|
|
|
|
|
leader_location=request_object.get_leader_GPS(); //get Leader/Follower 's GPS
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
uint64_t get_data_t = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
follower_location=GPS_object.gps_position();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -551,9 +555,17 @@ void FormationClass::calculate_position(float k,float theta,int direction){
|
|
|
|
|
// // ROS_INFO("error_degree:%f",error_degree);
|
|
|
|
|
// // ROS_INFO("error_yaw:%f",error_yaw);
|
|
|
|
|
// ROS_INFO("************************************");
|
|
|
|
|
|
|
|
|
|
// command_object.set_velocity(error_lon,error_lat,0,error_yaw,0.3);
|
|
|
|
|
command_object.set_global_position(Pf[0]/1e5,Pf[1]/1e5,2,deg_phi);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
uint64_t cal_data_t = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
command_object.set_velocity(error_lon ,error_lat ,0,0,0.1);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
command_object.set_velocity(error_lon ,error_lat ,0,0,0.1,get_data_t,cal_data_t);
|
|
|
|
|
#endif
|
|
|
|
|
// command_object.set_global_position(Pf[0]/1e5,Pf[1]/1e5,2,deg_phi);
|
|
|
|
|
// command_object.set_velocity(0,0,0,error_yaw,0.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -636,13 +648,17 @@ void FormationClass::spherical_coordinate(float k,float theta,float psi){
|
|
|
|
|
ROS_INFO("Q[2]:%f ,Pf[2]:%f ,error_z:%f",k*sin(psi),Pf[2],error_z);
|
|
|
|
|
// ROS_INFO("************************************");
|
|
|
|
|
|
|
|
|
|
command_object.set_velocity(error_x,error_y,error_z,error_yaw,0.1);
|
|
|
|
|
// command_object.set_velocity(error_x,error_y,error_z,error_yaw,0.1);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormationClass::go2target(float x,float y){
|
|
|
|
|
|
|
|
|
|
leader_location=request_object.get_leader_GPS();
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
uint64_t get_data_t = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
current_location=GPS_object.gps_position();
|
|
|
|
|
|
|
|
|
|
float target_heading,error_heading;
|
|
|
|
|
@ -686,8 +702,17 @@ void FormationClass::go2target(float x,float y){
|
|
|
|
|
flag = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
uint64_t cal_data_t = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
PubData_object.publishData(drone_speed);
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
command_object.set_velocity(drone_speed.x ,drone_speed.y ,0,0,0.1);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
command_object.set_velocity(drone_speed.x ,drone_speed.y ,0,0,0.1,get_data_t,cal_data_t);
|
|
|
|
|
#endif
|
|
|
|
|
// command_object.set_global_position(target_location.lon/1e5,target_location.lat/1e5,2,target_heading);
|
|
|
|
|
|
|
|
|
|
// ROS_INFO("slope:%f,%f,%f",slope,x,y);
|
|
|
|
|
@ -713,7 +738,13 @@ void FormationClass::face2target(float target_heading){
|
|
|
|
|
error_yaw = 0;
|
|
|
|
|
heading_status = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
command_object.set_velocity(0 ,0 ,0,error_yaw,0.1);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
command_object.set_velocity(0 ,0 ,0,error_yaw,0.1,0,0);
|
|
|
|
|
#endif
|
|
|
|
|
ROS_INFO("face2target...");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|