The oIRRange Object is a Hardware Object that uses one I/O line to read a Sharp GP2D12 distance detector in a 64 steps per foot reading. Sharp GP2D12 can precisely and reliably read the distance to an from 10cm-80cm away.
The oIRRange Object calculates a value based on how far away the obstacle is from the sensor.
The following table lists the size and availability of the oIRRange Object.
The oIRRange Object reads the output signal from a Sharp GP2D12 IR ranging module and calculates a number that indicates the distance between the GP2D12 and its target. It expects that the signal is being provided by a Sharp GP2D12 Module connected to the I/O line specified by the IOLine property. The distance value that is calculated (which is measured in 64 steps per foot) is stored in the Distance property.
Each Sharp GP2D12 Module appears to return slightly different readings. The Adjust property was added in firmware version B.2.0 to allow the input value from the Sharp GP2D12 to be adjusted. When connecting a new Sharp GP2D12 Module, the Adjust property needs to be adjusted so that when nothing is in front of it, the oIRRange Object returns a steady reading of 128. The most common Adjust values are between 0 and 10.
When created, the oIRRange Object also creates an instance of the oA2DX object which it uses to read the output signal from the sensor. The instance of the oA2DX is configured to use a 5 volt reference and modifying that or any other properties of the oA2DX instance will affect the oIRRange Object's operation in ways that could make the oIRRange Object unable to read the sensor. See the oA2DX Help for more detail on how analog signals (such as the signal form the Sharp GP2D12 IR ranging module) are read.
In the following example, the oIRRange Object is used.
Visual Basic Syntax
C and Java Syntax
'This program reads a Sharp
'GP2D12 and outputs the binary
'result on a oDio8.
Dim I As New oIRRange
Dim P As New oDIO8
Sub Main()
I.IOLine = 3
I.Operate = 1
I.Adjust = 8
P.IOGroup = 1
P.Direction = cvOutput
Do
P.Value = I.Value
Loop
End Sub
// This program reads a Sharp
// GP2D12 and outputs the binary
// result on a oDio8.
oIRRange I = New oIRRange;
oDIO8 P = New oDIO8;
Void Main(Void){
I.IOLine = 3;
I.Operate = 1;
I.Adjust = 8;
P.IOGroup = 1;
P.Direction = cvOutput;
Do{
P.Value = I.Value;
} While (1);
}
Basic Syntax
'This program reads a Sharp
'GP2D12 and outputs the binary
'result on a oDio8.
I As oIRRange(3,8,cvOn)
P As oDIO8(1,cvOutput)
Do
P.Value = I.Value
Loop
The oIRRange Object uses 1 I/O line. The I/O line can be any 1 of the analog I/O lines. As shown, a Sharp GP2D12 is connected in a circuit with a capacitor.