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

DIY Robocars via Twitter
RT @a1k0n: Did I get rid of hand-tuned parameters? Yes. Am I still hand-tuning more parameters? Also yes. I have a few knobs to address the…
Monday
DIY Robocars via Twitter
RT @a1k0n: I'm not going to spoil it, but (after charging the battery) this works way better than it has any right to. The car is now faste…
Monday
DIY Robocars via Twitter
RT @a1k0n: Decided to just see what happens if I run the sim-trained neural net on the car, with some safety rails around max throttle slew…
Monday
DIY Robocars via Twitter
Saturday
DIY Robocars via Twitter
RT @SmallpixelCar: @a1k0n @diyrobocars I learned from this. This is my speed profile. Looks like I am too conservative on the right side of…
Saturday
DIY Robocars via Twitter
RT @a1k0n: @SmallpixelCar @diyrobocars Dot color is speed; brighter is faster. Yeah, it has less room to explore in the tighter part, and t…
Saturday
DIY Robocars via Twitter
RT @a1k0n: I'm gonna try to do proper offline reinforcement learning for @diyrobocars and throw away all my manual parameter tuning for the…
Friday
DIY Robocars via Twitter
RT @circuitlaunch: DIY Robocars & Brazilian BBQ - Sat 10/1. Our track combines hairpin curves with an intersection for max danger. Take tha…
Sep 22
DIY Robocars via Twitter
RT @SmallpixelCar: Had an great test today on @RAMS_RC_Club track. However the car starts to drift at 40mph. Some experts recommended to ch…
Sep 11
DIY Robocars via Twitter
RT @gclue_akira: 世界最速 チームtamiyaのaiカー https://t.co/1Qq2zOeftG
Sep 10
DIY Robocars via Twitter
RT @DanielChiaJH: Always a good time working on my @diyrobocars car at @circuitlaunch. Still got some work to do if I’m to beat @a1k0n howe…
Sep 10
DIY Robocars via Twitter
RT @SmallpixelCar: My new speed profile for @RAMS_RC_Club track https://t.co/RtLb7TcgIJ
Sep 10
DIY Robocars via Twitter
RT @SmallpixelCar: Practiced at @RAMS_RC_Club today with my new @ARRMARC car https://t.co/AEu2hCx89T
Aug 28
DIY Robocars via Twitter
Aug 24
DIY Robocars via Twitter
RT @gclue_akira: 柏の葉で走行させてるjetracerの中身 #instantNeRF #jetracer https://t.co/giVvuE4hP7
Jul 4
DIY Robocars via Twitter
Cool web-based self-driving simulator. Click save when the AI does the right thing https://github.com/pncsoares/self-driving-car
Jul 4
More…