|
@@ -76,9 +76,18 @@ void Sub::handle_attitude_sport(){
|
|
|
//get_pilot_desired_lean_angles(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_roll, target_pitch, attitude_control.get_althold_lean_angle_max());
|
|
|
//get_pilot_desired_lean_angles((int16_t)(channel_lateral->norm_input()*5700), (int16_t)((0.5-channel_throttle->norm_input())*5700*2), target_roll, target_pitch, attitude_control.get_althold_lean_angle_max());
|
|
|
//get_pilot_desired_lean_angles(0, (int16_t)((0.5-channel_throttle->norm_input())*5700*2), target_roll, target_pitch, attitude_control.get_althold_lean_angle_max());
|
|
|
- get_pilot_desired_lean_angles(0, (int16_t)((0.5-channel_throttle->norm_input())*5700), target_roll, target_pitch, attitude_control.get_althold_lean_angle_max());
|
|
|
+ float throttle = 2*(0.5-channel_throttle->norm_input());
|
|
|
+ float yaw = channel_yaw->norm_input();
|
|
|
+ if (fabsf(throttle)>=fabsf(yaw))
|
|
|
+ {
|
|
|
+ yaw = 0.0;
|
|
|
+ }else{
|
|
|
+ throttle = 0.0;
|
|
|
+ yaw = channel_yaw->get_control_in()*0.3;
|
|
|
+ }
|
|
|
+ get_pilot_desired_lean_angles(0, (int16_t)(throttle/2.0*5700), target_roll, target_pitch, attitude_control.get_althold_lean_angle_max());
|
|
|
|
|
|
- target_yaw = get_pilot_desired_yaw_rate(channel_yaw->get_control_in()*0.3);//*0.6 变慢
|
|
|
+ target_yaw = get_pilot_desired_yaw_rate(yaw);//*0.6 变慢
|
|
|
|
|
|
if (abs(target_roll) > 300 || abs(target_pitch) > 300) {
|
|
|
//last_roll = ahrs.roll_sensor;
|
|
@@ -108,6 +117,195 @@ void Sub::handle_attitude_sport(){
|
|
|
|
|
|
}
|
|
|
|
|
|
+void Sub::sport_run_alt(void){
|
|
|
+
|
|
|
+
|
|
|
+ // When unarmed, disable motors and stabilization
|
|
|
+ if (!motors.armed()) {
|
|
|
+
|
|
|
+ motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
|
|
|
+ // Sub vehicles do not stabilize roll/pitch/yaw when not auto-armed (i.e. on the ground, pilot has never raised throttle)
|
|
|
+ attitude_control.set_throttle_out(0.5 ,true, g.throttle_filt);
|
|
|
+ attitude_control.relax_attitude_controllers();
|
|
|
+ pos_control.relax_alt_hold_controllers();
|
|
|
+ pos_control.set_alt_target(barometer.get_altitude()*100);//当前深度
|
|
|
+
|
|
|
+ updowmgain =0.5;
|
|
|
+ last_roll = 0;
|
|
|
+ last_pitch = 0;
|
|
|
+ last_yaw = ahrs.yaw_sensor;
|
|
|
+ holding_depth = false;
|
|
|
+ ahrs.get_quat_body_to_ned(attitude_desired_quat_);//12.19
|
|
|
+
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
|
|
|
+ handle_attitude_sport();
|
|
|
+ //pos_control.update_z_controller();//输出了set_throttle_out
|
|
|
+ Matrix3f mat_body = ahrs.get_rotation_body_to_ned();
|
|
|
+ Vector3f Zb = mat_body*Vector3f(0,0,1);
|
|
|
+ Vector3f Ze = Vector3f(0,0,1);
|
|
|
+ float thetaz = Zb*Ze;//计算有没有翻过来
|
|
|
+ Matrix3f mat_half;
|
|
|
+
|
|
|
+ if(mat_body.c.x<0.98 && mat_body.c.x>-0.98){//大约78.5度认为Z轴指向方向,小于78.5进入X轴指向方向
|
|
|
+
|
|
|
+ float beta = 0.0;
|
|
|
+ beta = safe_sqrt(1.0-mat_body.c.x*mat_body.c.x);
|
|
|
+ if (thetaz<0)//翻过来
|
|
|
+ {
|
|
|
+ beta =-beta;
|
|
|
+ }
|
|
|
+ mat_half.a.x= mat_body.a.x/beta;
|
|
|
+ mat_half.a.y=-mat_body.b.x/beta;
|
|
|
+ mat_half.a.z=0.0;
|
|
|
+ mat_half.b.x= mat_body.b.x/beta;
|
|
|
+ mat_half.b.y= mat_body.a.x/beta;
|
|
|
+ mat_half.b.z=0.0;
|
|
|
+ mat_half.c.x= 0.0;
|
|
|
+ mat_half.c.y= 0.0;
|
|
|
+ mat_half.c.z=1.0;
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+
|
|
|
+ Vector3f Xb = mat_body*Vector3f(0,0,1);
|
|
|
+ Xb.z = 0.0;
|
|
|
+ Vector3f Xe = Vector3f(1,0,0);
|
|
|
+ float alphacos = Xb * Xe/Xb.length();
|
|
|
+ float beta = safe_sqrt(1.0-alphacos*alphacos);
|
|
|
+ if (Xb.y<0)
|
|
|
+ {
|
|
|
+ beta =-beta;
|
|
|
+ }
|
|
|
+ mat_half.a.x= alphacos;
|
|
|
+ mat_half.a.y=-beta;
|
|
|
+ mat_half.a.z=0.0;
|
|
|
+ mat_half.b.x= beta;
|
|
|
+ mat_half.b.y=alphacos;
|
|
|
+ mat_half.b.z=0.0;
|
|
|
+ mat_half.c.x= 0.0;
|
|
|
+ mat_half.c.y= 0.0;
|
|
|
+ mat_half.c.z=1.0;
|
|
|
+ }
|
|
|
+ // mat 地到half状态
|
|
|
+
|
|
|
+ Matrix3f rc_vehicle_frame = mat_half*ahrs.get_rotation_body_to_ned().transposed();//rc_vehicle_frame(half)到body
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ float forward = channel_forward->norm_input();
|
|
|
+ float lateral =channel_lateral->norm_input();
|
|
|
+ if (fabsf(forward)>=fabsf(lateral))
|
|
|
+ {
|
|
|
+ lateral = 0.0;
|
|
|
+ }else{
|
|
|
+ forward = 0.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ Vector3f rc_throttle = Vector3f(getgainf(forward), getgainf(lateral), 2*(gaindelay(1.0-(float)PressLevel_f*0.1,updowmgain)-0.5));//手柄的值
|
|
|
+
|
|
|
+
|
|
|
+ Vector3f rc_throttle_vehicle_frame = rc_vehicle_frame*rc_throttle;//手柄从half系到body系
|
|
|
+
|
|
|
+ static uint16_t count2 = 0;
|
|
|
+ count2++;
|
|
|
+ if (count2>200)
|
|
|
+ {
|
|
|
+ count2 = 0;
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " rc_throttle %f %f %f\n",rc_throttle.x,rc_throttle.y,rc_throttle.z);
|
|
|
+ // gcs().send_text(MAV_SEVERITY_INFO, " mata %f %f %f\n",mat_half.a.x,mat_half.a.y,mat_half.a.z);
|
|
|
+// gcs().send_text(MAV_SEVERITY_INFO, " matb %f %f %f\n",mat_half.b.x,mat_half.b.y,mat_half.b.z);
|
|
|
+// gcs().send_text(MAV_SEVERITY_INFO, " matc %f %f %f\n",mat_half.c.x,mat_half.c.y,mat_half.c.z);
|
|
|
+// Matrix3f matx = ahrs.get_rotation_body_to_ned();
|
|
|
+
|
|
|
+// gcs().send_text(MAV_SEVERITY_INFO, " ahrsa %f %f %f\n",matx.a.x,matx.a.y,matx.a.z);
|
|
|
+ // gcs().send_text(MAV_SEVERITY_INFO, " ahrsb %f %f %f\n",matx.b.x,matx.b.y,matx.b.z);
|
|
|
+ // gcs().send_text(MAV_SEVERITY_INFO, " ahrsc %f %f %f\n",matx.c.x,matx.c.y,matx.c.z);
|
|
|
+
|
|
|
+ }
|
|
|
+ // Read the output of the z controller and rotate it so it always points up
|
|
|
+ //将Z轴输出变到机体坐标系
|
|
|
+ //Vector3f throttle_vehicle_frame = ahrs.get_rotation_body_to_ned().transposed() * Vector3f(0, 0, motors.get_throttle_in_bidirectional());
|
|
|
+ float z_throttle = pos_control.update_z_controller_f();//输出了set_throttle_out
|
|
|
+
|
|
|
+ Vector3f throttle_vehicle_frame = ahrs.get_rotation_body_to_ned().transposed() * Vector3f(0, 0, z_throttle);
|
|
|
+
|
|
|
+
|
|
|
+ //手柄控制和Z轴输出的叠加
|
|
|
+
|
|
|
+ motors.set_forward(-throttle_vehicle_frame.x +rc_throttle_vehicle_frame.x);
|
|
|
+ motors.set_lateral(-throttle_vehicle_frame.y +rc_throttle_vehicle_frame.y);//*0.6 变慢
|
|
|
+ motors.set_throttle(throttle_vehicle_frame.z +rc_throttle_vehicle_frame.z/2+0.5);
|
|
|
+ rov_message.pressure_level = int(PressLevel);
|
|
|
+ static uint16_t count3 = 0;
|
|
|
+ count3++;
|
|
|
+ if (count3>200)
|
|
|
+ {
|
|
|
+ count3 = 0;
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " rc_frame %f %f %f\n",z_throttle,throttle_vehicle_frame.z);
|
|
|
+
|
|
|
+ // gcs().send_text(MAV_SEVERITY_INFO, " rc_frame %f %f %f\n",rc_vehicle_frame.a.x,rc_vehicle_frame.a.y,rc_vehicle_frame.a.z);
|
|
|
+ // gcs().send_text(MAV_SEVERITY_INFO, " rc_frame %f %f %f\n",rc_vehicle_frame.b.x,rc_vehicle_frame.b.y,rc_vehicle_frame.b.z);
|
|
|
+ // gcs().send_text(MAV_SEVERITY_INFO, " rc_frame %f %f %f\n",rc_vehicle_frame.c.x,rc_vehicle_frame.c.y,rc_vehicle_frame.c.z);
|
|
|
+ //gcs().send_text(MAV_SEVERITY_INFO, " rc_throttle %f %f %f\n",rc_throttle.x,rc_throttle.y,rc_throttle.z);
|
|
|
+ // gcs().send_text(MAV_SEVERITY_INFO, " rc %f %f %f\n",rc_throttle_vehicle_frame.x,rc_throttle_vehicle_frame.y,rc_throttle_vehicle_frame.z);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ Vector3f earth_frame_rc_inputs = Vector3f(0.0, 0.0, 2*(gaindelay(1.0-(float)PressLevel_f*0.1,updowmgain)-0.5));//去掉侧移影响
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (fabsf(earth_frame_rc_inputs.z) > 0.05f) { // Throttle input above 5%
|
|
|
+ // reset z targets to current values
|
|
|
+ holding_depth = false;
|
|
|
+ pos_control.relax_alt_hold_controllers();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else { // hold z
|
|
|
+ if (ap.at_surface) { //最大油门不能向上动
|
|
|
+ pos_control.set_alt_target(g.surface_depth - 10.0f); // set target to 5cm below surface level
|
|
|
+ holding_depth = true;
|
|
|
+
|
|
|
+
|
|
|
+ } else if (ap.at_bottom) {//最大油门不能向下动
|
|
|
+ //pos_control.set_alt_target(inertial_nav.get_altitude() + 20.0f); // set target to 10 cm above bottom
|
|
|
+ pos_control.set_alt_target(barometer.get_altitude()*100 +20);//cm
|
|
|
+ holding_depth = true;
|
|
|
+
|
|
|
+
|
|
|
+ } else if (!holding_depth) {
|
|
|
+ //pos_control.set_target_to_stopping_point_z();//有对位置的付值
|
|
|
+ pos_control.calc_leash_length_z();//刹车长度 12.19
|
|
|
+ pos_control.set_alt_target(barometer.get_altitude()*100);//cm 当前深度
|
|
|
+
|
|
|
+ holding_depth = true;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ static bool lastdepth = holding_depth;
|
|
|
+ if(lastdepth !=holding_depth){
|
|
|
+ lastdepth = holding_depth;
|
|
|
+
|
|
|
+
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " get_alt_target %d %f \n",(int)holding_depth,motors.get_throttle());
|
|
|
+
|
|
|
+ }
|
|
|
+ static uint16_t count = 0;
|
|
|
+ count++;
|
|
|
+ if (count>200)
|
|
|
+ {
|
|
|
+ count = 0;
|
|
|
+
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " altitude %f %f %f \n",pos_control.get_alt_target(),barometer.get_altitude()*100,motors.get_throttle());
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " surface %d %d\n",(int)ap.at_surface,(int)ap.at_bottom);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
// althold_run - runs the althold controller
|
|
|
// should be called at 100hz or more
|
|
@@ -145,10 +343,15 @@ void Sub::sport_run()
|
|
|
//handle_attitude();
|
|
|
|
|
|
|
|
|
- pos_control.update_z_controller();
|
|
|
+ float z_throttle = pos_control.update_z_controller_f();//输出了set_throttle_out
|
|
|
|
|
|
// Read the output of the z controller and rotate it so it always points up
|
|
|
- Vector3f throttle_vehicle_frame = ahrs.get_rotation_body_to_ned().transposed() * Vector3f(0, 0, motors.get_throttle_in_bidirectional());
|
|
|
+
|
|
|
+ //变到机体坐标系
|
|
|
+ // Vector3f throttle_vehicle_frame = ahrs.get_rotation_body_to_ned().transposed() * Vector3f(0, 0, motors.get_throttle_in_bidirectional());
|
|
|
+ Vector3f throttle_vehicle_frame = ahrs.get_rotation_body_to_ned().transposed() * Vector3f(0, 0, z_throttle);
|
|
|
+
|
|
|
+
|
|
|
// Output the Z controller + pilot input to all motors.
|
|
|
|
|
|
//TODO: scale throttle with the ammount of thrusters in the given direction
|
|
@@ -156,26 +359,51 @@ void Sub::sport_run()
|
|
|
// motors.set_throttle(throttle_vehicle_frame.z + 1.0-(float)PressLevel_f*0.1);
|
|
|
|
|
|
motors.set_throttle(throttle_vehicle_frame.z + gaindelay(1.0-(float)PressLevel_f*0.1,updowmgain));
|
|
|
+
|
|
|
+ static uint16_t j=0;
|
|
|
+ j++;
|
|
|
+ if(j>300)
|
|
|
+ {
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " sportthrottle %f %f \n",z_throttle,throttle_vehicle_frame.z);
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " throttle %f %f\n",gaindelay(1.0-(float)PressLevel_f*0.1,updowmgain),motors.get_throttle());
|
|
|
+
|
|
|
+ j=0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
rov_message.pressure_level = int(PressLevel);
|
|
|
- motors.set_forward(constrain_float(-throttle_vehicle_frame.x + getgainf(channel_forward->norm_input()),-0.8,0.8));//*0.6 变慢
|
|
|
- motors.set_lateral(constrain_float(-throttle_vehicle_frame.y + getgainf(channel_lateral->norm_input()),-0.8,0.8));//*0.6 变慢
|
|
|
+ float forward = channel_forward->norm_input();
|
|
|
+ float lateral =channel_lateral->norm_input();
|
|
|
+ if (fabsf(forward)>=fabsf(lateral))
|
|
|
+ {
|
|
|
+ lateral = 0.0;
|
|
|
+ }else{
|
|
|
+ forward = 0.0;
|
|
|
+ }
|
|
|
+ motors.set_forward(constrain_float(-throttle_vehicle_frame.x + getgainf(forward),-0.8,0.8));//*0.6 变慢
|
|
|
+ motors.set_lateral(constrain_float(-throttle_vehicle_frame.y + getgainf(lateral),-0.8,0.8));//*0.6 变慢
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// We rotate the RC inputs to the earth frame to check if the user is giving an input that would change the depth.
|
|
|
//Vector3f earth_frame_rc_inputs = ahrs.get_rotation_body_to_ned() * Vector3f(channel_forward->norm_input(), channel_lateral->norm_input(), (2.0f*(-0.5f+channel_throttle->norm_input())));
|
|
|
//Vector3f earth_frame_rc_inputs = ahrs.get_rotation_body_to_ned() * Vector3f(channel_forward->norm_input(), channel_lateral->norm_input(), (2.0*(0.5-PressLevel_f*0.1)));
|
|
|
- Vector3f earth_frame_rc_inputs = ahrs.get_rotation_body_to_ned() * Vector3f(channel_forward->norm_input(), 0.0, (2.0*(0.5-PressLevel_f*0.1)));//去掉侧移影响
|
|
|
+ Vector3f earth_frame_rc_inputs1 = ahrs.get_rotation_body_to_ned() * Vector3f(channel_forward->norm_input(), 0.0, 2*(gaindelay(1.0-(float)PressLevel_f*0.1,updowmgain)-0.5));//去掉侧移影响
|
|
|
+ //Vector3f earth_frame_rc_inputs2 = ahrs.get_rotation_body_to_ned() * Vector3f(channel_forward->norm_input(), 0.0, motors.get_throttle_bidirectional());//去掉侧移影响
|
|
|
|
|
|
- if (fabsf(earth_frame_rc_inputs.z) > 0.05f) { // Throttle input above 5%
|
|
|
+
|
|
|
+ if (fabsf(earth_frame_rc_inputs1.z) > 0.05f) { // Throttle input above 5%
|
|
|
// reset z targets to current values
|
|
|
holding_depth = false;
|
|
|
pos_control.relax_alt_hold_controllers();
|
|
|
+
|
|
|
//pos_control.set_alt_target(barometer.get_altitude()*100);//当前深度
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
} else { // hold z
|
|
|
if (ap.at_surface) { //最大油门不能向上动
|
|
|
pos_control.set_alt_target(g.surface_depth - 10.0f); // set target to 5cm below surface level
|
|
|
holding_depth = true;
|
|
|
+
|
|
|
|
|
|
|
|
|
} else if (ap.at_bottom) {//最大油门不能向下动
|
|
@@ -183,47 +411,43 @@ void Sub::sport_run()
|
|
|
pos_control.set_alt_target(barometer.get_altitude()*100 +20);//cm
|
|
|
holding_depth = true;
|
|
|
|
|
|
+
|
|
|
|
|
|
} else if (!holding_depth) {
|
|
|
- //pos_control.set_target_to_stopping_point_z();//有对位置的付值
|
|
|
- pos_control.calc_leash_length_z();//刹车长度 12.19
|
|
|
- pos_control.set_alt_target(barometer.get_altitude()*100);//cm 当前深度
|
|
|
+
|
|
|
+
|
|
|
+ pos_control.calc_leash_length_z();//刹车长度 12.19
|
|
|
+ pos_control.set_alt_target(barometer.get_altitude()*100);//cm 当前深度
|
|
|
|
|
|
- holding_depth = true;
|
|
|
+ holding_depth = true;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //pos_control.set_target_to_stopping_point_z();//有对位置的付值
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-/*
|
|
|
-float rmpforward(float _gain){
|
|
|
- static uint16_t rmpcounter = 0;
|
|
|
- float get_forward_gain = motors.get_forward();
|
|
|
- float temp=0;
|
|
|
- rmpcounter++;
|
|
|
- if (rmpcounter>20)
|
|
|
- {
|
|
|
- rmpcounter =0;
|
|
|
- if(get_forward_gain - _gain>0.01){
|
|
|
- temp = get_forward_gain-0.01;
|
|
|
+ static bool lastdepth = holding_depth;
|
|
|
+ if(lastdepth !=holding_depth){
|
|
|
+ lastdepth = holding_depth;
|
|
|
|
|
|
- }else if(get_forward_gain- _gain<-0.01){
|
|
|
- temp = get_forward_gain+0.01;
|
|
|
- }
|
|
|
- else{
|
|
|
- temp = _gain;
|
|
|
- }
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " surface %d %d\n",(int)ap.at_surface,(int)ap.at_bottom);
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " get_alt_target %d %f %f \n",(int)holding_depth,gaindelay(1.0-(float)PressLevel_f*0.1,updowmgain),motors.get_throttle());
|
|
|
}
|
|
|
- if (_gain>0.3)
|
|
|
- {
|
|
|
- temp =constrain_float(temp,0.4,1.0);
|
|
|
- }else if(temp<-0.3){
|
|
|
- temp = constrain_float(temp,-1.0,-0.4);
|
|
|
- }else{
|
|
|
- temp=0.0;
|
|
|
+
|
|
|
+ static uint16_t count = 0;
|
|
|
+ count++;
|
|
|
+ if (count>300)
|
|
|
+ {
|
|
|
+ count = 0;
|
|
|
+
|
|
|
+
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " altitude %f %f \n",pos_control.get_alt_target(),barometer.get_altitude()*100);
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
|
|
|
+}
|
|
|
|
|
|
-}*/
|