Hi!
I did a slight improvement of my interpretation of mahowiks great work.
Just alter my version posted here:
viewtopic.php?f=8&t=2371&start=110#p22860to improve the hightchange with the throttlestick.
*******************************************************************************************************************************
EDIT: This is experimental, with low acc "I" the performance of althold can be worsened
*******************************************************************************************************************************
Find this in the mainprogram (MultiWii_2_1_NewBaroPIDVario3) at line 962 and delete it:
Code: Select all
#if BARO
Baro_update(); // Do Baro every time!
getEstimatedAltitude();
if (currentTime >= ThrTime){ // Get ThrottleRate in Ticks/sec Upmovement=+ Polling at 10Hz
ThrTime = currentTime+100000;
ThrottleRate = (rcCommand[THROTTLE]-LastThrottle)*10;
if (abs(ThrottleRate) < 150) ThrottleRate = 0;
LastThrottle=rcCommand[THROTTLE];}
if (rcOptions[BOXBARO]){ // New Logic: When User exceeds neutral zone and stops fiddeling with throttle, then after 1 second a new Althold is defined
if (abs(rcCommand[THROTTLE] - initialThrottleHold)<ALT_HOLD_THROTTLE_NEUTRAL_ZONE && HightChange==0){
rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
rcCommand[THROTTLE] = constrain(rcCommand[THROTTLE],MINTHROTTLE+1,MAXTHROTTLE-50);}
else {
HightChange=1;
if (ThrottleRate==0 && AltHoldBlindTimer==0) AltHoldBlindTimer = currentTime+AltHoldBlindTime;}
if (ThrottleRate !=0) AltHoldBlindTimer = 0;
if (currentTime >= AltHoldBlindTimer && AltHoldBlindTimer !=0) f.BARO_MODE = 0; // Set new ref hight
}
#endif
Replace with this:
Code: Select all
#if BARO
Baro_update(); // Do Baro every time!
getEstimatedAltitude();
if (rcOptions[BOXBARO])
{
int16_t ActualThr=rcCommand[THROTTLE];
if (currentTime >= ThrTime){ // 10Hz Loop Get ThrottleRate in 10Ticks/sec Upmovement=+
ThrTime = currentTime+100000;
ThrottleRate = (ActualThr-LastThrottle);
if (abs(ThrottleRate) < 15) ThrottleRate = 0;
else AltHoldBlindTimer=0;
if (abs(ActualThr-initialThrottleHold)>ALT_HOLD_THROTTLE_NEUTRAL_ZONE) HightChange=1;
LastThrottle=ActualThr;}
if (HightChange==0) rcCommand[THROTTLE] = initialThrottleHold+BaroPID;
else{
rcCommand[THROTTLE] = ActualThr+constrain(BaroPID,-ALT_HOLD_THROTTLE_NEUTRAL_ZONE,ALT_HOLD_THROTTLE_NEUTRAL_ZONE);
if (ThrottleRate==0 && AltHoldBlindTimer==0) AltHoldBlindTimer = currentTime+AltHoldBlindTime;}
if (currentTime >= AltHoldBlindTimer && AltHoldBlindTimer !=0) f.BARO_MODE = 0;
rcCommand[THROTTLE] = constrain(rcCommand[THROTTLE],MINTHROTTLE+1,MAXTHROTTLE-50);
}
#endif
I tested it with config.h:
#define ALT_HOLD_THROTTLE_NEUTRAL_ZONE 20
#define AltHoldBlindTime 500000
During hightchange "Baropid" is constantly done with the last althold in mind in the range of ALT_HOLD_THROTTLE_NEUTRAL_ZONE. This smoothes out the transition with the throttlestick.
@Hamburger: Thank you for the config - hint !!
And btw i did a "SUPPRESS_BARO_ALTHOLD" mod - this saves over 900 Bytes.
My approach of moving average with "while" loop is not so nice like marbalons moving average but it saves 25 Bytes (tried both). Adding 8 bytes in a loop and 5 longwords in a loop is done very quickly.
BTW: My getEstimatedAltitude has a good timebase of 30ms. This is done by synchronizing with the baroreadout (newbaroalt). Both baro read outs (MS&BMP) are optimized to put out a new value every 30ms. Acc calculations are done on every runtime and drift is compensated every 30ms.
So long
Crashpilot1000