Pages: [1]   Go Down
Author Topic: PPM RC receiver reading  (Read 603 times)
0 Members and 1 Guest are viewing this topic.
Barcelona
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino hurts my brain... but i like it
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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

Logged

0
Online Online
Shannon Member
****
Karma: 220
Posts: 12710
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: