Servo Jitter

Hello guys,

I'm totally new to Arduino, this is my first project out of the 15 projects that came along with my kit.

I searched over the web but couldn't find an answer to my question.

I'm a longtime RC modelist from France (sorry for bad english ;)).

I own a Futaba 6J radio system with a Futaba R2006GS receiver, so it's a 6 channel system.

For the purpose of controlling a RC device truck with lots of functions I need 9 functions (not all at the same time), that's why I thought my Arduino Uno might be helpfull.

I would like to be able to flip a switch on the transmitter so that I can have two mods like mode1: driving and mode2: accessories.

To be clearer I would like 2 options.
Switch is off
ch1=>servo 1
ch2 =>servo 2
ch3 =>servo 3
ch4 =>servo 4

switch is flipped
ch1 =>servo 5
ch2 =>servo 6
ch3 =>servo7
ch4 =>servo 8

the switch is ch5.

I wrote the following code wich works but I end up with jitter in the servo wich I think is produced by the translation from PWM to time, then from time to angle and then sent back to the servo.

#include <Servo.h>
Servo myServoBlack;
Servo myServoOrange;

int ch5;
int ch4;
int angle;

void setup() {
 
 myServoBlack.attach(3);
 myServoOrange.attach(2);  
 pinMode(4, INPUT);
 pinMode(5, INPUT);
 
 
 Serial.begin(9600);

}

void loop() {
 
 ch4 = pulseIn(4, HIGH, 25000);
 ch5 = pulseIn(5, HIGH, 25000);
 
 Serial.print("Channel 4: ");
 Serial.print(ch4);
 
 Serial.print(" , Channel 5: ");
 Serial.print(ch5);
 
 angle = map(ch4,1050,1950,0,179);
 Serial.print(" , angle: ");
 Serial.println(angle);
 
 if(ch5 < 1500){
 myServoBlack.write(angle);
 myServoOrange.write (90);

 }else if(ch5 > 1000) {
 myServoBlack.write(90);
 myServoOrange.write(angle);
 }
 
   
 delay(10);

}

Is there a way to avoid the jitter ?
Or something simpler like directly taking the value from the receiver with let's say input2 and sending it to output 3 or 4 depending of the position of the switch?

Hope it's clear :wink:

Thanks for your help!!

Hello Ockay16,

Please edit your post so your sketch is in code tags. Your sketch will be easier to analyze.

Image taken from How to use this forum - please read.

Can you be more specific about the "jitter"?

  ch4 = pulseIn(4, HIGH, 25000);
  ch5 = pulseIn(5, HIGH, 25000);
 
  Serial.print("Channel 4: ");
  Serial.print(ch4);
 
  Serial.print(" , Channel 5: ");
  Serial.print(ch5);

What is the "pulseIn(4, HIGH, 25000)" connected to?

What does this part of your code show in the Serial monitor?

Does "ch4" have fairly stable value or does it change rapidly?
If it rapidly changing back and forth, it will effect your "angle" value that you are sending to your servo, "angle = map(ch4,1050,1950,0,179);"

Last thought, I have servos that do not operate as well at the ends of the range. If you can sacrifice some range try something like... angle = map(ch4,1050,1950,10,170);

You need to find out where the jitter is coming from. So start with a 2 or 3 line program that just initializes a servo and causes it to move to (say) 90 degrees. If there is jitter with that simple program there is no point in wondering about any more complicated program.

...R

Hello Birddog and Robin2, and thank you for your answer.
I'm sorry to come back only now, I don't know what happened but I never got any notification saying someone replied to my post so I assumed no one did.

I'm not working on this project anymore but I'll go back to it since it might be really useful for me in the futur and might also inspire others.

Birddog, the "pulseIn(4, HIGH, 25000)" is connected to my Futaba R2006GS to the channel 4 my objective was to read the signal from the receiver and copy paste it to either one of the servos.

The CH4 value is "oscillating", so I'm pretty sure that's where the jitter was from but I don't understand why these numbers where oscillating but when my servo is directly plugged to the receiver it's perfectly still.

No jitter from your RC receiver is a decent indication that it is producing a clean servo signal.

I do not care for pulseIn as a way to read RC receiver data. A method that uses interrupts is a bit harder to work through but I think it is worth the effort.

First, follow Robin2's advice and write a simple sketch that moves the servo to a fixed position and does nothing else. Any jitter?

Now, instead of pulseIn, read up on a few pages that discuss it in detail (with code)

http://playground.arduino.cc/Code/ReadReceiver

Thanks guys, as soon as I have some spare time I'll give it a go.
I'm pretty sure everything I need is there: Reading Remote Control Receiver Values with Arduino | Ryan Boland
Thanks vinceherman!!