@@ -113,16 +113,15 @@ static void updateAltitudeVelocityController_MC(timeDelta_t deltaMicros)
113
113
static void updateAltitudeThrottleController_MC (timeDelta_t deltaMicros )
114
114
{
115
115
// Calculate min and max throttle boundaries (to compensate for integral windup)
116
- const int16_t thrAdjustmentMin = ( int16_t ) getThrottleIdleValue () - ( int16_t ) currentBatteryProfile -> nav .mc .hover_throttle ;
117
- const int16_t thrAdjustmentMax = ( int16_t ) motorConfig ()-> maxthrottle - ( int16_t ) currentBatteryProfile -> nav .mc .hover_throttle ;
116
+ const int16_t thrCorrectionMin = getThrottleIdleValue () - currentBatteryProfile -> nav .mc .hover_throttle ;
117
+ const int16_t thrCorrectionMax = motorConfig ()-> maxthrottle - currentBatteryProfile -> nav .mc .hover_throttle ;
118
118
119
- float velocity_controller = navPidApply2 (& posControl .pids .vel [Z ], posControl .desiredState .vel .z , navGetCurrentActualPositionAndVelocity ()-> vel .z , US2S (deltaMicros ), thrAdjustmentMin , thrAdjustmentMax , 0 );
119
+ float velocity_controller = navPidApply2 (& posControl .pids .vel [Z ], posControl .desiredState .vel .z , navGetCurrentActualPositionAndVelocity ()-> vel .z , US2S (deltaMicros ), thrCorrectionMin , thrCorrectionMax , 0 );
120
120
121
- posControl .rcAdjustment [THROTTLE ] = pt1FilterApply4 (& altholdThrottleFilterState , velocity_controller , NAV_THROTTLE_CUTOFF_FREQENCY_HZ , US2S (deltaMicros ));
121
+ int16_t rcThrottleCorrection = pt1FilterApply4 (& altholdThrottleFilterState , velocity_controller , NAV_THROTTLE_CUTOFF_FREQENCY_HZ , US2S (deltaMicros ));
122
+ rcThrottleCorrection = constrain (rcThrottleCorrection , thrCorrectionMin , thrCorrectionMax );
122
123
123
- posControl .rcAdjustment [THROTTLE ] = constrain (posControl .rcAdjustment [THROTTLE ], thrAdjustmentMin , thrAdjustmentMax );
124
-
125
- posControl .rcAdjustment [THROTTLE ] = constrain ((int16_t )currentBatteryProfile -> nav .mc .hover_throttle + posControl .rcAdjustment [THROTTLE ], getThrottleIdleValue (), motorConfig ()-> maxthrottle );
124
+ posControl .rcAdjustment [THROTTLE ] = constrain (currentBatteryProfile -> nav .mc .hover_throttle + rcThrottleCorrection , getThrottleIdleValue (), motorConfig ()-> maxthrottle );
126
125
}
127
126
128
127
bool adjustMulticopterAltitudeFromRCInput (void )
@@ -213,7 +212,7 @@ void resetMulticopterAltitudeController(void)
213
212
navPidReset (& posControl .pids .vel [Z ]);
214
213
navPidReset (& posControl .pids .surface );
215
214
216
- posControl .rcAdjustment [THROTTLE ] = 0 ;
215
+ posControl .rcAdjustment [THROTTLE ] = currentBatteryProfile -> nav . mc . hover_throttle ;
217
216
218
217
posControl .desiredState .vel .z = posToUse -> vel .z ; // Gradually transition from current climb
219
218
@@ -869,20 +868,19 @@ static void applyMulticopterEmergencyLandingController(timeUs_t currentTimeUs)
869
868
870
869
/* Attempt to stabilise */
871
870
rcCommand [YAW ] = 0 ;
871
+ rcCommand [ROLL ] = 0 ;
872
+ rcCommand [PITCH ] = 0 ;
873
+ rcCommand [THROTTLE ] = currentBatteryProfile -> failsafe_throttle ;
872
874
873
- if (( posControl . flags . estAltStatus < EST_USABLE )) {
874
- /* Sensors has gone haywire, attempt to land regardless */
875
+ /* Altitude sensors gone haywire, attempt to land regardless */
876
+ if ( posControl . flags . estAltStatus < EST_USABLE ) {
875
877
if (failsafeConfig ()-> failsafe_procedure == FAILSAFE_PROCEDURE_DROP_IT ) {
876
878
rcCommand [THROTTLE ] = getThrottleIdleValue ();
877
879
}
878
- else {
879
- rcCommand [THROTTLE ] = currentBatteryProfile -> failsafe_throttle ;
880
- }
881
-
882
880
return ;
883
881
}
884
882
885
- // Normal sensor data
883
+ // Normal sensor data available, use controlled landing descent
886
884
if (posControl .flags .verticalPositionDataNew ) {
887
885
const timeDeltaLarge_t deltaMicrosPositionUpdate = currentTimeUs - previousTimePositionUpdate ;
888
886
previousTimePositionUpdate = currentTimeUs ;
@@ -903,15 +901,12 @@ static void applyMulticopterEmergencyLandingController(timeUs_t currentTimeUs)
903
901
posControl .flags .verticalPositionDataConsumed = true;
904
902
}
905
903
906
- // Update throttle controller
904
+ // Update throttle
907
905
rcCommand [THROTTLE ] = posControl .rcAdjustment [THROTTLE ];
908
906
909
907
// Hold position if possible
910
908
if ((posControl .flags .estPosStatus >= EST_USABLE )) {
911
909
applyMulticopterPositionController (currentTimeUs );
912
- } else {
913
- rcCommand [ROLL ] = 0 ;
914
- rcCommand [PITCH ] = 0 ;
915
910
}
916
911
}
917
912
0 commit comments