I tried to make a simple implementation of altitude control in ALT mode.
The basic idea is that depending on the stick position, I change the value of AltHold.
Here are my changes (in Multiwii 2.0):
in multiwii.ino, define these values:
Code: Select all
static uint32_t currentTime2 = 0;
static uint32_t varioTime = 0;
then replace this part:
Code: Select all
#if BARO
if (baroMode) {
if (abs(rcCommand[THROTTLE]-initialThrottleHold)>20) {
baroMode = 0; // so that a new althold reference is defined
}
rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
}
#endif
with this:
Code: Select all
#if BARO
currentTime2=millis();
if (baroMode) {
if ( ((rcCommand[THROTTLE]-initialThrottleHold)>ALT_HOLD_THR_DEADBAND) && ((currentTime2 - varioTime)>100) ) {
//baroMode = 0; // so that a new althold reference is defined
AltHold = AltHold + (VARIO_SCALE*(rcCommand[THROTTLE]-initialThrottleHold))/100;
varioTime = currentTime2;
}
else if ( ((initialThrottleHold-rcCommand[THROTTLE])>ALT_HOLD_THR_DEADBAND) && ((currentTime2 - varioTime)>100) ) {
//baroMode = 0; // so that a new althold reference is defined
AltHold = AltHold - (VARIO_SCALE*(initialThrottleHold-rcCommand[THROTTLE]))/100;
varioTime = currentTime2;
}
rcCommand[THROTTLE] = initialThrottleHold + BaroPID;
}
#endif
and finally define these in config.h:
Code: Select all
#define ALT_HOLD_THR_DEADBAND 50 //deadband around setpoint throttle value
#define VARIO_SCALE 1 //relation between vario and throttle stick
Changing the value of VARIO_SCALE will change the raising/descending speed.
CAUTION!!! I tested this code till now only with gui or in my living room since we have ..... strong wind nowasays in Hungary, so try it on your own risk!!!!! Please note that using these changes, when ALT mode is activated, you will NOT have direct relation between throttle stick and real throttle, so this code needs as good ALT_HOLD PID settings as it can be!!!
Any comments are wellcome, since I don't have much programming skills, just pure logics...
BR
Adrian