@ -509,7 +509,7 @@ void Mode::make_safe_spool_down()
int32_t Mode : : get_alt_above_ground_cm ( void )
int32_t Mode : : get_alt_above_ground_cm ( void )
{
{
int32_t alt_above_ground ;
int32_t alt_above_ground ;
if ( copter . rangefinder_alt_ok ( ) ) {
if ( copter . rangefinder_alt_ok ( ) & & copter . current_loc . alt < g . land_slow_2nd_alt ) {
alt_above_ground = copter . rangefinder_state . alt_cm_filt . get ( ) ;
alt_above_ground = copter . rangefinder_state . alt_cm_filt . get ( ) ;
} else {
} else {
bool navigating = pos_control - > is_active_xy ( ) ;
bool navigating = pos_control - > is_active_xy ( ) ;
@ -533,18 +533,10 @@ void Mode::land_run_vertical_control(bool pause_descent)
const float precland_acceptable_error = 15.0f ;
const float precland_acceptable_error = 15.0f ;
const float precland_min_descent_speed = 10.0f ;
const float precland_min_descent_speed = 10.0f ;
// modify by @Brown , Staging land speed control
// modify by @Brown , Staging land speed control
if ( get_alt_above_ground_cm ( ) < 100 )
int16_t land_speed_now = g . land_speed ;
g . land_speed = 20 ;
if ( get_alt_above_ground_cm ( ) < g . land_slow_2nd_alt )
else if ( get_alt_above_ground_cm ( ) < 500 )
land_speed_now = g . land_speed_2nd ;
g . land_speed = 30 ;
else if ( get_alt_above_ground_cm ( ) < 1000 )
g . land_speed = 50 ;
else if ( get_alt_above_ground_cm ( ) < 2000 )
g . land_speed = 100 ;
else if ( get_alt_above_ground_cm ( ) < 3000 )
g . land_speed = 150 ;
float cmb_rate = 0 ;
float cmb_rate = 0 ;
if ( ! pause_descent ) {
if ( ! pause_descent ) {
@ -556,16 +548,19 @@ void Mode::land_run_vertical_control(bool pause_descent)
}
}
// Don't speed up for landing.
// Don't speed up for landing.
max_land_descent_velocity = MIN ( max_land_descent_velocity , - abs ( g . land_speed ) ) ;
// max_land_descent_velocity = MIN(max_land_descent_velocity, -abs(g.land_speed));
max_land_descent_velocity = MIN ( max_land_descent_velocity , - abs ( land_speed_now ) ) ;
// Compute a vertical velocity demand such that the vehicle approaches g2.land_alt_low. Without the below constraint, this would cause the vehicle to hover at g2.land_alt_low.
// Compute a vertical velocity demand such that the vehicle approaches g2.land_alt_low. Without the below constraint, this would cause the vehicle to hover at g2.land_alt_low.
cmb_rate = AC_AttitudeControl : : sqrt_controller ( MAX ( g2 . land_alt_low , 100 ) - get_alt_above_ground_cm ( ) , pos_control - > get_pos_z_p ( ) . kP ( ) , pos_control - > get_max_accel_z ( ) , G_Dt ) ;
cmb_rate = AC_AttitudeControl : : sqrt_controller ( MAX ( g2 . land_alt_low , 100 ) - get_alt_above_ground_cm ( ) , pos_control - > get_pos_z_p ( ) . kP ( ) , pos_control - > get_max_accel_z ( ) , G_Dt ) ;
// Constrain the demanded vertical velocity so that it is between the configured maximum descent speed and the configured minimum descent speed.
// Constrain the demanded vertical velocity so that it is between the configured maximum descent speed and the configured minimum descent speed.
cmb_rate = constrain_float ( cmb_rate , max_land_descent_velocity , - abs ( g . land_speed ) ) ;
// cmb_rate = constrain_float(cmb_rate, max_land_descent_velocity, -abs(g.land_speed));
cmb_rate = constrain_float ( cmb_rate , max_land_descent_velocity , - abs ( land_speed_now ) ) ;
if ( doing_precision_landing & & copter . rangefinder_alt_ok ( ) & & copter . rangefinder_state . alt_cm > 35.0f & & copter . rangefinder_state . alt_cm < 200.0f ) {
if ( doing_precision_landing & & copter . rangefinder_alt_ok ( ) & & copter . rangefinder_state . alt_cm > 35.0f & & copter . rangefinder_state . alt_cm < 200.0f ) {
float max_descent_speed = abs ( g . land_speed ) * 0.5f ;
// float max_descent_speed = abs(g.land_speed)*0.5f;
float max_descent_speed = abs ( land_speed_now ) * 0.5f ;
float land_slowdown = MAX ( 0.0f , pos_control - > get_horizontal_error ( ) * ( max_descent_speed / precland_acceptable_error ) ) ;
float land_slowdown = MAX ( 0.0f , pos_control - > get_horizontal_error ( ) * ( max_descent_speed / precland_acceptable_error ) ) ;
cmb_rate = MIN ( - precland_min_descent_speed , - max_descent_speed + land_slowdown ) ;
cmb_rate = MIN ( - precland_min_descent_speed , - max_descent_speed + land_slowdown ) ;
}
}
@ -637,6 +632,30 @@ void Mode::land_run_horizontal_control()
pos_control - > override_vehicle_velocity_xy ( - target_vel_rel ) ;
pos_control - > override_vehicle_velocity_xy ( - target_vel_rel ) ;
}
}
# endif
# endif
static uint8_t prt_once ;
// bool land_lock_attitude = (get_alt_above_ground_cm() < g.land_lock_alt * 2) && copter.rangefinder_alt_ok() && g.land_lock_alt && (copter.control_mode == Mode::Number::LAND);
bool land_lock_attitude = ( get_alt_above_ground_cm ( ) < g . land_lock_alt * 4 ) & & g . land_lock_alt & & ( copter . control_mode = = Mode : : Number : : LAND ) ;
if ( land_lock_attitude )
{
if ( prt_once = = 0 )
{
gcs ( ) . send_text ( MAV_SEVERITY_INFO , " Land ready to enter attitude lock mode " ) ;
copter . Log_Write_Event ( DATA_LAND_READY_LOCK ) ;
prt_once = 1 ;
}
if ( copter . rangefinder_state . alt_cm_filt . get ( ) < g . land_lock_alt * 2 ) {
target_roll = 0 ;
target_pitch = 0 ;
target_yaw_rate = 0 ;
loiter_nav - > soften_for_landing ( ) ;
if ( prt_once = = 1 )
{
gcs ( ) . send_text ( MAV_SEVERITY_INFO , " Land Lock attitude! " ) ;
copter . Log_Write_Event ( DATA_LAND_LOCK_ATT ) ;
prt_once = 2 ;
}
}
}
// process roll, pitch inputs
// process roll, pitch inputs
loiter_nav - > set_pilot_desired_acceleration ( target_roll , target_pitch , G_Dt ) ;
loiter_nav - > set_pilot_desired_acceleration ( target_roll , target_pitch , G_Dt ) ;