koenkooi / multiwii-firmware

Firmware - GitHub mirror of the official SVN multiwii project
https://github.com/multiwii/multiwii-firmware/wiki
13 stars 1 forks source link

Failsafe mode does not work #17

Closed Arne-W closed 10 years ago

Arne-W commented 10 years ago

The failsafe mode does not work cause of the rcSerialCount decreases to 0 if the controller disconnects. If its 0 the code sets the input values to 1500 (see #16 ).

To fix this we have to do some changes:

The failsafe mode must be enabled :-) https://github.com/koenkooi/multiwii-firmware/blob/pruts/config.h#L577

The normal RC should be disabled by inserting #if !defined(RC_TINY) after line https://github.com/koenkooi/multiwii-firmware/blob/pruts/RX.cpp#L424 and the #endif after line https://github.com/koenkooi/multiwii-firmware/blob/pruts/RX.cpp#L440 should look like this:

 for (chan = 0; chan < RC_CHANS; chan++) {
#if !defined(RC_TINY)
      rcDataTmp = readRawRC(chan);
#if defined(FAILSAFE)
        failsafeGoodCondition = rcDataTmp>FAILSAFE_DETECT_TRESHOLD || chan > 3 || !f.ARMED; // update controls channel only if pulse is above FAILSAFE_DETECT_TRESHOLD
#endif // In disarmed state allow always update for easer configuration.
#if defined(SPEKTRUM) || defined(SBUS) // no averaging for Spektrum & SBUS signal
        if(failsafeGoodCondition) rcData[chan] = rcDataTmp;
#else
        if(failsafeGoodCondition) {
          rcDataMean = rcDataTmp;
          for (a=0;a<AVERAGING_ARRAY_LENGTH-1;a++) rcDataMean += rcData4Values[chan][a];
          rcDataMean = (rcDataMean+(AVERAGING_ARRAY_LENGTH/2))/AVERAGING_ARRAY_LENGTH;
          if ( rcDataMean < (uint16_t)rcData[chan] -3) rcData[chan] = rcDataMean+2;
          if ( rcDataMean > (uint16_t)rcData[chan] +3) rcData[chan] = rcDataMean-2;
          rcData4Values[chan][rc4ValuesIndex] = rcDataTmp;
        }
#endif
#endif
      if (chan<8 && rcSerialCount > 0) { // rcData comes from MSP and overrides RX Data until rcSerialCount reaches 0
        rcSerialCount --;
#if defined(FAILSAFE)
          failsafeCnt = 0;
#endif
        if (rcSerial[chan] >900) {rcData[chan] = rcSerial[chan];} // only relevant channels are overridden
      }
    }

And last but not least I think there is a bug in the failsafe code. https://github.com/koenkooi/multiwii-firmware/blob/pruts/MultiWii.cpp#L815 It should look like this (see the braces) ?!

  if ((failsafeCnt > (5*FAILSAFE_DELAY)) && f.ARMED) { 

These changes will force the copter into failsafe mode as soon as rcSerialCount reaches 0 and FAILSAFE_DELAY passed by.

I did some synthetic testing (not really flying) yesterday and it seems to be working. With this changes it should be safe to fly outside without any ceiling.

koenkooi commented 10 years ago

The 'pruts' and 'integration' branch should have all the changes you mentioned.

Arne-W commented 10 years ago

Hey KoenKooi - you are incredible fast - thank you for that!!