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 @chr1sa: Donkeycar 4.4 released with tons of new features, including path learning (useful with GPS outdoors), better Web and Lidar supp…
Sunday
DIY Robocars via Twitter
RT @NXP: We are already biting our nails in anticipation of the #NXPCupEMEA challenge! 😉 Did you know there are great cash prizes to be won…
Nov 24
DIY Robocars via Twitter
RT @gclue_akira: レースまであと3日。今回のコースは激ムズかも。あと一歩 #jetracer https://t.co/GKcEjImQ3t
Nov 24
DIY Robocars via Twitter
UC Berkeley's DIY robocar program https://roar.berkeley.edu/
Nov 24
DIY Robocars via Twitter
RT @chr1sa: The next @DIYRobocars autonomous car race at @circuitlaunch will be on Sat, Dec 10. Thrills, spills and a Brazilian BBQ. Fun…
Nov 24
DIY Robocars via Twitter
RT @arthiak_tc: Donkey car platform ... Still training uses behavioral cloning #TCXpo #diyrobocar @OttawaAVGroup https://t.co/PHBYwlFlnE
Nov 20
DIY Robocars via Twitter
RT @emurmur77: Points for style. @donkeycar racing in @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/Y2hMyj1…
Nov 20
DIY Robocars via Twitter
RT @SmallpixelCar: Going to @diyrobocars race at @UCSDJacobs https://t.co/Rrf9vDJ8TJ
Nov 8
DIY Robocars via Twitter
RT @SmallpixelCar: Race @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/kK686Hb9Ej
Nov 8
DIY Robocars via Twitter
RT @PiWarsRobotics: Presenting: the Hacky Racers Robotic Racing Series in collaboration with #PiWars. Find out more and register your inter…
Oct 23
DIY Robocars via Twitter
RT @Hacky_Racers: There will be three classes at this event: A4, A2, and Hacky Racer! A4 and A2 are based around UK paper sizing and existi…
Oct 23
DIY Robocars via Twitter
Oct 23
DIY Robocars via Twitter
Oct 19
DIY Robocars via Twitter
Oct 18
DIY Robocars via Twitter
RT @NeaveEng: Calling all UK based folks interested in @diyrobocars, @f1tenth, @donkey_car, and similar robot racing competitions! @hacky_r…
Oct 13
DIY Robocars via Twitter
RT @araffin2: 🏎️ After hours of video editing, I'm happy to share a best of my Twitch videos on learning to race with RL. 🏎️ Each part is…
Oct 13
More…