|
|
|
@ -67,7 +67,7 @@ void FormationClass::leader(){
|
|
|
|
|
|
|
|
|
|
|
|
void FormationClass::leader1(float x,float y){
|
|
|
|
void FormationClass::leader1(float x,float y){
|
|
|
|
|
|
|
|
|
|
|
|
std::string command = "",pre_command = "";
|
|
|
|
std::string command = "",pre_command = receiver_object.check_command();;
|
|
|
|
std_msgs::String message;
|
|
|
|
std_msgs::String message;
|
|
|
|
|
|
|
|
|
|
|
|
leader_location=request_object.get_leader_GPS();
|
|
|
|
leader_location=request_object.get_leader_GPS();
|
|
|
|
@ -88,9 +88,9 @@ void FormationClass::leader1(float x,float y){
|
|
|
|
|
|
|
|
|
|
|
|
command = receiver_object.check_command();
|
|
|
|
command = receiver_object.check_command();
|
|
|
|
while(command =="stop" || command == "land"){
|
|
|
|
while(command =="stop" || command == "land"){
|
|
|
|
command_object.set_velocity(0,0,0,0,1);
|
|
|
|
// command_object.set_velocity(0,0,0,0,1);
|
|
|
|
command = receiver_object.check_command();
|
|
|
|
// command = receiver_object.check_command();
|
|
|
|
|
|
|
|
|
|
|
|
if(command == "land"){
|
|
|
|
if(command == "land"){
|
|
|
|
mode_object.set_Mode("LAND");
|
|
|
|
mode_object.set_Mode("LAND");
|
|
|
|
}else if(command != "stop"){
|
|
|
|
}else if(command != "stop"){
|
|
|
|
@ -150,7 +150,8 @@ void FormationClass::follower1(int type){
|
|
|
|
|
|
|
|
|
|
|
|
void FormationClass::follower2(int type){
|
|
|
|
void FormationClass::follower2(int type){
|
|
|
|
|
|
|
|
|
|
|
|
std::string message,command,pre_command = "";
|
|
|
|
std::string message,command;
|
|
|
|
|
|
|
|
std::string pre_command = receiver_object.check_command();
|
|
|
|
while(true){
|
|
|
|
while(true){
|
|
|
|
|
|
|
|
|
|
|
|
if(type == 0){
|
|
|
|
if(type == 0){
|
|
|
|
@ -174,7 +175,6 @@ void FormationClass::follower2(int type){
|
|
|
|
// ROS_INFO("change formation");
|
|
|
|
// ROS_INFO("change formation");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pre_command = command;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -413,6 +413,7 @@ void FormationClass::calculate_position(float k,float theta,int direction){
|
|
|
|
|
|
|
|
|
|
|
|
float deg_phi = request_object.get_leader_heading()/100;
|
|
|
|
float deg_phi = request_object.get_leader_heading()/100;
|
|
|
|
float heading = GPS_object.get_heading();
|
|
|
|
float heading = GPS_object.get_heading();
|
|
|
|
|
|
|
|
std::string type = receiver_object.check_command();
|
|
|
|
|
|
|
|
|
|
|
|
float phi = deg_phi*3.14/180; //degree-->radian
|
|
|
|
float phi = deg_phi*3.14/180; //degree-->radian
|
|
|
|
theta = theta*3.14/180;
|
|
|
|
theta = theta*3.14/180;
|
|
|
|
@ -432,15 +433,16 @@ void FormationClass::calculate_position(float k,float theta,int direction){
|
|
|
|
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_lat = PID_y.update(follower_location.lat*1e5 , Pf[1] ,follower_pid);
|
|
|
|
|
|
|
|
|
|
|
|
float error_x = PID_x.update(follower_location.lon*1e5 , Pf[0] ,follower_pid); //caculate error
|
|
|
|
|
|
|
|
float error_y = 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] );
|
|
|
|
|
|
|
|
|
|
|
|
float error_lon = Pf[0] - (follower_location.lon*1e+5); //caculate error
|
|
|
|
// error_lon = Pf[0] - (follower_location.lon*1e+5); //caculate error
|
|
|
|
float error_lat = Pf[1] - (follower_location.lat*1e+5);
|
|
|
|
// error_lat = Pf[1] - (follower_location.lat*1e+5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float error_degree = deg_phi - heading + direction;
|
|
|
|
float error_degree = deg_phi - heading + direction;
|
|
|
|
float error_yaw = 0.2; //CCW
|
|
|
|
float error_yaw = 0.2; //CCW
|
|
|
|
@ -466,19 +468,31 @@ void FormationClass::calculate_position(float k,float theta,int direction){
|
|
|
|
error_yaw = 0;
|
|
|
|
error_yaw = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (error_lon < -1){
|
|
|
|
|
|
|
|
// error_lon = -1;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (error_lon > 1){
|
|
|
|
|
|
|
|
// error_lon = 1;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (error_lat < -1){
|
|
|
|
|
|
|
|
// error_lat = -1;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (error_lat > 1){
|
|
|
|
|
|
|
|
// error_lat = 1;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// ROS_INFO("%f,%f",leader_location.lon/100 ,leader_location.lat/100);
|
|
|
|
// ROS_INFO("%f,%f",leader_location.lon/100 ,leader_location.lat/100);
|
|
|
|
// ROS_INFO("%f,%f",follower_location.lon*1e+5 ,follower_location.lat*1e+5);
|
|
|
|
// ROS_INFO("%f,%f",follower_location.lon*1e+5 ,follower_location.lat*1e+5);
|
|
|
|
// ROS_INFO("%f,%f",Pf[0],Pf[1]);
|
|
|
|
// ROS_INFO("%f,%f",Pf[0],Pf[1]);
|
|
|
|
// ROS_INFO("%f,%f",error_x,error_y);
|
|
|
|
// // ROS_INFO("%f,%f",error_x,error_y);
|
|
|
|
// ROS_INFO("%f,%f",error_lon,error_lat);
|
|
|
|
// ROS_INFO("%f,%f",error_lon,error_lat);
|
|
|
|
// ROS_INFO("deg:%f",deg_phi);
|
|
|
|
// // ROS_INFO("deg:%f",deg_phi);
|
|
|
|
// ROS_INFO("heading:%f",heading);
|
|
|
|
// // ROS_INFO("heading:%f",heading);
|
|
|
|
// ROS_INFO("error_degree:%f",error_degree);
|
|
|
|
// // ROS_INFO("error_degree:%f",error_degree);
|
|
|
|
// ROS_INFO("error_yaw:%f",error_yaw);
|
|
|
|
// // ROS_INFO("error_yaw:%f",error_yaw);
|
|
|
|
// ROS_INFO("************************************");
|
|
|
|
// ROS_INFO("************************************");
|
|
|
|
|
|
|
|
|
|
|
|
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.3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormationClass::spherical_coordinate(float k,float theta,float psi){
|
|
|
|
void FormationClass::spherical_coordinate(float k,float theta,float psi){
|
|
|
|
@ -587,12 +601,24 @@ void FormationClass::go2target(float x,float y){
|
|
|
|
// float error_x = PID_x.update1(current_location.lon*1e5 , target_location.lon );
|
|
|
|
// float error_x = PID_x.update1(current_location.lon*1e5 , target_location.lon );
|
|
|
|
// float error_y = PID_y.update1(current_location.lat*1e5 , target_location.lat );
|
|
|
|
// float error_y = PID_y.update1(current_location.lat*1e5 , target_location.lat );
|
|
|
|
|
|
|
|
|
|
|
|
if (drone_speed.x < 0.3 && drone_speed.x > -0.3){ //ignore small errors
|
|
|
|
if (drone_speed.x < ignore_small && drone_speed.x > -ignore_small){ //ignore small errors
|
|
|
|
drone_speed.x = 0;
|
|
|
|
drone_speed.x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (drone_speed.y < 0.3 && drone_speed.y > -0.3){
|
|
|
|
if (drone_speed.y < ignore_small && drone_speed.y > -ignore_small){
|
|
|
|
drone_speed.y = 0;
|
|
|
|
drone_speed.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drone_speed.x < -1){ //max velociy
|
|
|
|
|
|
|
|
drone_speed.x = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drone_speed.x > 1){
|
|
|
|
|
|
|
|
drone_speed.x = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drone_speed.y < -1){
|
|
|
|
|
|
|
|
drone_speed.y = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drone_speed.y > 1){
|
|
|
|
|
|
|
|
drone_speed.y = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (drone_speed.x == 0 && drone_speed.y == 0){
|
|
|
|
if (drone_speed.x == 0 && drone_speed.y == 0){
|
|
|
|
flag = 1;
|
|
|
|
flag = 1;
|
|
|
|
@ -602,7 +628,7 @@ void FormationClass::go2target(float x,float y){
|
|
|
|
command_object.set_velocity(drone_speed.x ,drone_speed.y ,0,0,0.1);
|
|
|
|
command_object.set_velocity(drone_speed.x ,drone_speed.y ,0,0,0.1);
|
|
|
|
|
|
|
|
|
|
|
|
// ROS_INFO("slope:%f,%f,%f",slope,x,y);
|
|
|
|
// ROS_INFO("slope:%f,%f,%f",slope,x,y);
|
|
|
|
// ROS_INFO("%f,%f",error_x,error_y);
|
|
|
|
ROS_INFO("%f,%f",drone_speed.x,drone_speed.y);
|
|
|
|
// ROS_INFO("heading:%f,target_heading:%f",heading,target_heading);
|
|
|
|
// ROS_INFO("heading:%f,target_heading:%f",heading,target_heading);
|
|
|
|
// ROS_INFO("target:%f,%f",target_location.lon ,target_location.lat);
|
|
|
|
// ROS_INFO("target:%f,%f",target_location.lon ,target_location.lat);
|
|
|
|
// ROS_INFO("current:%f,%f",current_location.lon*1e5 ,current_location.lat*1e5);
|
|
|
|
// ROS_INFO("current:%f,%f",current_location.lon*1e5 ,current_location.lat*1e5);
|
|
|
|
@ -625,6 +651,7 @@ void FormationClass::face2target(float target_heading){
|
|
|
|
heading_status = 1;
|
|
|
|
heading_status = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
command_object.set_velocity(0 ,0 ,0,error_yaw,0.1);
|
|
|
|
command_object.set_velocity(0 ,0 ,0,error_yaw,0.1);
|
|
|
|
|
|
|
|
ROS_INFO("face2target...");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|