How can I move a servo to its middle position?

Started by naimead May 27, 2005
I tried the following code so i can move the servo to its middle
position:

*******************************************
Sub Main()
' This program will move the servo to its middle position.
Const ServoPin As Byte = 6
Do
' Generate a high-going 1.5 ms pulse.
Call PulseOut(ServoPin, 0.0015, 1)
' This is to produce a pulse rate of about 50 Hz.
Call Delay(0.02)
Loop
End Sub
*******************************************

The result was the servo to move all the way to the left and it seemed
that if there was any more space it could keep moving to the left!
How can i find the real middle position of my servo?


I have also tried the following example but although in the debugging
window I do have the forward and reverse messages the servo stays in
the same position!I think that the problem is in the middle
position.Why does it always go left?How can i possible move it with
very small steps(e.g very few degrees left,very few degrees
right).Aren't 1.5 and 2ms the limits of the servo? '---------------------------------
----------
Option Explicit

'---------------------------------
----------
Public Sub Main()

' This program exercises a servo by moving it back and forth through
its
' position range, at about 1 cycle every 5 seconds.

Const ServoPin As Byte = 17

Const NSteps As Integer = 100

' This is to generate a refresh rate of roughly 50 Hz.
Const RefreshPeriod As Single = 0.02

Dim i As Integer, Position As Single

Debug.Print
Debug.Print "Servo Demonstration"
Debug.Print

Debug.Print "Center servo"

For i = 1 To 50 ' For about 1 second.
Call MoveServo(ServoPin, 0.5)
Call Delay(RefreshPeriod)
Next

Do
Debug.Print "Forward"

For i = 0 To NSteps

' Nondimensionalize position.
Position = CSng(i) / CSng(NSteps)

Call MoveServo(ServoPin, Position)

Call Delay(RefreshPeriod)
Next

Debug.Print "Reverse"

For i = NSteps To 0 Step -1

' Nondimensionalize position.
Position = CSng(i) / CSng(NSteps)

Call MoveServo(ServoPin, Position)

Call Delay(RefreshPeriod)
Next
Loop

End Sub
'---------------------------------
----------
Public Sub MoveServo( _
ByVal ServoPin As Byte, _
ByVal Position As Single)

' Moves a servo by sending a single pulse. The position is a
nondimensional
' value in range 0.0 to 1.0.

Dim PulseWidth As Single

' Translate position to pulse width. Resulting range is 1.0 to
2.0 ms,
' centered at 1.5 ms.
PulseWidth = 0.001 + (0.001 * Position)

' Generate a high-going pulse on the servo pin.
Call PulseOut(ServoPin, PulseWidth, 1)

End Sub
'---------------------------------
----------


Most all servos have a CENTER at either 1.5mS (more common)
or 1.2mS. 1mS and 2mS are usually the limits (some at 950 to 2.2mS)

Paul Tegler
ptegler@pteg...
www.teglerizer.com

----- Original Message -----
From: "naimead" <naimead@naim...>
To: <basicx@basi...>
Sent: Saturday, May 28, 2005 10:40 PM
Subject: [BasicX] Re: How can I move a servo to its middle position? > I have also tried the following example but although in the debugging
> window I do have the forward and reverse messages the servo stays in
> the same position!I think that the problem is in the middle
> position.Why does it always go left?How can i possible move it with
> very small steps(e.g very few degrees left,very few degrees
> right).Aren't 1.5 and 2ms the limits of the servo? > '---------------------------------
> ----------
> Option Explicit
>
> '---------------------------------
> ----------
> Public Sub Main()
>
> ' This program exercises a servo by moving it back and forth through
> its
> ' position range, at about 1 cycle every 5 seconds.
>
> Const ServoPin As Byte = 17
>
> Const NSteps As Integer = 100
>
> ' This is to generate a refresh rate of roughly 50 Hz.
> Const RefreshPeriod As Single = 0.02
>
> Dim i As Integer, Position As Single
>
> Debug.Print
> Debug.Print "Servo Demonstration"
> Debug.Print
>
> Debug.Print "Center servo"
>
> For i = 1 To 50 ' For about 1 second.
> Call MoveServo(ServoPin, 0.5)
> Call Delay(RefreshPeriod)
> Next
>
> Do
> Debug.Print "Forward"
>
> For i = 0 To NSteps
>
> ' Nondimensionalize position.
> Position = CSng(i) / CSng(NSteps)
>
> Call MoveServo(ServoPin, Position)
>
> Call Delay(RefreshPeriod)
> Next
>
> Debug.Print "Reverse"
>
> For i = NSteps To 0 Step -1
>
> ' Nondimensionalize position.
> Position = CSng(i) / CSng(NSteps)
>
> Call MoveServo(ServoPin, Position)
>
> Call Delay(RefreshPeriod)
> Next
> Loop
>
> End Sub
> '---------------------------------
> ----------
> Public Sub MoveServo( _
> ByVal ServoPin As Byte, _
> ByVal Position As Single)
>
> ' Moves a servo by sending a single pulse. The position is a
> nondimensional
> ' value in range 0.0 to 1.0.
>
> Dim PulseWidth As Single
>
> ' Translate position to pulse width. Resulting range is 1.0 to
> 2.0 ms,
> ' centered at 1.5 ms.
> PulseWidth = 0.001 + (0.001 * Position)
>
> ' Generate a high-going pulse on the servo pin.
> Call PulseOut(ServoPin, PulseWidth, 1)
>
> End Sub
> '---------------------------------
> ---------- >
>
> Yahoo! Groups Links >



I notice that every single value i am trying,leads the motor to the
same position(which is always to the left)?Any explanation please?

Public Sub Main()
call Center_Servo
end sub
Public Sub Center_Servo()
Const ServoPin2 As Byte = 6
Dim i As Long
Const RefreshPeriod As Single = 0.02
For i = 1 To 200
Call MoveServo2(ServoPin2, 0.2)
Call Delay(RefreshPeriod)
Next
Delay(3.0)
For i = 1 To 300
Call MoveServo2(ServoPin2, 0.095)
Call Delay(RefreshPeriod)
Next
End Sub
Public Sub MoveServo2( _
ByVal ServoPin2 As Byte, _
ByVal Position As Single)

Dim PulseWidth As Single
PulseWidth = (0.001 + (0.001 * Position))
Call PulseOut(ServoPin2, PulseWidth, 1)

End Sub


naimead,
Try changing: Position to vary from 0 to 1. Somewhere NEAR 0.5, the servo should be at its center position or it will not rotate.

Was the servo bought or modified for continous rotation?

Thad

naimead <naimead@naim...> wrote:
I notice that every single value i am trying,leads the motor to the
same position(which is always to the left)?Any explanation please?

Public Sub Main()
call Center_Servo
end sub
Public Sub Center_Servo()
Const ServoPin2 As Byte = 6
Dim i As Long
Const RefreshPeriod As Single = 0.02
For i = 1 To 200
Call MoveServo2(ServoPin2, 0.2)
Call Delay(RefreshPeriod)
Next
Delay(3.0)
For i = 1 To 300
Call MoveServo2(ServoPin2, 0.095)
Call Delay(RefreshPeriod)
Next
End Sub
Public Sub MoveServo2( _
ByVal ServoPin2 As Byte, _
ByVal Position As Single)

Dim PulseWidth As Single
PulseWidth = (0.001 + (0.001 * Position))
Call PulseOut(ServoPin2, PulseWidth, 1)

End Sub

---------------------------------
Yahoo! Groups Links

To __________________________________________________




I give values like 0.518,0.523,0.490 etc... but it moves always to
the left.When I give values like 0.95,0.3 etc it moves to the left
too!!I am not sure if it is meant to be for continuous rotation.
It is a well known model-the robbe futaba S3001-.When you mean
somewhere near 0.5 could it be 0.6 or even 0.7 or we are talking
about decimals(e.g 0.521)? Public Sub Main()
call Center_Servo
end sub
Public Sub Center_Servo()
Const ServoPin2 As Byte = 6
Dim i As Long
Const RefreshPeriod As Single = 0.02
For i = 1 To 200
Debug.Print "Center servo"
Call MoveServo2(ServoPin2, 0.518)
Call Delay(RefreshPeriod)
Next
Delay(3.0)
For i = 1 To 200
Debug.Print "move servo"

Call MoveServo2(ServoPin2, 0.95)
Call Delay(RefreshPeriod)
Next
End Sub
Public Sub MoveServo2( _
ByVal ServoPin2 As Byte, _
ByVal Position As Single)

Dim PulseWidth As Single
PulseWidth = (0.001 + (0.001 * Position))
Call PulseOut(ServoPin2, PulseWidth, 1)

End Sub



I had this same problem once. The problem with me was a faulty ground. You
have to make sure that the ground of the servo is common with the ground of
the microprocessor. Otherwise, the signals have no where to go to complete
the circuit, and you get strange behavior like that. Also, it recommend in
the BX docs to connect a 470 ohm resistor between the BX and the signal line
of the servo. On the servos I have used, the 470 ohm resistor did not
affect the operation of the servo, and I am lead to believe that it is only
to protect the processor, however, I do not know this for sure.

In a nutshell, I think you have a grounding problem. Connect the ground of
the servo power supply to the ground of the BX.

Austin

-----Original Message-----
From: basicx@basi... [mailto:basicx@basi...] On Behalf Of
naimead
Sent: Sunday, May 29, 2005 11:49 AM
To: basicx@basi...
Subject: [BasicX] Re: How can I move a servo to its middle position?

I give values like 0.518,0.523,0.490 etc... but it moves always to
the left.When I give values like 0.95,0.3 etc it moves to the left
too!!I am not sure if it is meant to be for continuous rotation.
It is a well known model-the robbe futaba S3001-.When you mean
somewhere near 0.5 could it be 0.6 or even 0.7 or we are talking
about decimals(e.g 0.521)? Public Sub Main()
call Center_Servo
end sub
Public Sub Center_Servo()
Const ServoPin2 As Byte = 6
Dim i As Long
Const RefreshPeriod As Single = 0.02
For i = 1 To 200
Debug.Print "Center servo"
Call MoveServo2(ServoPin2, 0.518)
Call Delay(RefreshPeriod)
Next
Delay(3.0)
For i = 1 To 200
Debug.Print "move servo"

Call MoveServo2(ServoPin2, 0.95)
Call Delay(RefreshPeriod)
Next
End Sub
Public Sub MoveServo2( _
ByVal ServoPin2 As Byte, _
ByVal Position As Single)

Dim PulseWidth As Single
PulseWidth = (0.001 + (0.001 * Position))
Call PulseOut(ServoPin2, PulseWidth, 1)

End Sub
Yahoo! Groups Links


naimead:

I'm not too sure, but you may have just a bit too much delay. The pulse
should begin about every 20 ms. Some servos I've used were more sensitive,
and I know that if you wait too long between pulses, the servo will behave
erratically. Coming too soon doesn't seem to have the same effect unless
it's under about 5ms-10ms (depending upon the servo). Take a look at
http://www.bxdocs.com/index.asp?pi=Article:ControllingServos for some sample
(not debugged yet) code, and an explaination of how it works.

Sloan
----- Original Message -----
From: "naimead" <naimead@naim...>
To: <basicx@basi...>
Sent: Friday, May 27, 2005 8:29 PM
Subject: [BasicX] How can I move a servo to its middle position? > I tried the following code so i can move the servo to its middle
> position:
>
> *******************************************
> Sub Main()
> ' This program will move the servo to its middle position.
> Const ServoPin As Byte = 6
> Do
> ' Generate a high-going 1.5 ms pulse.
> Call PulseOut(ServoPin, 0.0015, 1)
> ' This is to produce a pulse rate of about 50 Hz.
> Call Delay(0.02)
> Loop
> End Sub
> *******************************************
>
> The result was the servo to move all the way to the left and it seemed
> that if there was any more space it could keep moving to the left!
> How can i find the real middle position of my servo? > Yahoo! Groups Links >
>




Do you have another method of generating a 1mS 50Hz signal to test the
servo? Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700