Fail safe in PPM setup

Recently i faced a problem with my Quad and ArduCopter v.2.7.x. Im using a APM2 with PPM setup, so the PPM signal is feeded directly from the RC receiver into the ATmega. Depending on the receiver you use, the PPM signal provided by the receiver doesn't matches the signal output at the normal servo  pins in case of fail safe. My receiver simply stops sending PPM out if it recognizes a fail safe situation. I think it's the right behavior to indicate a error situation. The problem is, that the actual ArduCopter code can't handle this situation correctly. The code handles such situation (no PPM input) as "position hold", the last "good" signal input is "frozen".

Actual implementation of APM_RC_APMx depends on the timer compare interrupt which is not triggered due the absence of the PPM signal, check void APM_RC_APMx::_timer5_capt_cb(void).

A possible solution for this problem is to implement a simple watchdog that checks for the absence of PPM signal for ie. 3sec and then triggers the fail safe event. A sample code could look like this, which has been implemented in the 50Hz user hook:

void userhook_50Hz()
{
// put your 50Hz code here
#ifdef PPM_WATCHDOG
//PPM watchdog
static uint16_t old_icr = 0;
static uint8_t icr_same_count = 0;

if(motors.armed()) { //we are up in the sky
#if CONFIG_APM_HARDWARE == APM_HARDWARE_APM2
  uint16_t icr = ICR5;
#endif
#if CONFIG_APM_HARDWARE == APM_HARDWARE_APM1
  uint16_t icr = ICR4;
#endif
  if(icr != old_icr) {
  old_icr = icr; //everything ok, ICR4/5 changed
  if(icr_same_count != 0)
  icr_same_count = 0;
  if(failsafe) {
  //clean fail safe state
   set_failsafe(false);
  }
} else {
 //same value?
 if(icr_same_count > PPM_WATCHDOG_TRIGGER * 50) {
  //about 3sec without a change, DO something!
  if(!failsafe)
    set_failsafe(true);
} else {
    icr_same_count++;
  }
}
}

//
#endif

}

Sorry, no idea how to format this code right in this editor..

First results looks promising. What do you think about this solution approach? 

Regards

 Adam

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Hi Adam,

     

    I also have the problem with the Graupner RX. It sends 20mS pulses out the PPM with no RX signal, so I made there changes to implement Failsafe.

     

    This now works as expected. It also allows you to use PPM directly into the Mega..

     

    In APM_RC_APM2.ccp

    *****************************************************************

        icr = ICR5;
        // Calculate pulse width assuming timer overflow TOP = 40000
        if ( icr < prev_icr ) {
            pwidth = ( icr + 40000 ) - prev_icr;
        } else {
            pwidth = icr - prev_icr;
        }

     // Basic Sanity check for Graupner RX in PPM mode
     if ( pwidth > ( MIN_PULSEWIDTH * 2 ) ) {  // This is .5uS counts
      // Was it a sync pulse? If so, reset frame.
      if ( pwidth > 8000 ) {
       frame_idx=0;
      } else {
       // Save pulse into _PWM_RAW array.
       if ( frame_idx < NUM_CHANNELS ) {
        _PWM_RAW[ frame_idx++ ] = pwidth;
        // If this is the last pulse in a frame, set _radio_status.
        if (frame_idx >= NUM_CHANNELS) {
         _radio_status = 1;
        }
       }
      }
     }
        // Save icr for next call.
        prev_icr = icr;

    ****************************************************************

    In Radio.ino

    *****************************************************************

    static void read_radio()
    {

        if (APM_RC.GetState() == 1) {
            new_radio_frame = true;
            g.rc_1.set_pwm(APM_RC.InputCh(CH_1));
            g.rc_2.set_pwm(APM_RC.InputCh(CH_2));
            g.rc_3.set_pwm(APM_RC.InputCh(CH_3));
            g.rc_4.set_pwm(APM_RC.InputCh(CH_4));
            g.rc_5.set_pwm(APM_RC.InputCh(CH_5));
            g.rc_6.set_pwm(APM_RC.InputCh(CH_6));
            g.rc_7.set_pwm(APM_RC.InputCh(CH_7));
            g.rc_8.set_pwm(APM_RC.InputCh(CH_8));

    #if FRAME_CONFIG != HELI_FRAME
            // limit our input to 800 so we can still pitch and roll
            g.rc_3.control_in = min(g.rc_3.control_in, MAXIMUM_THROTTLE);
    #endif

            throttle_failsafe(g.rc_3.radio_in);
      radio_fail_counter = 0;    // Restart the fail counter
        } else {
      if ( radio_fail_counter++ > 20 ) {     // we are in here every 10mS
            g.rc_3.set_pwm(900);
            throttle_failsafe(g.rc_3.radio_in);
      radio_fail_counter = 20;
      }
     }
    }

     

    *************************************************************

  • You clearly are going along the same lines as I do :-) (Graupner hardware, simple wiring) i was going to write to Jordi Muniz (the author of the PPM decoding software) about this and ask for a timeout...

    My proposal was centered around the radio_status variable in his software.

    Otto

This reply was deleted.

Activity