View Single Post
  #1   Spotlight this post!  
Unread 14-01-2017, 18:03
randy_pham randy_pham is offline
Registered User
FRC #0498 (Cobra Commanders)
Team Role: Programmer
 
Join Date: Jan 2017
Rookie Year: 2016
Location: Arizona
Posts: 7
randy_pham is an unknown quantity at this point
Maxbotics Ultrasonic Sensor Not Working



We are trying to use the Maxbotics Ultrasonic sensor as an analog input. However, we are not getting responsive voltages from the sensor.

Code:
package org.usfirst.frc.team498.robot;

import edu.wpi.first.wpilibj.AnalogInput;

public class AnalogUltrasonicSensor2017 {
	AnalogInput AI;
	public AnalogUltrasonicSensor2017(Ports ports) {
		AI = new AnalogInput(ports.ULTRASONIC_SENSOR); // !!!MUY IMPORTANTE!!!
	}
	
	public double GetRangeMM() {
		double output = 0;
		output = AI.getVoltage();
		output = output / 1000; //Measured in millivolts
		output = output / 0.977;
		return output;
	}
	
	public double GetRangeInches() {
		double output = GetRangeMM();
		output = output * 25.4;
		return output;
	}
	
	public double GetVoltage() {
		return AI.getVoltage();
	}
}
Reply With Quote