|
'******************************************************
'****************** Brightest Light *******************
'brightestlight - Mouse with ONE VDB with photoresistor
'@ Platform: NetMedia BasicX 24
'@ Version: 2.0
'@ Author: Chris D. Odom (chris_odom@georgeschool.org)
' Robodyssey Systems, LLC. - www.robodyssey.com
'@ Last Updated: August 21, 2003
'May be freely distributed and modified, but must contain above information
'******************************************************
' The Robodyssey Mouse uses ONE Robodyssey VDB with a photoresistor pointing
' forward. The Mouse turns approximately 360 degrees,
' making light readings with every rotation. As the
' Mouse rotates, it keeps track of the position of the brightest
' light (lowest voltage). The mouse will then turn directly to that
' position and start moving toward the light.
' IR sensors are not used. I plugged the VDB into RAMB pin 8 (BX-24 pin #13).
' The number of steps for MY Mouse to complet a complete circle moving clockwise:
'.....................................................x <-- Start and Finish the clockwise turn here (29-30 steps)
'.....................................................|
'3/4 Turn is 21-22 steps --> 3/4 -- -- 1/4 <-- Quarter turn is 7-8 steps
'.....................................................|
'....................................................1/2 <-- Half turn is 15 steps
' Before the demonstration, perform the following steps.
' 1. Use a Debug app to calibrate photoresistors (PR) -- essentially ensure the PR has an appropriate range
' bright to dark.
' 2. Determine how many steps are required for YOUR Mouse to make one complete revolution. Change the
' constant named MaxSteps below.
' 3. Run program with Mouse in uniformly lit room, but with an obviously bright light pointing at Mouse.
' Teachers should ask students to add some lines to below application to do the following:
' 1: Make the program run quicker.
' 2: Make the Mouse turn Clockwise OR Counterclockwise to reach the brightest position once
' that position has been determined, whichever is quickest.
' 3: Once the Mouse is moving forward, have it use its IR sensors to stop before hitting a wall.
' 4: Have the Mouse take 10 reading of the Photoresistor values 10 times and calculate the
' average for each step.
' 5: Add Subroutines (Subprograms) to make the below code easier to read.
' 6: Make use of Arrays and have the Mouse find the THREE brightest lights surrounding it and then
' rotate to face each of them in order from least bright to brightest with a small pause in between.
'******************************************************
Option Explicit
'Declare Servo Constants - min 0.001 max 0.002
Public Const Left_Forward As Single = 0.002
Public Const Right_Forward As Single = 0.001
Public Const Left_Reverse As Single = 0.001
Public Const Right_Reverse As Single = 0.002
'Servo Pins
Public Const LeftServo As Byte = 5 ' (Pin #0 on RAMB)
Public Const RightServo As Byte = 6 ' (Pin #1 on RAMB)
'Photoresistor (PR) Pins
Const PRF As Byte = 13 ' Sensor looking forward (Pin #8 on RAMB)
' The number of steps necessary for YOUR Mouse to make one revolution. May be battery dependent?
' MY Mouse requires roughly 29 steps to turn 360 degrees (~12.4 degrees per step)
Const MaxSteps as Integer = 29
'******************************************************
'********************* Main Loop **********************
Sub Main()
Dim i as Integer
Dim BrightestPos as Integer
Dim LightValue as Integer
Dim BrightestLight as Integer
BrightestPos = 0 ' Initial value. Initial look direction is 0 by default
BrightestLight = 1023 ' Default is darkest possible value, 1023.
' Make Mouse rotate through one complete circle and read the photoresistor before taking each step
For i = 0 to (MaxSteps - 1) ' Start with 0 not 1
' Read the VDB Photogate
LightValue = GetADC(13) ' Get value of Forward Photoresistor
Debug.Print "Step = " & CStr(i) & " Light = " & CStr(LightValue) ' Print Step and LightValue to screen
' Determine if current light value is brightest (lowest)
If (LightValue < BrightestLight) then
BrightestLight = LightValue
BrightestPos = i
Debug.Print "BrightestPos = " & CStr(BrightestPos) ' Print BrightestPos to screen
End If
' Turn Right
Call PulseOut(LeftServo, Left_Forward, 1)
Call PulseOut(RightServo, Right_Reverse, 1)
Delay(0.500) ' Some arbitrary delay > 20ms (0.020s) needed by servos
Next
' Now that the brightest position has been determined, turn Mouse (Clockwise) to face the brightest light
Debug.Print
Debug.Print "Rotating to position " & CStr(BrightestPos) & ", the brightest light..."
For i = 0 to BrightestPos ' it MAY be best if you run from 0 to (BrightestPos - 1)? A last second tweak?
' Turn Right
Call PulseOut(LeftServo, Left_Forward, 1)
Call PulseOut(RightServo, Right_Reverse, 1)
Delay(0.250) ' Moving faster
Next
' Move the Mouse forward toward the brightest light indefinitely
Debug.Print
Debug.Print "Move toward the brightest light..."
Do
' Move forward
Call PulseOut(LeftServo, Left_Forward, 1)
Call PulseOut(RightServo, Right_Forward, 1)
Delay(0.050) ' Moving much faster
Loop
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.
|