RoboJDETM v2.0

com.ridgesoft.robotics.sensors
Class SharpGP2D12

java.lang.Object
  extended by com.ridgesoft.robotics.sensors.SharpGP2D12
All Implemented Interfaces:
RangeFinder
Direct Known Subclasses:
SharpGP2Y0A02, SharpGP2Y0A21

public class SharpGP2D12
extends Object
implements RangeFinder

Class to interface with the Sharp GP2D12 infrared range finder.


Field Summary
protected  AnalogInput mInput
           
protected  DigitalOutput mPowerControl
           
protected  int mSample
           
protected  float mScaleFactor
           
 
Constructor Summary
SharpGP2D12(AnalogInput input, DigitalOutput powerControl)
          Constructs a SharpGP2D12 range finder object.
 
Method Summary
 float getDistanceCm()
          Gets the distance to the nearest object in centimeters based on an curve fitting apporximation of the output voltage verse distance curve.
 float getDistanceInches()
          Gets the distance to the nearest object in inches based on an curve fitting apporximation of the output voltage verse distance curve.
 void ping()
          Powers the sensor on if necessary and takes a sample.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Field Detail

mInput

protected AnalogInput mInput

mPowerControl

protected DigitalOutput mPowerControl

mSample

protected int mSample

mScaleFactor

protected float mScaleFactor
Constructor Detail

SharpGP2D12

public SharpGP2D12(AnalogInput input,
                   DigitalOutput powerControl)
Constructs a SharpGP2D12 range finder object.

Parameters:
input - analog input receiving sensor output
powerControl - digital output used to control the power to the sensor. Should be null if power is always on. When power switching is used, the ping method sleeps for 70 milliseconds after powering up the sensor.
Method Detail

getDistanceCm

public float getDistanceCm()
Gets the distance to the nearest object in centimeters based on an curve fitting apporximation of the output voltage verse distance curve.

Specified by:
getDistanceCm in interface RangeFinder
Returns:
distance in inches or -1 if out of valid measurement range

getDistanceInches

public float getDistanceInches()
Gets the distance to the nearest object in inches based on an curve fitting apporximation of the output voltage verse distance curve.

Specified by:
getDistanceInches in interface RangeFinder
Returns:
distance in inches or -1 if out of valid measurement range

ping

public void ping()
Powers the sensor on if necessary and takes a sample.

Note: The sensor has an ~50 millisecond sample frequency. This method sleeps for 70 milliseconds after powering the sensor on if a powerEnable was provided in the constructor.

Specified by:
ping in interface RangeFinder

RoboJDETM v2.0

Copyright (c) 2003-2009 RidgeSoft, LLC. All rights reserved.
www.ridgesoft.com