@@ -76,7 +76,7 @@ static void updateAltitudeVelocityController_MC(timeDelta_t deltaMicros)
7676 );
7777
7878 posControl .desiredState .pos .z = pos_desired_z ;
79-
79+
8080 // hard limit desired target velocity to max_climb_rate
8181 float vel_max_z = 0.0f ;
8282
@@ -119,11 +119,11 @@ static void updateAltitudeThrottleController_MC(timeDelta_t deltaMicros)
119119 // Calculate min and max throttle boundaries (to compensate for integral windup)
120120 const int16_t thrAdjustmentMin = (int16_t )getThrottleIdleValue () - (int16_t )currentBatteryProfile -> nav .mc .hover_throttle ;
121121 const int16_t thrAdjustmentMax = (int16_t )motorConfig ()-> maxthrottle - (int16_t )currentBatteryProfile -> nav .mc .hover_throttle ;
122-
122+
123123 float velocity_controller = navPidApply2 (& posControl .pids .vel [Z ], posControl .desiredState .vel .z , navGetCurrentActualPositionAndVelocity ()-> vel .z , US2S (deltaMicros ), thrAdjustmentMin , thrAdjustmentMax , 0 );
124-
124+
125125 posControl .rcAdjustment [THROTTLE ] = pt1FilterApply4 (& altholdThrottleFilterState , velocity_controller , NAV_THROTTLE_CUTOFF_FREQENCY_HZ , US2S (deltaMicros ));
126-
126+
127127 posControl .rcAdjustment [THROTTLE ] = constrain (posControl .rcAdjustment [THROTTLE ], thrAdjustmentMin , thrAdjustmentMax );
128128
129129 posControl .rcAdjustment [THROTTLE ] = constrain ((int16_t )currentBatteryProfile -> nav .mc .hover_throttle + posControl .rcAdjustment [THROTTLE ], getThrottleIdleValue (), motorConfig ()-> maxthrottle );
@@ -224,7 +224,7 @@ void resetMulticopterAltitudeController(void)
224224 pt1FilterReset (& altholdThrottleFilterState , 0.0f );
225225 pt1FilterReset (& posControl .pids .vel [Z ].error_filter_state , 0.0f );
226226 pt1FilterReset (& posControl .pids .vel [Z ].dterm_filter_state , 0.0f );
227-
227+
228228 if (FLIGHT_MODE (FAILSAFE_MODE ) || FLIGHT_MODE (NAV_RTH_MODE ) || FLIGHT_MODE (NAV_WP_MODE ) || navigationIsExecutingAnEmergencyLanding ()) {
229229 const float maxSpeed = getActiveWaypointSpeed ();
230230 nav_speed_up = maxSpeed ;
@@ -239,8 +239,8 @@ void resetMulticopterAltitudeController(void)
239239 sqrtControllerInit (
240240 & alt_hold_sqrt_controller ,
241241 posControl .pids .pos [Z ].param .kP ,
242- - fabsf (nav_speed_down ),
243- nav_speed_up ,
242+ - fabsf (nav_speed_down ),
243+ nav_speed_up ,
244244 nav_accel_z
245245 );
246246}
@@ -546,7 +546,7 @@ static void updatePositionAccelController_MC(timeDelta_t deltaMicros, float maxA
546546 // Calculate XY-acceleration limit according to velocity error limit
547547 float accelLimitX , accelLimitY ;
548548 const float velErrorMagnitude = calc_length_pythagorean_2D (velErrorX , velErrorY );
549-
549+
550550 if (velErrorMagnitude > 0.1f ) {
551551 accelLimitX = maxAccelLimit / velErrorMagnitude * fabsf (velErrorX );
552552 accelLimitY = maxAccelLimit / velErrorMagnitude * fabsf (velErrorY );
@@ -726,6 +726,7 @@ bool isMulticopterFlying(void)
726726 *-----------------------------------------------------------*/
727727bool isMulticopterLandingDetected (void )
728728{
729+ DEBUG_SET (DEBUG_LANDING , 4 , 0 );
729730 static timeUs_t landingDetectorStartedAt ;
730731 const bool throttleIsLow = calculateThrottleStatus (THROTTLE_STATUS_TYPE_RC ) == THROTTLE_LOW ;
731732
@@ -745,6 +746,8 @@ bool isMulticopterLandingDetected(void)
745746 posControl .actualState .velXY < MC_LAND_CHECK_VEL_XY_MOVING ;
746747 // check gyro rates are low (degs/s)
747748 bool gyroCondition = averageAbsGyroRates () < 2.0f ;
749+ DEBUG_SET (DEBUG_LANDING , 2 , velCondition );
750+ DEBUG_SET (DEBUG_LANDING , 3 , gyroCondition );
748751
749752 bool possibleLandingDetected = false;
750753 const timeUs_t currentTimeUs = micros ();
@@ -753,6 +756,7 @@ bool isMulticopterLandingDetected(void)
753756 // We have likely landed if throttle is 40 units below average descend throttle
754757 // We use rcCommandAdjustedThrottle to keep track of NAV corrected throttle (isLandingDetected is executed
755758 // from processRx() and rcCommand at that moment holds rc input, not adjusted values from NAV core)
759+ DEBUG_SET (DEBUG_LANDING , 4 , 1 );
756760
757761 static int32_t landingThrSum ;
758762 static int32_t landingThrSamples ;
@@ -774,7 +778,11 @@ bool isMulticopterLandingDetected(void)
774778 isAtMinimalThrust = rcCommandAdjustedThrottle < (landingThrSum / landingThrSamples - MC_LAND_DESCEND_THROTTLE );
775779
776780 possibleLandingDetected = isAtMinimalThrust && velCondition ;
781+
782+ DEBUG_SET (DEBUG_LANDING , 6 , rcCommandAdjustedThrottle );
783+ DEBUG_SET (DEBUG_LANDING , 7 , landingThrSum / landingThrSamples - MC_LAND_DESCEND_THROTTLE );
777784 } else { // non autonomous and emergency landing
785+ DEBUG_SET (DEBUG_LANDING , 4 , 2 );
778786 if (landingDetectorStartedAt ) {
779787 possibleLandingDetected = velCondition && gyroCondition ;
780788 } else {
@@ -790,6 +798,7 @@ bool isMulticopterLandingDetected(void)
790798 // surfaceMin is our ground reference. If we are less than 5cm above the ground - we are likely landed
791799 possibleLandingDetected = possibleLandingDetected && (posControl .actualState .agl .pos .z <= (posControl .actualState .surfaceMin + MC_LAND_SAFE_SURFACE ));
792800 }
801+ DEBUG_SET (DEBUG_LANDING , 5 , possibleLandingDetected );
793802
794803 if (possibleLandingDetected ) {
795804 timeUs_t safetyTimeDelay = MS2US (2000 + navConfig ()-> mc .auto_disarm_delay ); // check conditions stable for 2s + optional extra delay
0 commit comments