#define LAND_DETECT_THRESHOLD 40 //Counts of land situation
//#define BAROPIDMIN -180 //BaroPID reach this if we landed..... Carlonb commented
//Check if we landed or not
void check_land() {
int16_t baropidmin; // Carlonb added
// Carlonb mod: BaroPID is related to Pterm of althold PID, if P=6.4 as per default, OK, BAROPIDMIN=-180 but if P=2.3 the max value of BaroPID will be -112, here will never stops motors.
// So, i've calculated some of these values changing the Pterm and I've found these results and put them in few if...
// The best and elegant coding is runtime pre-calc baropidmin avoiding all these if statements...I'm not able to do it.
if(conf.pid[PIDALT].P8 >= 60) baropidmin=-190; // BaroPID with P>=7.0 will be not grather than -209 // carlonb added
else if(conf.pid[PIDALT].P8 >= 50) baropidmin=-170; // carlonb added
else if(conf.pid[PIDALT].P8 >= 40) baropidmin=-145;
else if(conf.pid[PIDALT].P8 >= 30) baropidmin=-125;
else if(conf.pid[PIDALT].P8 >= 20) baropidmin=-100;
else if(conf.pid[PIDALT].P8 >= 10) baropidmin=-80;
else if(conf.pid[PIDALT].P8 >= 0) baropidmin=-55;
// detect whether we have landed by watching for low climb rate and throttle control
// if ( (abs(alt.vario) < 20) && (BaroPID < BAROPIDMIN)) { // carlonb commented
if ( (abs(alt.vario) < 20) && (BaroPID < baropidmin)) { // carlonb added
if (!f.LAND_COMPLETED) {
if( land_detect < LAND_DETECT_THRESHOLD) {
land_detect++;
} else {
f.LAND_COMPLETED = 1;
land_detect = 0;
}
}
} else {
// we've detected movement up or down so reset land_detector
land_detect = 0;
if(f.LAND_COMPLETED) {
f.LAND_COMPLETED = 0;
}
}
}
Return to Software development
Users browsing this forum: No registered users and 0 guests