Servo Jitters back

Hello!

Hardware: Arduino Uno R3, Parallax 360 degree feedback servo, Velleman WPI435 digital encoder, 4-digit 7 segment display module

The servo is powered from the Arduino. I know that is not good, however right now there is no other possibility, but if this might be the reason for the malfunction, I would be "glad" to hear that. The feedback of the servo uses one interupt pin and the other one is used for the CLK from my encoder.

I want to turn the servo from 0 to 300 degrees corresponding to a value from 0 to 100 which I increase and decrease with the encoder, the value from 0 to 100 is displayed at the display. I had to use a mix of the standard arduino servo library and a library made for the parallax feedback servo (Link to Github repository: GitHub - HyodaKazuaki/Parallax-FeedBack-360-Servo-Control-Library-4-Arduino: Arduino library which control Parallax FeedBack 360° High Speed Servo easy. ), because I had troubles with servo jitter (at least thats what I think it is) when using the parallax libraries .rotate() function and changing thhe angle in small increments.
Now the servo turns, always in between the 0 and 300 degree range, but it sometimes bounces back. I feel like it works smoother in one direction (counterclockwise) than the other way round, I thought this might have to do with the interupt.

Here is my code:


#include "TM1637.h"
#include <Servo.h>
#include <Encoder.h>
#include "FeedBackServo.h"

Encoder myEnc(3, 7);

int8_t TimeDisp[] = { 0x00, 0x00, 0x00, 0x00 };
long oldPosition = 0;
long newPosition;
long displayValue_new = 0;
long displayValue_old = 0;
long displayValue_tmp = 0;
int maxDeg = 300;
int startDeg = 0;
int displayValue_last = 0;
bool firstLoop = true;

#define FEEDBACK_PIN 2
#define CLK 12  //pins definitions for TM1637 and can be changed to other ports
#define DIO 13
TM1637 tm1637(CLK, DIO);

Servo myservo;  // create servo object to control a servo

FeedBackServo servo = FeedBackServo(FEEDBACK_PIN);

void setup() {
  myservo.attach(5);  // attaches the servo on pin 9 to the servo object
  tm1637.set();
  tm1637.init();
  Serial.begin(9600);
}

void loop() {

  newPosition = myEnc.read();

  if (newPosition != oldPosition) {
    displayValue_new = displayValue_old - (newPosition - oldPosition);

    if (displayValue_new <= 100 && displayValue_new >= 0) {

      displayValue_old = displayValue_new;
      // Serial.println(displayValue_old);
    }

    else {
      if (displayValue_new >= 100) {
        displayValue_new = 100;
        displayValue_old = displayValue_new;
        // Serial.println(displayValue_old);
      } else if (displayValue_new <= 0) {
        displayValue_new = 0;
        displayValue_old = displayValue_new;
        // Serial.println(displayValue_old);
      }
    }
    oldPosition = newPosition;
  }

  displayValue_tmp = displayValue_new;

  for (int i = 3; i >= 0; i--) {
    TimeDisp[i] = displayValue_tmp % 10;  // remainder of division with 10 gets the last digit
    displayValue_tmp /= 10;               // dividing by ten chops off the last digit.
  }

  displayValue_tmp = displayValue_new * maxDeg / 100;

  if (firstLoop == false) {
    if (displayValue_new != displayValue_last) {
      if (displayValue_tmp > servo.Angle()) {
        myservo.write(1280);  // sets the servo position according to the scaled value
      }
      if (displayValue_tmp < servo.Angle()) {
        myservo.write(1720);
      }
    } else myservo.write(1500);
  }

  delay(15);

  Serial.println(servo.Angle());
  Serial.println(displayValue_new);
  Serial.println(displayValue_last);
  Serial.println(firstLoop);

  tm1637.display(TimeDisp);
  displayValue_last = displayValue_new;
  firstLoop = false;
}

Can please anyone tell me why this is happening?

And why does the servo always spins for 4 seconds clockwise, stops for 2 seconds and then spins for another one until it stays in position? This I don't understand at all.

And last, why does the servo still turn very slowly sometimes, while testing with the hold pulsewith (1500), is this related to powering it with the arduino?

Thank you very much for your help!

How is the Arduino itself powered ?

1500 microseconds or 90 degrees should stop the continuous rotation servo. But the value might be slightly wrong.

You'll have to experiment a bit to calibrate that value for your servo.

See

a7

Fix any problems at another time, using a separate power supply.

It's generally agreed that powering your servo from the Arduino Uno is ill-advised.

It seems the servo feedback signal is 3.3V logic. I would think that's a good possibility, too.

RPM: +/-120 w/feedback control, 140 max (+/- 10) @ 6 V, no load
Gears: POM
Case: Nylon & fiberglass
Spline: 25-tooth, 5.96 mm OD
Peak stall torque @ 6 V: 2.2 kg-cm (30.5 oz-in)
Voltage requirements: 6 VDC typical, 5–8.4 VDC max range*
Current requirements: 15 mA (+/- 10) idle, 150 mA (+/- 40) no-load, 1200 mA stalled
Control signal: PWM, 3–5 V 50 Hz, 1280–1720 µs
Control signal zero-speed deadband: 1480–1520 µs (+/- 10)
Feedback sensor: Hall effect
Feedback signal: PWM, 3.3V, 910 Hz, 2.7–97.1% duty cycle
Product weight: 1.4 oz ( 40 g)
Cable length: ~ 9.8 in (250 mm)
Dimensions: approx. 2.15 x 1.46 x 0.79 in (50.4 x 37.2 x 20 mm)
Mounting hole spacing: 10 x 49.5 mm on center
Operating temperature range: 5 to 158 °F (-15 to +70 °C)

source:
https://www.parallax.com/product/parallax-feedback-360-high-speed-servo/

@reliefpfeiler

Keep in mind that the servo briefly draws the stall current every time it starts moving, regardless whether there is any load on the servo output shaft.

The Arduino 5V output is designed for a couple of LEDs or low power sensors, NOT for a servo that draws 1.2 Amperes.

1 Like

Thank you for your answers!

I fixed the power supply. Everything is now powered by 5V max 4A AC Adapter.

Keeping the servo in halt also works.

But I still have this problem: When I turn and the value is increasing, at the begining the servo turns slightly counterclockwise before it starts turning clockwise as it should. From high value down its the same, BUT only at certain (mostly slow) turn speeds. When I turn at a certain faster speed it works pretty good. Does anyone understand this problem? Can I solve this if I use an Arduina Mega and use only interrupt pins for the encoder?

Thx!

Didn't see what servo you use however expecting most servos to travel 300 degrees is out of their spec range and you've more that likely damaged the servo feedback mechanism.

Ah...ok.... Parallax 360 degree feedback servo
However these need a voltage range of 5.8 to 8.4V which is not going to happen fed from the Arduino (bad idea anyhow) and neither with you addition of a 5v separate supply.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.