Pages: [1]   Go Down
Author Topic: My Continuous Rotation Servo Keeps Drifting / Jumping; Won't Hold Position  (Read 1753 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on my first Arduino project with motors.

I have some small servos (http://hobbypartz.ecommerce-site-search.com/?query=&query=120G+EXI+Servo+B1226&vwcatalog=yhst-62196343123315&.autodone=http%3A%2F%2Fwww.hobbypartz.com%2F) that I've converted to be continuous rotation. I'm using an analog joystick to, hopefully, make the servos spin either in one direction or the other. I'd like there to be no motion when the joystick is centered.

Everything seems to work when I'm pushing the joystick. The servo moves at varying speeds in both directions. However, when the joystick is centered, the servo constantly is jostling back and forth a small amount. Any ideas on how I can address this?

The code is sending a position command of 90 to the servo when the joystick is centered.

Thanks--I appreciate any ideas.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9682
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First thing you need to do is post the code you are using. Second, writeMicroseconds is generally more useful with continous rotation servos for finer speed control. Third, a deadband may need be established for the neutral position, and possibly detach the servo if they tend to creep.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for trying to help me. Here is the code I'm using just to test the basic functionality of the servo:


#include <Servo.h>
 
Servo myservo;
 
int potPin = A0; 
int val;
int servoPin = 6;
 
void setup()
{
  pinMode(potPin,INPUT);
  myservo.attach(servoPin);
  Serial.begin(9600);
}
 
void loop()
{
  val = analogRead(potPin);             
  val = map(val, 0, 1023, 0, 179);     
  if (val>95 || val< 85)
  {
    myservo.write(val);
  }
 else
  {
    myservo.write(90);
  }
 
  Serial.println(val);
  delay(15);                           
}



I've read that by converting a servo to continuous rotation, you can control its speed instead of its position. To be honest, I'm not sure I understand how that works. With this code running on my Arduino, I notice that there is a little bit of speed control, but it's sort of like off, kind of fast, and fast. I don't notice it as being infinitely variable.

I'll do a little reading about writeMicroseconds--I am not familiar with that at all.

I'm not sure what a "deadband" is, but I will try to do some research on that as well.

Thanks again!
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9682
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Below is some code you can use to test how your servo responds to deg and us commands. Not sure about yorr servo as the kink went to an 8 turn sail servo. Bottom is some test code with a dead band. The pot in your modified servo should be adjusted such that when a 1500us (or 90 deg) command is sent, the servo does not move.

Code:
// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  }
}


pot control code

Code:
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
int potpin = 0;  // analog pin used to connect the potentiometer
int newval;    // variable to read the value from the analog pin
int oldval;
void setup()
{
  Serial.begin(9600);   
  //myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  newval = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  newval = map(newval, 0, 1023, 1400, 1600);     // scale it to use it with the servo (value between 1400 and 1600)
  //newval = map(newval, 0, 1023, 500, 2500);     //scale it to use it with the servo (value between 500 and 2500)
 
if (newval < (oldval-2) || newval > (oldval+2)){ //deadband
//if (newval != oldval){
  myservo.write(newval);
  //Serial.print("#1P");
  Serial.println(newval);
  oldval=newval;
}           
  // sets the servo position according to the scaled value
  delay(50);                           // waits for the servo to get there
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I will try your code when I can get to my computer. I see now what you meant by a deadband. Finally, that link I provided is correct--that is the servo I am using. It was advertised as "easy to convert to continuous rotation." I disassembled the gearbox, pulled a little plastic ring off the potentiometer shaft, and I think that was all there was to it. It does spin forever in either direction.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also try another POT, if not, try different value resistors.  Some pots are "dirty" and give some jumpy values.  A resistor in place could eliminate the possibility of a faulty pot.
Logged

Pages: [1]   Go Up
Jump to: