Go Down

Topic: PPM RC receiver reading (Read 616 times) previous topic - next topic

lebenj

hi,

i'm trying to read only one channel on my RC receiver (Spektrum AR6100).
then move a servo with the servo.h librarie

my problem, is the same a several people: servo jitter....

when use a fixed false input, the servo does not jitter.

so i was playing with a simple sketch to read only the input value.
the result is clear, i don't have a fixed value, it's oscilating, a little, but enough to make jittet to the servo.

i'm sure there is a better way to read the input

my code:

Code: [Select]
void loop() {
    rxRposi = 0;
    for (int i = 0; i < rxRsamples; ++i) {
      rxRpos = pulseIn(pinRchannel, HIGH);
      rxRposi = rxRpos + rxRposi;
            if (rxRpos < rxRmini){
        rxRmini= rxRpos;
       }
       if (rxRpos > rxRmaxi){
        rxRmaxi = rxRpos;
       }
      //delay (2);
  }
    rxRpostotal = rxRposi;
    rxRposave = abs(rxRposi / (rxRsamples));
   
    //if (rxRposave == 0 || rxRposave < 1000 || rxRposave > 2000) {
     // return;
    //}
    //svRpos = map(rxRposave, 1000, 2000, 0, 180);
    //svRpos = constrain (svRpos, 0, 180);
 
    //rudder.write(svRpos);
    Serial.println("rxRpostotal....rxRposave....rxRsamples....rxRmini...rxRmaxi" );
    Serial.print("....");
    Serial.print(rxRpostotal);
    Serial.print(".........");
    Serial.print(rxRposave);
    Serial.print(".........");
    Serial.print(rxRsamples);
    Serial.print(".........");
    Serial.print(rxRmini);
    Serial.print(".........");
    Serial.println(rxRmaxi);
  }


thanks for your help


MarkT

You could add a little hysteresis to stop the jitter - if the input value varies less than a threshold from the currently used value, ignore the new input.  The threshold might be quite small like 1 or 2.  Alternatively a low-pass filter might be enough (it would lower the frequency of the jitter at expense of slowing the response to changes).
[ I won't respond to messages, use the forum please ]

Go Up