Go Down

Topic: sg90 servo deflection (Read 4483 times) previous topic - next topic

colubridae

Hi I'm trying to use a servo to control the position of a model windmill (not its sails) on my model railway.

The servo will be imbedded in the baseboard and will rotate the body of the windmill around the vertical axis.

The problem I have is that when switched on the servo immediately deflects by roughly 20 degrees (anti-clockwise viewed from above).

Is there any way to suppress this deflection?

Is this a feature of all servos or just the SG90?

Many thanks for any help
Saddo railway nerd (65yrs)

manor_royal

#1
Feb 16, 2017, 11:43 am Last Edit: Feb 16, 2017, 12:01 pm by manor_royal
It's It might be (see Robin2 below) a result of where it was when you finished with it compared to the first place you tell it to go.

If you reliably know that it's at X degrees when you shut down then do a servo.write(X) before your servo.attach() then it won't fly off to the default position but go to X, which means if it's already there, it won't move.

(ie, the 20 deflection is not 20 in absolute terms, it just happens to be 20 degrees away from where you left it.)

If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

Robin2

#2
Feb 16, 2017, 11:47 am Last Edit: Feb 16, 2017, 11:49 am by Robin2
I have found the same effect with a small HobbyKing servo. But it does not happen with another Hitec servo.

I assume the problem is that there is a short period between the Arduino being powered up and the servo being attached and taken under control. I only noticed this problem yesterday so I have not explored a solution yet. Actually for my use (controlling points or signals) it probably would not really matter. But I can see how the windmill behaviour would look a bit strange.

And to follow from @manor-royal, the problem I detected is not a result of the servo stopping in the "wrong" position because several brief restarts (i.e. without leaving it connected long enough for servo.attach() to happen) will progressively move the arm all the way to the limit of the servos movement.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

manor_royal

Hm ok, that's very interesting Robin2.

Maybe my answer is a red herring then, although it behooves OP to try the servo.write before servo.attach idea.

BTW @OP, here's the line in servo.h where it sets the default pulse to 1500ms, ~90 degrees:

Code: [Select]

#define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached


If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

colubridae

And to follow from @manor-royal, the problem I detected is not a result of the servo stopping in the "wrong" position because several brief restarts (i.e. without leaving it connected long enough for servo.attach() to happen) will progressively move the arm all the way to the limit of the servos movement.

...R
Thanks robin

This is exactly my problem the servo deflects at each power-up by approx 20 degrees
Even with the arduino not powered-up.

thanks manor_royal

@manor_royal.
I have already included a servo.write before my servo.attach in void setup. The result is always the same - a rapid deflection at power-up of approx 20 degrees.

Am i right in assuming from your answer that your set-up does not experience deflections during power-up? If this is the case may I ask the make and model of your servo? Please.
Saddo railway nerd (65yrs)

manor_royal

Am i right in assuming from your answer that your set-up does not experience deflections during power-up? If this is the case may I ask the make and model of your servo? Please.

I won't answer that until I've checked that it never happens, but I've certainly never noticed it before. Or should I say I've never noticed that I noticed, if you know what I mean.

Sorry, I didn't realise your problem was purely power related, I assumed it was a control thing.

So just to clarify: if you literally apply just power to the servo, with no live control wire, it deflects by 20-odd degrees no matter where it last stopped?

If so what happens if it was stopped at the end of travel and can't move another 20?- does it start coming back?

If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

colubridae

I won't answer that until I've checked that it never happens, but I've certainly never noticed it before. Or should I say I've never noticed that I noticed, if you know what I mean.

Sorry, I didn't realise your problem was purely power related, I assumed it was a control thing.

So just to clarify: if you literally apply just power to the servo, with no live control wire, it deflects by 20-odd degrees no matter where it last stopped?

If so what happens if it was stopped at the end of travel and can't move another 20?- does it start coming back?


Yes to first question. Simply powering-up produces a consistent 20 degree deflection. I've now tried it on a second SG90 and get the same result.

In an answer to your second question, at full deflection the servo seems to try another 20 degree deflection but simply produces what I can only describe as a squeek.

In point of fact the deflection is not a 'serious' problem, it's the speed of the deflection. This would produce a problematic torque on the joint of the sails to the sail-motor housing of the model.

Many thanks in advance
Saddo railway nerd (65yrs)

manor_royal

I just found this here:

Quote
Without signal, they will constantly wind themselves around with each successive power-up.
Look up how a servo works internally and you will see the reason why.
Hint, it has to do with the internally generated servo position signal to the comparator.
If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

alka

I just checked with a sg90 I have and it has the same strange behaviour. It always moves at power up regardless of last position. If you unplug and plug in again it takes another 20 degree step.

However..

As a test I tried hot plugging the servo into a header that already had a signal and it only twitches but does not take a big jump.

alka

So can you power your servos up with a relay or something after they are getting their signal? Should stop the jump.

colubridae

So can you power your servos up with a relay or something after they are getting their signal? Should stop the jump.
Will try that solution. Many thanks.
Saddo railway nerd (65yrs)

Robin2

Will try that solution. Many thanks.
While it should work it is a real PITA.

I suspect a small transistor would be sufficient to control the power to the servo - simpler than a relay.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

alka

While it should work it is a real PITA.

I suspect a small transistor would be sufficient to control the power to the servo - simpler than a relay.

...R
Agreed, a transitor would be a better choice than a relay.

Robin2

#13
Feb 16, 2017, 05:13 pm Last Edit: Feb 16, 2017, 05:20 pm by Robin2
I have now tested 5 different types of servo.

As indicated earlier the small HobbyKing servo moves with every power-up while it has no signal. Two other types (but don't know the make) behave the same.

An old and larger Hitec servo and a really tiny HobbyKing servo don't move at all until they get the servo.attach() signal.

Clearly this unwelcome phenomenon is not an intrinsic property of servos as was implied by the piece quoted in Reply #7.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

septillion

The SG90 is known for that. In most situation you can overcome it by connection a pull up (something like 4k7) between signal and the servo 5V. But I rater get the tiny bit more expensive SG92 which is as stable as a rock :)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Go Up