|
Option Explicit
Const LeftServoPin As Byte = 5
Const RightServoPin As Byte = 6
Const CenterServoPin As Byte = 7
Const LeftServoMin As Single = 0.002
Const LeftServoMid As Single = 0.0015
Const LeftServoMax As Single = 0.001
Const RightServoMin As Single = 0.001
Const RightServoMid As Single = 0.0015
Const RightServoMax As Single = 0.002
Const CenterServoLeft As Single = 0.0012
Const CenterServoMid As Single = 0.0015
Const CenterServoRight As Single = 0.0018
Const ServoCommandSleep As Single = 0.018
Const ServoPulses As Byte = 17
Const FrontSensorPin As Byte = 20
Dim SensorMonitorStack (1 To 96) As Byte
Dim ContinueMoving As Boolean
'********************************************
Public Sub Main()
ContinueMoving = True
CallTask “SensorMonitor”, SensorMonitorStack
Sleep(0.5)
Do
If ContinueMoving = True Then
Call Forward(1)
Else
Sleep(0.4)
End If
Loop
End Sub
'********************************************
Sub SensorMonitor()
Do
If GetADC(FrontSensorPin) > 225 Then
ContinueMoving = False
Call Reverse(3)
Call TurnRight(3)
ContinueMoving = True
End If
Sleep(0.2)
Loop
End Sub
'*********************************************
Sub Forward(ByVal NumSteps As Byte)
Dim i As Byte
For i=1 to NumSteps
Call SendServoCommands(LeftServoMin, RightServoMax, CenterServoRight)
Call SendServoCommands(LeftServoMax, RightServoMin, CenterServoLeft)
Next
End Sub
'*********************************************
Sub TurnLeft(ByVal NumSteps As Byte)
Dim i As Byte
For i=1 to NumSteps
Call SendServoCommands(LeftServoMin, RightServoMin, CenterServoLeft)
Call SendServoCommands(LeftServoMax, RightServoMax, CenterServoRight)
Next
End Sub
'*********************************************
Sub TurnRight(ByVal NumSteps As Byte)
Dim i As Byte
For i=1 to NumSteps
Call SendServoCommands(LeftServoMin, RightServoMin, CenterServoRight)
Call SendServoCommands(LeftServoMax, RightServoMax, CenterServoLeft)
Next
End Sub
'*********************************************
Sub Reverse(ByVal NumSteps As Byte)
Dim i As Byte
For i=1 to NumSteps
Call SendServoCommands(LeftServoMin, RightServoMax, CenterServoLeft)
Call SendServoCommands(LeftServoMax, RightServoMin, CenterServoRight)
Next
End Sub
'*********************************************
Sub SendServoCommands(ByVal LeftServoPos As Single, ByVal RightServoPos As Single, _
ByVal CenterServoPos As Single)
Dim j As Byte
For j = 1 to ServoPulses
Call PulseOut(CenterServoPin, CenterServoPos, 1)
Sleep(ServoCommandSleep)
Next
For j = 1 to ServoPulses
Call PulseOut(LeftServoPin, LeftServoPos, 1)
Call PulseOut(RightServoPin, RightServoPos, 1)
Call PulseOut(CenterServoPin, CenterServoPos, 1)
Sleep(ServoCommandSleep)
Next
End Sub
|
Robodyssey Systems manufactures Robot Kits including Autonomous Mobile
Walking Robots, Wheeled Robots, Talking Robots, Expressive Robots, and
Social Robots. We also sell Robotics Accessories including Nexcell NiMH AA
Rechargeable Batteries, Nexcell NiMH AAA Rechargeable Batteries, Battery Holders,
Velcro Straps for Battery Packs, Battery Chargers, Robot Grippers, Hobby Servos,
Servos Modified for Continuous Rotation, Tail Wheels for all Rolling Robotic Platforms,
Polyurethane Skate Wheels with Servo Adapter Hubs, Sharp IR Sensors and Adjustable
Sensor Brackets, Sensor Cables, and Programming Cables. All of our Robot Kits
can be purchased as easy to assemble robot kits or as fully assembled stationary
or mobile robots. Robodyssey uses 1/8 inch aluminum and acetyl for most all of
our mobile robot components and robotics accessories. We provide classroom
training for teachers interested in integrating robotics, computer programming
and electronics into the classroom.
We hope you enjoy our web site. Feel free to use any robotic resources.
Robodyssey is your complete solution for Educational Robotics as well as Hobby Robotics.
|