Sonar Code...
Hi John and Everyone,
Here is the code that I am using with the 6500 sonar module:
Thanks for your time,
Tim
'================================================
' POLAROID RANGING TEST PROGRAM - 11/26/2000
'================================================
'
'BSII CONFIGURATION OF PINS USED
Output 0 'Serial out to LCD display.
Output 14 'Ranging module control.
Input 15 'Input from ranging module.
'
'INITIALIZE LCD DISPLAY
Pause 2000 'Pause for the LCD display/driver backpack to initialize.
'
'VARIABLES
TIMEOFFLIGHT var word 'Echo variable from ranging module.
DISTANCE var word 'Working variable for calculating distance.
'
'CONSTANTS
ECHO con 15 'Ranging module echo result.
INIT con 14 'Ranging module control.
SETTLE con 1 'Delay to ensure proper ranging module initialization.
DELAY con 2000 'Time between sonar samples - in milliseconds.
CONVFACT con 74 'Result in inches. See CONVERSION FACTORS below.
OFFSET con 700 'Delay between start of sonar reading and measurement of result
- prevents false measurement.
'
'
MAIN_LOOP:
Gosub PING_CALC
Serout 0,$4054,[noparse][[/noparse]254,1] 'Clear the LCD display and reset cursor position.
Pause 2 'Pause for LCD display to clear and cursor position to reset.
Serout 0,$4054,[noparse][[/noparse]"DISTANCE: ",dec3 DISTANCE,"in"] 'Send the title and distance
result to the LCD display.
Pause DELAY 'Time between sonar samples.
Goto MAIN_LOOP
'
'
PING_CALC:
High INIT
Pause SETTLE
Rctime ECHO,0,TIMEOFFLIGHT
Low INIT
'
'DISTANCE FORMULA AND CONVERSION FACTORS
'Distance = (timeofflight + offset time) / (conversion factor)
'Use 74 as a conversion factor for inches. (73.764 microseconds per in.)
'Use 29 as a conversion factor for centimeters. (29.033 microseconds per cm.)
'
DISTANCE=(TIMEOFFLIGHT+OFFSET)/CONVFACT
Return
'
Here is the code that I am using with the 6500 sonar module:
Thanks for your time,
Tim
'================================================
' POLAROID RANGING TEST PROGRAM - 11/26/2000
'================================================
'
'BSII CONFIGURATION OF PINS USED
Output 0 'Serial out to LCD display.
Output 14 'Ranging module control.
Input 15 'Input from ranging module.
'
'INITIALIZE LCD DISPLAY
Pause 2000 'Pause for the LCD display/driver backpack to initialize.
'
'VARIABLES
TIMEOFFLIGHT var word 'Echo variable from ranging module.
DISTANCE var word 'Working variable for calculating distance.
'
'CONSTANTS
ECHO con 15 'Ranging module echo result.
INIT con 14 'Ranging module control.
SETTLE con 1 'Delay to ensure proper ranging module initialization.
DELAY con 2000 'Time between sonar samples - in milliseconds.
CONVFACT con 74 'Result in inches. See CONVERSION FACTORS below.
OFFSET con 700 'Delay between start of sonar reading and measurement of result
- prevents false measurement.
'
'
MAIN_LOOP:
Gosub PING_CALC
Serout 0,$4054,[noparse][[/noparse]254,1] 'Clear the LCD display and reset cursor position.
Pause 2 'Pause for LCD display to clear and cursor position to reset.
Serout 0,$4054,[noparse][[/noparse]"DISTANCE: ",dec3 DISTANCE,"in"] 'Send the title and distance
result to the LCD display.
Pause DELAY 'Time between sonar samples.
Goto MAIN_LOOP
'
'
PING_CALC:
High INIT
Pause SETTLE
Rctime ECHO,0,TIMEOFFLIGHT
Low INIT
'
'DISTANCE FORMULA AND CONVERSION FACTORS
'Distance = (timeofflight + offset time) / (conversion factor)
'Use 74 as a conversion factor for inches. (73.764 microseconds per in.)
'Use 29 as a conversion factor for centimeters. (29.033 microseconds per cm.)
'
DISTANCE=(TIMEOFFLIGHT+OFFSET)/CONVFACT
Return
'
Comments
Thank you for sharing that code. Verrrrrrrrry interesting!
Is that 2 second delay between sonar samples required
for proper ranging? Is it there to let the batteries 'rest'
between firings?
I'm wondering, given a supply with enough oomph, how
fast one can get back to back readings.
Regards,
Steve
As I mentioned, this code is an example from Acroname Robotics. I've added
the 2 second delay for testing purposes - the module is capable of taking
samples every 20 miliseconds.
Tim
Original Message
From: PicProgrammer@a... [noparse]/noparse]SMTP:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=9KUdF9SPQIMYd4o17S29oXgq86RjT6KUs_BlQZTtdvLEx9U0SyEGmRfPGm6uK63gkh0RgiKFwAwCsOs]PicProgrammer@a...[/url
Sent: Wednesday, November 29, 2000 11:46 AM
To: basicstamps@egroups.com
Subject: Re: [noparse][[/noparse]basicstamps] Sonar Code...
Tim,
Thank you for sharing that code. Verrrrrrrrry interesting!
Is that 2 second delay between sonar samples required
for proper ranging? Is it there to let the batteries 'rest'
between firings?
I'm wondering, given a supply with enough oomph, how
fast one can get back to back readings.
Regards,
Steve