oSonarDV Object

Main Index
Object List
Back to top of page Description:
 

The oSonarDV is a Hardware Object that reads an Devantech SRF04 Ultrasonic Range Finder and measures the distance between the sonar transducer and its target in 64 steps per foot increments.

 

 The following table lists the size and availability of the oSonarDV Object.
 ObjectSizeDescriptionA1A2B1B2C1
oSonarDV6 BytesReads a Devantech SRF04 Ultrasonic Range Finder.xxx
Back to top of page Operation:
 

The oSonarDV Object handles all the necessary I/O timing required to communicate with the Devantech SRF04 and measures the distance between the sonar module and its target in 64 steps per foot increments. 

When the oSonarDV Object's Operate property transitions from 0 to 1, the sonar unit is instructed to send a ping signal, the Transmitting property is set to 1 and the Received property is cleared to 0.  After which, the oSonarDV Object waits for an echo.  Once the echo is received, the time-of-flight of the echo is stored in the Distance property, the Transmitting property is cleared to 0 and the Received property is set to 1.

If no echo was received after a short period of time, the Transmitting property is cleared to 0 and the TimeOut property is set to 1.

A single sonar ping is sent for each time that the Operate property transitions from 0 to 1 which results in a single sonar reading being updated into the Distance property.  This is different than most of the other ooPIC Objects which continually update the properties.  This difference was designed into the oSonarDV Object so that multiple sonar units could be controlled without Ultrasonic interference between them.

To continually update the Distance property, the Operate property needs to be toggled at the rate that the sonar needs to be monitored.  This can be accomplished by linking the Output property of an oClock to the Operate property of the oSonarDV Object.

The FeedBack property is an instance of the oFeedBack1T Object which is created when the oSonarDV Object is.  The oSonarDV Object uses the oFeedBack1T Object to do the actual ping/echo timing for the sonar.  (see oFeedBack1T Object for more detail on how the sonar is controlled.)

Back to top of page Properties:

The following table lists the properties of the oSonarDV Object:

Property

Description

Distance
A value that indicates the distance to the item in front of the sonar.
Object Class: oDistance2 Value Range: 0 - 32768*
Data Type: Numeric Default Value: 0
*The maximum distance that the Devantech SRF04 Range Finder will detect a target is 9.8 Feet.  9.8 Feet * 64 steps per foot = 627.  Therefore, the maximum meaningful value that Distance will return is 627.
Transmitting
A value that indicates that the sonar has pinged.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
TransmittingConstantDescription
0cvFalseThe oSonarDV is not waiting for an Echo.
1cvTrueThe oSonarDV is waiting for an Echo.
Received
A value that indicates that an echo was received.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
ReceivedConstantDescription
0cvFalse

An Echo was not received.

1cvTrueAn Echo was received and the Distance property was updated.
TimeOut
A value that indicates that the sonar ping went out of range.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
TimeOutConstantDescription
0cvFalse

An Echo was received or the oSonarDV is still waiting for an Echo.

1cvTrueAn Echo was not received.
IOLineE
A value that specifies which I/O Line is connected to the Echo signal.
Object Class: oIOLine Value Range: 0 - 31
Data Type: Numeric Default Value: 0
Some I/O Lines have special purposes.  Be sure to see oIOLine help file for details.
IOLineP
A value that specifies which I/O Line is connected to the Ping signal.
Object Class: oIOLine Value Range: 0 - 31
Data Type: Numeric Default Value: 0
Some I/O Lines have special purposes.  Be sure to see oIOLine help file for details.
Operate
A value that selects when the sonar is to send a ping.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOff

A ping is not sent.

1cvOn

A ping is sent.

FeedBack
The I/O function object used to measure the time-of-flight of the sonar ping.
Object Class: oFeedBack1T Value Range: 0 - 32768
Data Type: Numeric Default Value: 0
Address
Returns a pointer to the address of the oCounter Object instance.
Object Class: oAddress Value Range: 0 - 127
Data Type:Pointer (Read Only) Default Value: Address of Object

Back to top of page Examples:
 In the following example, the oSonarDV Object is used.
Visual Basic SyntaxC and Java Syntax
'This program reads an oSonarDV
'Object and outputs the distance
'on Scott Edwards LCD.

Dim A As New oSonarDV
Dim D As New oLCDSE

Sub Main()
  A.IOLineE = 31
  A.IOLineP = 30
  A.Operate = 1  
  D.IOLine = 16 
  Do  
    A.Operate.Pulse(1,1,250)
    D.Clear
    D.VString = Str$(A/64)+"."+Str$(A Mod 64)
  Loop  
End Sub 
// This program reads an oSonarDV
// Object and outputs the distance
// on Scott Edwards LCD.

oSonarDV A = New oSonarDV;
oLCDSE D = New oLCDSE;

Void Main(Void){
  A.IOLineE = 31;
  A.IOLineP = 30;
  A.Operate = 1;
  D.IOLine = 16;
  Do{
    A.Operate.Pulse(1,1,250);
    D.Clear;
    D.VString = Str$(A/64)+"."+Str$(A Mod 64);
  } While (1);
}
Basic Syntax 
'This program reads an oSonarDV
'Object and outputs the distance
'on Scott Edwards LCD.

A As oSonarDV(31,30,cvOn)
D As oLCDSE(16)

Do  
  A.Operate.Pulse(1,1,250)
  D.Clear
  D.VString = Str$(A/64)+"."+Str$(A Mod 64)
Loop
 
Back to top of page Connections:
The oSonarDV uses 2 I/O lines and 2 power lines.  The 2 I/O lines can be any 2 I/O lines of the ooPIC's 31 I/O lines.  The SRF04 Ultrasonic Range Finder requires a 5 Volt power supply that is capable of handling roughly 50mA of continuous output.
Devantech SRF04 Ultrasonic Range Finder
PinNameDescriptionI/O NameooPIC
I/O Line
15v+5 Volt power  
2EchoEcho OutputIOLineEAny
3TriggerPulse Trigger InputIOLinePAny
4DNUDo Not Use  
50v GroundPower Return G

Back to top of page Related Items:

 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oSonarPLReads a Polaroid 6500 sonar ranging module.xxx
Back to top of page Version History and Bug List:
 Firmware Ver B1: Introduced.

Bugs: No known bugs.


ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.