95Views1Replies

Author Options:

Arduino & Servo problem - servo overshooting/inaccurate Answered

Hello Forum!
So I'm planning to build a robotic arm and I'm testing servos for direct response to input values in degrees, in order to later build a code for forward and inverse kinematics.
My problem is as follows:
I've written some code to pass numbers to the motor from the keyboard. But my motor seems to be horribly innacurate and... well when I tell it to set itself at angle 90, it goes to like 110 or so. And in order to go from 0 to 180, I must pass 165 instead, because the servo goes beyond a half-full angle. Is it the motors fault or there should be some kind of additional feedback loop somewhere?
With reactions like those, I could hardly build an RC car, not mentioning a robot.
I add the code and I have filmed issue.
    vid 2: https://drive.google.com/file/d/0B_oVtjTRcVtwTnRtQWJxd1NJSEk/view?usp=sharing
    vid 1: https://drive.google.com/file/d/0B_oVtjTRcVtwdWg3ek80MUxLaEk/view?usp=sharing

I count on you guys! Thanks in advance!

#include <Servo.h>

Servo myservo;

int Input(0);

void setup() {
  myservo.attach(9);
  myservo.write(180);
  Serial.begin(9600);
  Serial.println("system initialized");
  Serial.println("input configuration value: ");
}

void loop() {

  while (1)
    {
        while (Serial.available())
        {
          Input = atoi(Serial.readStringUntil('\n').c_str());
            if(!(Input<0 || Input>180))
            {
               myservo.write(Input);
               delay(15);  
               Serial.println(Input);
               Serial.println("input configuration value: ");
            }
            else
            {
               Serial.print(Input);
               Serial.println("?");
               Serial.println("y u do dis?");           
            }
        }
        break;
    }
  delay(15);

Discussions

0
None
gmoon

2 years ago

Have you tested it with any hard-coded angle values? ...just in case your serial input routine -> int conversion code is misbehaving...