Programming for sonar with MaxRobotix Sensor

Hi, we are trying to get a reading from our MaxRobotix Sensor that we have plugged into pin 1 of the Analog input. We are using java (NetBeans) for programming. Some of our code:

Declaring variable:
public static final Button ultrasonicSensor = new AnalogIOButton(1);

And inside out Autonomous section, we simply print out ultrasonicSensor.get();

It would be greatly appreciated if someone could help us get a reading from our sensor so that we can work with it

You can get a reading from a sensor by getting the voltage output by the sensor. Which can be done like this:

private AnalogChannel ultrasonic = new AnalogChannel(1);
private double voltage = ultrasonic.getVoltage();

To get inches from the sensor I THINK you need to multiply the output voltage by 100. again I’m not positive. This is info I carried over from Labview. I see no reason it would be different.

If you’re using the maxbotix LV-MaxSonar-EZ sensor, there’s a good guide here:
http://www.maxbotix.com/articles/016.htm

This page includes details on converting the measured analog value to a distance in inches.

Hey,
So we used an unltrasonic sensor on two of the robots I worked on, and both times we used the .get() method, it returns integers that correspond to distance (in an arbitrary unit). Should work fine either way.

As for your problem, we noticed that we got strange issues when we had something connected to both analog 1 and 2, we’re still not sure why, but if both were connected one or both wouldn’t work (I don’t remember the exact symptoms). We found this problem when working with a gyro, so it could have been specific to a gyroscope, but it might not be. Regardless, you could try switching the port you are using.

Also, I just realized you are using this as a AnalogIOButton object? Is this a sensor on the driver station or on the robot? If this sensor is plugged into the cRio Analog Card (which is what I had assumed, and the above information is referring to), then I believe this should be an AnalogChannel Object. If not, what is the purpose of the sensor? and what is it’s use in autonomous mode, because driver station inputs are disregarded in autonomous?

Isn’t Analog1 used for battery voltage?

Analog input 8 is disabled/enabled by the breakout jumper for the battery feed.
The Analog input pins closest to the jumper.

Oh. I knew it was one of them at the end… :o