| |
'***************************************************************************
'***************************************************************************
' Description: This application demonstrates how the DS-SXM16S servo
expansion
' module can use a 24 pin BX-24 to control the servos from the on board
micro
' controller socket. The BX24 can also be programmed on the board via
the
' programming cable.
'
' Created: 09/01/03 Revision 1.0
' Written by: Total Robots (Jamie Finnan)
' Adapted from Netmedia Hobby Servo Example program.
'
'***************************************************************************
'***************************************************************************
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 ServoPin1 As Byte = 5 Servo on SV1
Const ServoPin2 As Byte = 6 Servo on SV2
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
Call PulseOut(ServoPin1,0.0015,1) Start Positions for servo1
Call Delay(0.02)
Call PulseOut(ServoPin2,0.0015,1) Start position for servo2
Call Delay(0.02)
Do
' Tilt down
For i = 40 To NSteps
' Nondimensionalize position.
Position = CSng(i) / CSng(NSteps)
Call MoveServo1(ServoPin1, Position)
Call Delay(RefreshPeriod)
Next
' Tilt Up.
For i = NSteps To 40 Step -1
' Nondimensionalize position.
Position = CSng(i) / CSng(NSteps)
Call MoveServo1(ServoPin1, Position)
Call Delay(RefreshPeriod)
Next
' Pan right
For i = 40 To NSteps
' Nondimensionalize position.
Position = CSng(i) / CSng(NSteps)
Call MoveServo2(ServoPin2, Position)
Call Delay(RefreshPeriod)
Next
' Pan Left.
For i = NSteps To 40 Step -1
' Nondimensionalize position.
Position = CSng(i) / CSng(NSteps)
Call MoveServo2(ServoPin2, Position)
Call Delay(RefreshPeriod)
Next Loop
End Sub
'***************************************************************************
Public Sub MoveServo1( _
ByVal ServoPin1 As Byte, _
ByVal Position As Single)
' Moves servo1 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(ServoPin1, PulseWidth, 1)
End Sub
'***************************************************************************
Public Sub MoveServo2( _
ByVal ServoPin2 As Byte, _
ByVal Position As Single)
' Moves servo2 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(ServoPin2, PulseWidth, 1)
End Sub
'***************************************************************************
'***************************************************************************
|