Thread: IR Sensors
View Single Post
  #5   Spotlight this post!  
Unread 25-01-2014, 17:34
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 430
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: IR Sensors

We used one in 2012 for detecting the balls in our hopper.
It was a sharp IR sensor.

Java code was something like this
Code:
AnalogChannel ballDetector = new AnalogChannel(channelNumber); //where channelNumber is the port you've plugged 

...

public double getBallDetectorUpper(){
    double sensorVoltage = ballDetector.getVoltage();
    
    if(sensorVoltage > 4.0 || sensorVoltage < 0.0){        //dont add in bogus data points
        sensorVoltage = 0.0;
    }
    return sensorVoltage;
}
Our code was a little more involved than that, but this is the general idea.

If you wanted to convert the voltage measured to a value in inches, there is usually a curve in the datasheet for the sensor which correlates voltages to distance. This can be used to generate an equation to convert voltage to distance.
We found that this wasn't necessary, at least for our uses in 2012. If the voltage was below a certain level a ball was considered present, otherwise a ball was not present. No need to determine the distance away in inches...
__________________
http://team2168.org
Reply With Quote