cork.module.devantech
Class SRF04

cork.module.devantech.SRF04
All Implemented Interfaces:
Device

public class SRF04
implements Device

Software driver for the Devontech SRF04 Range Finder.

in order to improve accuracy, the you may set the air temperature that the range finder is working in. If you don't set it, it will default to 25 degrees celsius which will be an average comfortable household temperature for most people.
The ping() method will block for aproximatly 360 milliseconds to allow the ranger to take 10 reading to the target, this will be used to find the average variation which was noted to exist during testing of the original example code from Systronix Inc.

Example of usage:

SRF04Ultrasonic sonar = new SRF04Ultrasonic(0);
sonar.setAirTemperature(15);
while(true){
sonar.ping();
int range = sonar.getRangeInCentimetres();
... do something with the range ...
}
 

This class is heavily based on example code provided my Systronix Inc. The original example was written by John Hartogh, with modifications by Bruce Boyes.

Version:
0.1.4
Author:
Brill Pappin

Field Summary
static double AIR_TEMPERATURE_CELSIUS_0
          The 0 degrees celsius (C) for speed-of-sound calculations: 0C Water freezes at 0C.
static double AIR_TEMPERATURE_CELSIUS_100
          The 100 degrees celsius (C) for speed-of-sound calculations: 0C Water boils at 0C (at sea level).
static double DEFAULT_AIR_TEMPERATURE_CELSIUS
          The default air temperature in celsius (C) for speed-of-sound calculations: 25C
 
Constructor Summary
SRF04(int timerId)
          Constructor for the SRF04Ultrasonic object
 
Method Summary
 void addResouceDevice(Device device)
          Adds another device to this so that device so that this device can use it's resources.
 double getAirTemperature()
          The speed of sound in air are is effected by many variables, among them is the temperature of the air.
 java.lang.String getDeviceDestription()
          Gets the destription attribute of the Device object
 java.lang.String getDeviceName()
          Gets the title attribute of the Device object
 int getEchoTimeInMicroseconds()
          Gets the round-trip echo time in microseconds attribute of the SRF04 object
 int getRangeInCentimetres()
          Gets the range from the SRF04 to the target in centimetres (cm).
 int getRangeInCentimetres(double temperatureInC)
          Gets the range from the SRF04 to the target in centimetres calculated with the termperature supplied.
 int getRangeMaximumInCentimetres()
          Gets the maximum range measured in centimetres out of 10 pulses.
 int getRangeMinimumInCentimetres()
          Gets the minimum range measured in centimetres out of 10 pulses.
 double getRangeVariationInCentimetres()
          Gets the error variation that was observed in centimetres.
 int getTimerID()
          Gets the Timer ID of the SRF04 object.
 void interruptEvent()
          Internal use only!
The event handler, triggered by the trailing edge of the echo pulse.
 boolean isDebugMode()
          Gets the debugMode attribute of the ConsoleDebug object
 boolean isOutputOnLineA()
          Gets the outputOnLineA attribute of the SRF04Ultrasonic object
 boolean isOutputOnLineB()
          Gets the outputOnLineB attribute of the SRF04Ultrasonic object
 boolean isResourceDevice(Device device)
          Checks to see if a device has already been bound to this device.
 boolean ping()
          Use this method to "ping" a target.
 boolean pingAndListen()
          This method does nothing.
 void removeResouceDevice(Device device)
          Removes another device from this device so that this device can no longer use it's resources.
 void setAirTemperature(double temperature)
          The speed of sound in air are is effected by many variables, among them is the temperature of the air.
 void setDebugMode(boolean debug)
          Sets the debugMode attribute of the ConsoleDebug object.
 void setOutputOnLineA()
          Sets the outputOnLineA attribute of the SRF04Ultrasonic object
 void setOutputOnLineB()
          Sets the outputOnLineB attribute of the SRF04Ultrasonic object
 

Field Detail

DEFAULT_AIR_TEMPERATURE_CELSIUS

public static final double DEFAULT_AIR_TEMPERATURE_CELSIUS
The default air temperature in celsius (C) for speed-of-sound calculations: 25C
Since:
0.1.0

AIR_TEMPERATURE_CELSIUS_0

public static final double AIR_TEMPERATURE_CELSIUS_0
The 0 degrees celsius (C) for speed-of-sound calculations: 0C Water freezes at 0C.
Since:
0.1.0

AIR_TEMPERATURE_CELSIUS_100

public static final double AIR_TEMPERATURE_CELSIUS_100
The 100 degrees celsius (C) for speed-of-sound calculations: 0C Water boils at 0C (at sea level).
Since:
0.1.0
Constructor Detail

SRF04

public SRF04(int timerId)
Constructor for the SRF04Ultrasonic object
Parameters:
timerId - The ID of the timer we're going to use [0|1]
Since:
0.1.0
Method Detail

interruptEvent

public void interruptEvent()
Internal use only!
The event handler, triggered by the trailing edge of the echo pulse. This method should not be called by external applications.
Since:
0.1.0

ping

public boolean ping()
Use this method to "ping" a target. The method will block for approximatly 360 mSec. The timing is not arbitrary. At 360 mSec the SRF04 will have time to send out 10 pulses and will use them to calculate the average variation in the range. This method also helps prevent external classes from trying to read the range values while the SRF04 is in the middle of a "ping". If you where to allow the SRF04 to ping while you read the values, you would get bad data at random intervals.
Returns:
boolean true if the ping was successful, false otherwise. If this method is not implemented in the instance class, it should always return false.
Since:
0.1.3

pingAndListen

public boolean pingAndListen()
This method does nothing. There are no event listeners implemented for this class.
Returns:
boolean true if the ping was successful, false otherwise. If this method is not implemented in the instance class, it should always return false.
Since:
0.1.5

addResouceDevice

public void addResouceDevice(Device device)
Adds another device to this so that device so that this device can use it's resources. e.g. a temperature device might be bound to an ultrasonic ranger to get better readings as ultrasound is dependant on temperature.
Parameters:
device - the device to add to this device.
Since:
0.1.1

removeResouceDevice

public void removeResouceDevice(Device device)
Removes another device from this device so that this device can no longer use it's resources.
Parameters:
device - the device to remove.
Since:
0.1.1

isDebugMode

public boolean isDebugMode()
Gets the debugMode attribute of the ConsoleDebug object
Returns:
boolean true if the class is in debug mode, false otherwise.
Since:
0.1.0

getTimerID

public final int getTimerID()
Gets the Timer ID of the SRF04 object.
Returns:
The Timer ID [0|1]
Since:
0.1.0

getAirTemperature

public final double getAirTemperature()
The speed of sound in air are is effected by many variables, among them is the temperature of the air. Use this attribute to improve the accuracy of the range finder. The default is 25 degrees celsius (C).
Returns:
the temperature of the air in degrees celsius
Since:
0.1.2

getEchoTimeInMicroseconds

public int getEchoTimeInMicroseconds()
Gets the round-trip echo time in microseconds attribute of the SRF04 object
Returns:
The round trip echo time in microseconds (uSec).
Since:
 

getRangeMaximumInCentimetres

public final int getRangeMaximumInCentimetres()
Gets the maximum range measured in centimetres out of 10 pulses.
Returns:
The maximum range measured
Since:
0.1.4

getRangeMinimumInCentimetres

public final int getRangeMinimumInCentimetres()
Gets the minimum range measured in centimetres out of 10 pulses.
Returns:
The minimum range measured
Since:
0.1.4

getRangeVariationInCentimetres

public final double getRangeVariationInCentimetres()
Gets the error variation that was observed in centimetres. The value returned is the amount of variation +/- that the range finder measured. The range in centimetres that the getRangeInCentimetres() method returns will already be corrected for this variation.
Returns:
The amount of +/- variation in centimetres.
Since:
0.1.4

getRangeInCentimetres

public int getRangeInCentimetres()
Gets the range from the SRF04 to the target in centimetres (cm).
Returns:
The range in centimetres.
Since:
0.1.0

getRangeInCentimetres

public int getRangeInCentimetres(double temperatureInC)
Gets the range from the SRF04 to the target in centimetres calculated with the termperature supplied.
Parameters:
temperatureInC - the temperature of the air in degrees celsius.
Returns:
The range to the target in centimetres.
Since:
0.1.0

isOutputOnLineB

public final boolean isOutputOnLineB()
Gets the outputOnLineB attribute of the SRF04Ultrasonic object
Returns:
The outputOnLineB value
Since:
 

isOutputOnLineA

public final boolean isOutputOnLineA()
Gets the outputOnLineA attribute of the SRF04Ultrasonic object
Returns:
The outputOnLineA value
Since:
 

getDeviceName

public java.lang.String getDeviceName()
Gets the title attribute of the Device object
Specified by:
getDeviceName in interface Device
Returns:
The title value
Since:
0.1.0

getDeviceDestription

public java.lang.String getDeviceDestription()
Gets the destription attribute of the Device object
Specified by:
getDeviceDestription in interface Device
Returns:
The destription value
Since:
0.1.0

isResourceDevice

public boolean isResourceDevice(Device device)
Checks to see if a device has already been bound to this device.
Parameters:
device - The device to check.
Returns:
boolean true if the specified device has already been bound, false otherwise.
Since:
0.1.1

setAirTemperature

public final void setAirTemperature(double temperature)
The speed of sound in air are is effected by many variables, among them is the temperature of the air. Use this attribute to improve accuracy of the range finder. The default is 25 degrees celsius (C).
Parameters:
temperature - The temperature of the air in degrees celsius.
Since:
0.1.1

setDebugMode

public void setDebugMode(boolean debug)
Sets the debugMode attribute of the ConsoleDebug object.
Parameters:
debug - boolean true the class will print to the console any debug messages at its discretion, false to turn off the debug messages.
Since:
0.1.0

setOutputOnLineB

public final void setOutputOnLineB()
Sets the outputOnLineB attribute of the SRF04Ultrasonic object
Since:
 

setOutputOnLineA

public final void setOutputOnLineA()
Sets the outputOnLineA attribute of the SRF04Ultrasonic object
Since: