Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Trouble with MaxBotics Ultrasonic Sensor EZ-1 (http://www.chiefdelphi.com/forums/showthread.php?t=102049)

LunaEques 05-02-2012 17:35

Trouble with MaxBotics Ultrasonic Sensor EZ-1
 
Our team is trying to implement an ultrasonic sensor, but we are unable to get it to read a proper distance. We have written our own sensor class, but the getDistance function does not return the proper distance. We had some trouble wiring it, but we finally figured it out. Here is our code:

In class TPARobot:

public void runUltrasonicSensor(Joystick aStick, TPAUltrasonicAnalogSensor aSensor){
if (shoot8ButtonPressable && aStick.getRawButton(8)){
ultrasonicSensorOn = flipBoolean(ultrasonicSensorOn);
if(DEBUG == true){
theDriverStationLCD.println(DriverStationLCD.Line. kUser2, 1 , "RunUltrasonicSensor recognizes button 8 press" );
System.out.println("RunUltrasonicSensor recognizes button 8 press");
}
shoot8ButtonPressable = false;
}
if (!shoot8ButtonPressable && !aStick.getRawButton(8)){
shoot8ButtonPressable = true;
theDriverStationLCD.println(DriverStationLCD.Line. kUser2, 1 , "In else statement" );
System.out.println("In else statement");

}
if (ultrasonicSensorOn == true){
aSensor.enable();
theDistance = aSensor.getDistance();
theAccumulatedDistance = theAccumulatedDistance + theDistance;
theDistancesCollected = theDistancesCollected + 1;
if (theDistancesCollected == theAveragingValue){
theAveragedDistance = theAccumulatedDistance/theDistancesCollected;
theDriverStationLCD.println(DriverStationLCD.Line. kUser6,1, "" + theAveragedDistance);
theAccumulatedDistance = 0;
theDistancesCollected = 0;
}
if(DEBUG == true){
theDriverStationLCD.println(DriverStationLCD.Line. kUser4, 1 , "Sensor Enabled " );
System.out.println("Sensor Enabled");
}
}
else{
aSensor.disable();
theDriverStationLCD.println(DriverStationLCD.Line. kUser6,1, "Sensor not Enabled ");
if(DEBUG == true){
theDriverStationLCD.println(DriverStationLCD.Line. kUser4, 1 , "Sensor Disabled" );
System.out.println("Sensor Disabled");
}
}
}

The TPAUltrasonicSensor Class:

TPAUltrasonicAnalogSensor(int aDigitalChannel, int aAnalogChannel){
theDigitalOutput = new DigitalOutput (aDigitalChannel);
theAnalogOutput = new AnalogChannel (aAnalogChannel);
theScaling = 5.0/512;
theDistance = 0;
}

public double getDistance(){
aVoltage = theAnalogOutput.getVoltage();
theDistance = aVoltage/theScaling;
return theDistance;
}

Is the code wrong?

codedr 06-02-2012 08:53

Re: Trouble with MaxBotics Ultrasonic Sensor EZ-1
 
We measured the voltage off the analog module a 6.2v, which makes a difference
when calculating the result from the ultrasonic.

cgmv123 06-02-2012 09:50

Re: Trouble with MaxBotics Ultrasonic Sensor EZ-1
 
Quote:

Originally Posted by codedr (Post 1120872)
We measured the voltage off the analog module a 6.2v, which makes a difference
when calculating the result from the ultrasonic.

That's weird. Our's is a consistent 5 volts. Do you have it wired correctly?


All times are GMT -5. The time now is 22:23.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi