Using Boe-Bot IR to detect wheel revolutions
FragsterTX
Posts: 4
Has anyone tried using the·IR lamp and detector supplied with the Boe-Bot to measure the·revolutions of the wheels? (for accurate distance measurement).· I've done this and it works great at slower speeds but when you kick it up to full speed, there apparently isn't enough time to register each individual hole in the wheels (there are eight).· I've tried adjusting the number holes to look for but can't find anything that is reliable like the slower speed method.
I was impressed with how accurate it seems at slower speeds but obviously disappointed at higher speeds.
Here is my code (disregard the sloppiness, please).
' Robotics with the Boe-Bot - IrDistanceMeasurementTest.bs2
' Test using IR transmitter and detector to measure wheel revolutions.
' {$STAMP BS2}
' {$PBASIC 2.5}
'DEBUG "Program Running!"
'
[noparse][[/noparse] Constants ]
LeftServoMax········· CON·· 841
LeftServoMin········· CON·· 660
RightServoMax········ CON·· 850
RightServoMin········ CON·· 650
LeftServoAdj········· CON·· 850 - LeftServoMax
RightServoAdj········ CON·· 850 - RightServoMax
WheelHoles··········· CON·· 8···················· ' How many openings in Boe-Bot wheel?
'
[noparse][[/noparse] Variables ]
irDetectLeft········· VAR·· Bit
irDetectRight········ VAR·· Bit
irCount·············· VAR·· Byte
irInterrupt·········· VAR·· Bit
revolutions·········· VAR·· Word
detectsPerHole······· VAR·· Byte
previousDetects······ VAR·· Byte
'
[noparse][[/noparse] Initialization ]
DEBUG "Testing piezospeaker..."
FREQOUT 4, 2000, 3000···························· ' Signal program start/reset.
DEBUG CLS,
····· "RIGHT IR DETECTOR", CR,
····· "Detects· Revolutions", CR,
····· "
·
"
irCount = 0······································ ' Initialize detect counter variable
irInterrupt = 0·································· ' Initialize detect interrupt variable
revolutions = 0·································· ' Initialize number of revolutions variable
'
[noparse][[/noparse] Main Routine ]
DO
· 'FREQOUT 8, 1, 38500
· 'irDetectLeft = IN9
· FREQOUT 2, 1, 35500
· irDetectRight = IN0
· 'IF (irDetectLeft = 0) THEN
· '· HIGH 10
· 'ELSE
· '· LOW 10
· 'ENDIF
· IF (irDetectRight = 0) THEN
··· HIGH 1
··· IF irInterrupt = 0 THEN
····· irInterrupt = 1···························· ' Set interrupt flag to monitor next break
··· ENDIF
· ELSE
··· LOW 1
··· IF irInterrupt = 1 THEN
····· irCount = irCount + 1
····· irInterrupt = 0······························ ' Reset interrupt flag to start new detect cycle
··· ENDIF
· ENDIF
· IF irCount = 8 THEN
··· revolutions = revolutions + 1············· ' Count another full revolution
··· irCount = 0
··· END······································· ' Stop processing and verify if one full turn occurred
··· 'PAUSE 100
· ENDIF
· DEBUG CRSRXY, 2, 3, DEC5 irCount ,
······· CRSRXY, 15, 3, DEC5 revolutions
· PULSOUT 12, LeftServoMin '+ 55
· PAUSE 20
LOOP
END
I was impressed with how accurate it seems at slower speeds but obviously disappointed at higher speeds.
Here is my code (disregard the sloppiness, please).
' Robotics with the Boe-Bot - IrDistanceMeasurementTest.bs2
' Test using IR transmitter and detector to measure wheel revolutions.
' {$STAMP BS2}
' {$PBASIC 2.5}
'DEBUG "Program Running!"
'
[noparse][[/noparse] Constants ]
LeftServoMax········· CON·· 841
LeftServoMin········· CON·· 660
RightServoMax········ CON·· 850
RightServoMin········ CON·· 650
LeftServoAdj········· CON·· 850 - LeftServoMax
RightServoAdj········ CON·· 850 - RightServoMax
WheelHoles··········· CON·· 8···················· ' How many openings in Boe-Bot wheel?
'
[noparse][[/noparse] Variables ]
irDetectLeft········· VAR·· Bit
irDetectRight········ VAR·· Bit
irCount·············· VAR·· Byte
irInterrupt·········· VAR·· Bit
revolutions·········· VAR·· Word
detectsPerHole······· VAR·· Byte
previousDetects······ VAR·· Byte
'
[noparse][[/noparse] Initialization ]
DEBUG "Testing piezospeaker..."
FREQOUT 4, 2000, 3000···························· ' Signal program start/reset.
DEBUG CLS,
····· "RIGHT IR DETECTOR", CR,
····· "Detects· Revolutions", CR,
····· "
·
"
irCount = 0······································ ' Initialize detect counter variable
irInterrupt = 0·································· ' Initialize detect interrupt variable
revolutions = 0·································· ' Initialize number of revolutions variable
'
[noparse][[/noparse] Main Routine ]
DO
· 'FREQOUT 8, 1, 38500
· 'irDetectLeft = IN9
· FREQOUT 2, 1, 35500
· irDetectRight = IN0
· 'IF (irDetectLeft = 0) THEN
· '· HIGH 10
· 'ELSE
· '· LOW 10
· 'ENDIF
· IF (irDetectRight = 0) THEN
··· HIGH 1
··· IF irInterrupt = 0 THEN
····· irInterrupt = 1···························· ' Set interrupt flag to monitor next break
··· ENDIF
· ELSE
··· LOW 1
··· IF irInterrupt = 1 THEN
····· irCount = irCount + 1
····· irInterrupt = 0······························ ' Reset interrupt flag to start new detect cycle
··· ENDIF
· ENDIF
· IF irCount = 8 THEN
··· revolutions = revolutions + 1············· ' Count another full revolution
··· irCount = 0
··· END······································· ' Stop processing and verify if one full turn occurred
··· 'PAUSE 100
· ENDIF
· DEBUG CRSRXY, 2, 3, DEC5 irCount ,
······· CRSRXY, 15, 3, DEC5 revolutions
· PULSOUT 12, LeftServoMin '+ 55
· PAUSE 20
LOOP
END
Comments
I suppose I could block off all but one of the wheel openings thereby eliminating any counting but I figure that I'd run into the same problem--the apparent slowness·of the IR detector check may miss the opening at full speed.
I think I'll proceed with my little experiment and just keep the speed down an a level whereby my process works.· I'm just fooling around with programming the Boe-Bot to accurately travel xy distance.· I know there is a real IR wheel·detector kit for the boe-bot but I wanted to use the parts that came with it.
Anyway, thanks to anyone who read this and didn't say to themselves, "why in the heck would you want to do that?"
http://www.parallax.com/detail.asp?product_id=28107
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
How did you physically set up the IR detectors so that they could "see" the wheels?
Maybe you could post some pictures?
I've included a couple of shots so you can see the IR decector tie-wrapped to the Boe-Bot frame just behind the wheels and the IR lamp attached to my wonderful wooden rig around the boe-bot.
Fun stuff!
I think now I'll work on the code to monitor both wheels and·insure the bot tracks straight (one servo is faster than the other).
Thank you for the pictures FragsterTX!
I like it when people recycle their (techno-) scrap.