Servo Motor Probem for making both Move Opposite ways

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

A standard servo moves in the range of 0-180 degrees (1/2 rotation). The sail-winch servo you posted above moves in the range of 0 to 1620 degrees (4 1/2 rotations). That is 9 times the rotation of a standard servo. So you need to reduce the range specified in your code by a factor of 9.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Does that mean I do 180 divided by 9, and than 180 with that number.

Also, my Sail Winch Servo is not moving 9 times more than 180 degrees.

I can clearly tell it is just moving a little bit more than 180 degrees and not moving even double of 180 degrees.

Should my Sail Winch Servo be moving 9 times more like you say a Sail Winch should?

Why do you think my Sail Winch Servo is acting this way?

Is something wrong with my Sail Winch Servo?

Just so you know here is a link to the model of my Sail Winch I am using as well as a picture so attached for reference:
https://www.amazon.com/W4505-4T-Plastic ... 209668c3ce
Attachments
EF946A6A-2314-4843-B1E3-567ABC6E6B88.jpeg
EF946A6A-2314-4843-B1E3-567ABC6E6B88.jpeg (87.37 KiB) Viewed 329 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

I don't have any experience with that particular servo. Based on the published specifications, it should turn 9 times as far as a standard servo with the same commands. In any case, you should be able to increase or decrease the numbers in your code until you find values that work for your servo.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Even after tweaking the numbers that tell the amount of degrees it moves for my Sail Winch, it still does not move exactly the degrees I want it too.

I think this Sail Winch Servo is NOT the most ideal for my project.

I should be able to use a regular servo that can sweep exactly the amount of degrees the sweep code tells it too.

I think this means I need a Servo Motor with an encoder.


What would you recommend for a Servo Motor with an encoder that would be able to turn exactly the degrees it is told in the code?




Also, my regular mini servo SG90 is acting up.

When I run the normal sweep code it works perfectly fine.

But when I add the command, "myservo.detach();", to the very bottom of the code it turns 90 degrees when it is told in the code to move 180 degrees

And also with the same code it moves the first 90 degrees fast, but when it moves back 90 degrees it slow and rickety.

Do you know why this is happening?

If so can you also recommend a servo with an encoder that doesn't do that when I add that line of code?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

Even after tweaking the numbers that tell the amount of degrees it moves for my Sail Winch, it still does not move exactly the degrees I want it too.
How far off is it? Since it uses the same signals as a regular RC servo but has a wider range of motion, the precision of the positioning will be lower.
I should be able to use a regular servo that can sweep exactly the amount of degrees the sweep code tells it too.

I think this means I need a Servo Motor with an encoder.

What would you recommend for a Servo Motor with an encoder that would be able to turn exactly the degrees it is told in the code?
By definition, all servos have encoders. Feedback is what makes them servos. If you can be more specific about what you need this motor to do we might be able to offer some suggestions.
But when I add the command, "myservo.detach();", to the very bottom of the code it turns 90 degrees when it is told in the code to move 180 degrees
Once you call myservo.detach();, you have no control over the servo. So you can't expect it to respond to any commands.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

I don't know exactly how much more degrees the Sail Winch servo is turning than the degrees it is supposed to.

But I can kind of estimate it.

Here is the sweep code I used recently.

I reduced both of the degrees

Code: Select all

   
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 160; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);// waits 15 ms for the servo to reach the position
  
  
  }
  for (pos = 106; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);  // waits 15 ms for the servo to reach the position
  myservo.detach();
    
  
  }
}      

For that code it maybe turns about 20 degrees more for the first turn and the turn back.





It seems like the only reason the SG90 mini servo is not working is because of the detach code at the bottom.

I would like to fix the code for the SG90 mini servo motor before I buy something else.

The whole reason why I put the detach code at the end is so that the servo would sweep and than stop rather than sweeping for infinity.

Do you know how to change the code so the SG90 servo sweeps the way it is supposed to, and than stops rather than sweeping for infinity?


But if we can't fix the code for the SG90 mini servo than I guess it doesn't matter too much what servo I get because they all have encoders anyways.

But if so, I would like a servo that is about as big as my Sail Winch servo , by that I mean a standard size and not anything mini sized like my SG90 mini servo, and moves pretty smoothly.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

For that code it maybe turns about 20 degrees more for the first turn and the turn back.
20 degrees more than what? How many degrees do you want it to rotate?
It seems like the only reason the SG90 mini servo is not working is because of the detach code at the bottom.

I would like to fix the code for the SG90 mini servo motor before I buy something else.

The whole reason why I put the detach code at the end is so that the servo would sweep and than stop rather than sweeping for infinity..
If that is the continuous rotation 'servo' you were using before, the reason it does not stop is because continuous rotation 'servos' ARE NOT SERVOS!
https://learn.adafruit.com/adafruit-mot ... /rc-servos
Servos by definition have feedback and the feedback in continuous rotation 'servos' is intentionally BROKEN. You cannot control position with these motors.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

I meant 20 degrees more than 180 degrees for both directions the Sail Winch servo turns when it sweeps.

I don’t think the SG90 mini servo is continuous.

What I meant was that the Sweep Sketch from Arduino is supposed to make the servo turn one direction and than the other direction and than repeat that for infinity.

That is what I mean when I say it sweeps for infinity.



I am just trying to make it to where this SG90 mini servo moves one direction, stops, moves the opposite direction, and than stops again forever.

Do you know how I can do this other than putting the detach code at the bottom of the Sweep Sketch?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

The 2 'for' loops in the code you posted have different limits for the two parts of the sweep.

The first part goes from 0 to 160:

Code: Select all

 for (pos = 0; pos <= 160; pos += 1) 
The second part goes from 106 to 0

Code: Select all

for (pos = 106; pos >= 0; pos -= 1)
To change the limits of the sweep, both of those values should be the same.
I am just trying to make it to where this SG90 mini servo moves one direction, stops, moves the opposite direction, and than stops again forever.

Do you know how I can do this other than putting the detach code at the bottom of the Sweep Sketch?
If you only want it to sweep once then stop, you need to stop sending it position commands. The simplest way to do that is to move your sweep code to the setup() function. That will only execute once at startup.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Ok. I tried that.

I moved all my code to "setup" and deleted the "void loop" code.

It ends up getting an error for not being able to compile to the Arduino

I also have a image of this error attached.

Here is the code:

Code: Select all

  #include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object


  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
}




     


It seemed like the problem was that I didn't have the loop code, so I put the loop code without anything in the loop code.

Here is the code for that:

Code: Select all

     #include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object


  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }

}
void loop(){
  
}




           








I tested this code out for my Sail Winch servo and my SG90 mini servo

But when I ran this code, for both servos it just made them turn in circles.

So that didn't seem to work when I put the loop code without anything in there.



Why do you think that the code without the loop code was having an error?

And why do you think my code makes the servos turn in circles when I add the loop code without anything?

What should I do to make this code work correctly?
Attachments
Supoort Adafruit Sweep only Once withou Detach image.PNG
Supoort Adafruit Sweep only Once withou Detach image.PNG (32.9 KiB) Viewed 287 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

I moved all my code to "setup" and deleted the "void loop" code.

It ends up getting an error for not being able to compile to the Arduino
Every Arduino program requires a setup() function and a loop() function. The loop() can be empty, but it must be there.
And why do you think my code makes the servos turn in circles when I add the loop code without anything?
What do you mean by "turn in circles?" Your SG90 should not be able to turn more than 180 degrees. If it is rotating continuously, it must be a continuous rotation servo.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

Yes, when I run the code my SG90 mini Servo ends up turning 360 degrees repeatedly.

So is my code with the loop code correct for making a code that tells the Servo to move one direction, and than move the other direction and than stop forever.

Why are my servos turning in circles from this code , other than the fact that my SG90 servo may be Continuous?

Can you give the full code that you would use to do this?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

Yes, when I run the code my SG90 mini Servo ends up turning 360 degrees repeatedly.
360 degrees in the same direction? Or 360 degrees in one direction and then 360 degrees back to where it started?

Using a standard RC servo, the code you posted should turn 180 degrees in one direction, then reverse 180 degrees and stop.

If it continues turning in the same direction forever, then it is probably a continuous rotation servo.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Servo Motor Probem for making both Move Opposite ways

Post by animefruit »

With that code my SG90 mini servo motor moves about 90 degrees in a twitchy way and than stops and than moves 360 degrees in the other direction repeatedly.

I kind of get why it turns 360 degrees in the opposite direction repeatedly, which is because it probably a continuous servo.

But I don't know why it only turns 90 degrees at first.

Would you know why that is?



But it does seem like this is a continuous rotation servo, so I should probably get a better one.

Can you also recommend me a non-continuous servo that is standard sized that would work well for turning how much I tell it to in the code?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Servo Motor Probem for making both Move Opposite ways

Post by adafruit_support_bill »

But I don't know why it only turns 90 degrees at first.

Would you know why that is?
If you tell a continuous rotation servo to go to a position > 90 degrees, it will rotate in one direction. If you tell it to rotate to a position < 90 degrees it will rotate in the opposite direction. Your first 'for' loop tells it to rotate to 180 degrees, so it goes in one direction. The second loop tells it to rotate to 0 degrees, so it rotates in the other direction. Since it is a continuous rotation 'servo', it has no feedback, so it continues moving in the direction you last told it to.

The SG5010 is a non-continuous-rotation standard size servo. https://www.adafruit.com/product/155
The SG92 is a non-continuous-rotation micro servo (same size as your SG90). https://www.adafruit.com/product/169

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”