Go to Post Yes, I have lost it! - Alan Anderson [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-02-2012, 17:35
LunaEques LunaEques is offline
Registered User
FRC #3944
 
Join Date: Feb 2012
Location: Phoenix
Posts: 1
LunaEques is an unknown quantity at this point
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 06-02-2012, 08:53
codedr codedr is online now
Registered User
FRC #0537
Team Role: Mentor
 
Join Date: Mar 2010
Rookie Year: 2009
Location: Wisconsin
Posts: 69
codedr will become famous soon enoughcodedr will become famous soon enough
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 06-02-2012, 09:50
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,073
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Trouble with MaxBotics Ultrasonic Sensor EZ-1

Quote:
Originally Posted by codedr View Post
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?
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:48.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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