Parallax Java Implementation?

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()
        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

Sorry to double post, but has any team successfully used a Parallax sensor before? If so, how do they work (and would they work with the code I posted above)?

We’d really appreciate some help with this!

Team 1884

Are you talking about the Parallax “Ping” sensor? I believe that it only has a single I/O line and is not supported. The maxbotics sensors that return analog values work very well, also the Vex/Davantech sensors work. The Vex and Daventech SRF04 sensors have have two lines, one to do the ping and another to read the return timing.