Hi everyone. Our team (Team 1884) has been trying to use ultrasonics for this year’s game. We’ve been successful in using an analog sensor but are facing trouble in reading from the Parallax digital ultrasonic sensors. Since the Ultrasonic Java class should work with our Parallax model (according to the documentation), we decided to use it.
Below is our code (parallax is an Ultrasonic object that has been properly constructed, enabled, and initialized in the code):
public double parallaxValue()
{
parallax.ping();
Timer.delay(0.05);
double parallaxReading = parallax.getRangeInches();
System.out.println("Parallax: " + parallaxReading + " inches");
return parallaxReading;
}
Unfortunately, this is always returning 0.04068 inches, regardless of which way the sensor points. We tried the getRangeMM() method but that just returned a constant of 1.033272 mm, which is just 25.4 mm/in * 0.04068 inches. We also tried changing the Timer delay, but to no avail.
We don’t see why this is happening since the ultrasonic just takes the amount of time it takes for a pulse to return, multiplies it by the speed of sound (in inches/sec), and divides that distance by two.
We’d really appreciate some input on why we always get this value. Has anyone else also tried the Parallax ultrasonic and gotten it to work?
Thank you,
Team 1884