Go Down

Topic: servo keep shaking (Read 1 time) previous topic - next topic

1035700564

I want to use RC to control four servos.

I have arduino mega and connect pin 22,24,26,28 to receiver. the PWM signal from serial printer is accurate from 1100 to 1900.

But when connect the four servo to pin 8,9,10,11. the servo will keep shaking even I dont move the joystick.

When connect servo directly to receiver, it doesnot shake and can be controled.

the code to drive the servo is here
Code: [Select]
#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

int ch1,ch2,ch3,ch4;
int m1,m2,m3,m4;
//int signal=1500;

void setup() {
  pinMode(22, INPUT);
  pinMode(24, INPUT);
  pinMode(26, INPUT);
  pinMode(28, INPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  servo1.attach(8);
  servo2.attach(9);
  servo3.attach(10);
  servo4.attach(11);
  Serial.begin(9600);
}

void loop() {
  ch1 = pulseIn(22, HIGH, 25000);
  ch2 = pulseIn(24, HIGH, 25000);
  ch3 = pulseIn(26, HIGH, 25000);
  ch4 = pulseIn(28, HIGH, 25000);
  /*if(ch1<1550&&ch1>1450)
  ch1=1500;
  if(ch2<1550&&ch2>1450)
  ch2=1500;
  if(ch3<1550&&ch3>1450)
  ch3=1500;
  if(ch4<1550&&ch4>1450)
  ch4=1500;
 
 if(ch2>1400&&ch2<1600)
  {
    m1=ch3;
    m3=m1;
    m2=ch4;
    m4=m2;
  }
  else
  {
    m1=ch2;
    m3=3000-ch2;
    m2=ch2;
    m4=3000-ch2;
  }*/

   
  servo1.write(ch1);
  servo2.write(ch2);
  servo3.write(ch3);
  servo4.write(ch4);
  delay(10);

}

MarkT

Any interrupt routines in your sketch?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

vinceherman

What values are you getting from your pulsein commands?
In your setup, put this
Serial.begin(9600);

Then in your loop, after you get the 4 values from pulse in, put something like this:
Serial.print("CH1 is:");
Serial.print(ch1);
Serial.print("  CH2 is:");
Serial.print(ch2);
Serial.print("  CH3 is:");
Serial.print(ch3);
Serial.print("  CH4 is:");
Serial.println(ch4);

TomGeorge

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What have you got powering your project, especially the servos?

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

jremington

Do not power servos or motors from the Arduino.

1035700564

hi

at first I also thought that the PWM signal from transmitter keep changing which leads to the servo shaking, but later when i connect the receiver directly to receiver the servo can work well without shaking. also i print the PWM signal, it's not that stable but will only change within 10(like 1500 to 1510), which cannot cause the servo shake so much, that's why I feel it's not because of the input signal.

I also have checked is it because of the servo library. i write the code just to drive the servo from 1900 to 1100 for one second and loop forever. no shaking at all.

I know Arduino cannot drive sufficient current for four servo, I have connect them to a five volt battery.


later i try another code with a "filter" i created. It can work well without shaking, but a new problem comes.

the resolution will decrease. only 1500, 1550,1600,1650......

i want to test on servo because later i'm going to connect to four ESC and blue robotis T100. any suggestion before I try the code on motor?

thank you very much for your help!

the code is below.

Code: [Select]
#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

int c1,c2,c3,c4;
int ch1=1500,ch2=1500,ch3=1500,ch4=1500;
int m1,m2,m3,m4;
//int signal=1500;

void setup() {
  pinMode(22, INPUT);
  pinMode(24, INPUT);
  pinMode(26, INPUT);
  pinMode(28, INPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  servo1.attach(8);
  servo2.attach(9);
  servo3.attach(10);
  servo4.attach(11);
  Serial.begin(9600);
}

void loop() {
  c1 = pulseIn(22, HIGH, 25000);
  c2 = pulseIn(24, HIGH, 25000);
  c3 = pulseIn(26, HIGH, 25000);
  c4 = pulseIn(28, HIGH, 25000);

  if(abs(ch1-c1)>50)
  ch1=c1;
 
  if(abs(ch2-c2)>50)
  ch2=c2;
 
  if(abs(ch3-c3)>50)
  ch3=c3;
 
  if(abs(ch4-c4)>50)
  ch4=c4;
 
  if(ch2>1400&&ch2<1600)
  {
    m1=ch3;
    m3=m1;
    m2=ch4;
    m4=m2;
  }
  else
  {
    m1=ch2;
    m3=3000-ch2;
    m2=ch2;
    m4=3000-ch2;
  }


 

   
  servo1.write(m1);
  servo2.write(m2);
  servo3.write(m3);
  servo4.write(m4);
  delay(10);

}

1035700564

at first I also thought that the PWM signal from transmitter keep changing which leads to the servo shaking, but later when i connect the receiver directly to servo, the servo can work well without shaking. also i print the PWM signal, it's not that stable but will only change within 10(like 1500 to 1510), which cannot cause the servo shake so much, that's why I feel it's not because of the input signal.

TomGeorge

Hi,
Quote
I know Arduino cannot drive sufficient current for four servo, I have connect them to a five volt battery.
What size 5volt battery, how much current can t supply?
A picture of your project, including the battery will help.

Have you written a simple bit of code, just to sweep the servos without ant RC input, to test your hardware arrangement?

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up