|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Noob Programmer question about coding a PSI Sensor
Hey everybody! Our team is using pneumatics this year and we don't know how to code a pressure sensor (pressure transducer). We thought that asking you guys how to would be better than hours on google. We appreciate any form of help. Thank you in advance!
|
|
#2
|
|||
|
|||
|
Re: Noob Programmer question about coding a PSI Sensor
Quote:
Code:
import edu.wpi.first.wpilibj.AnalogInput;
/**
* A class for easily interfacing with the REV-11-1107
* @author Alex Mechler {amechler1998@gmail.com}
*/
public class PressureSensor {
/**
* The analog input that the sensor is on
*/
private AnalogInput input;
/**
* The input voltage provided to the sensor
*/
private double inputVoltage;
/**
* What to use if we are no provided with another input voltage
*/
private final static double DEFAULT_VOLTS = 5.0;
/**
* The slope of the conversion of the return volts to pressure. From documentation.
*/
private final int SLOPE = 250;
/**
* The Y intercept of the conversion of the return volts to pressure. From the docs.
*/
private final int Y_INTERCEPT = -25;
/**
* Creates a new PressureSensor
* @param in The port the sensor is on
* @param volts The voltage we are providing to the sensor
*/
public PressureSensor(int in, double volts){
input = new AnalogInput(in);
inputVoltage = volts;
}
/**
* Creates a new PressureSensor with an input voltage of DEFAULT_VOLTS
* @param in The port the sensor is on
*/
public PressureSensor(int in){
this(in, DEFAULT_VOLTS);
}
/**
* @return the analog volts the sensor is returning
*/
public double getVolts(){
return input.getVoltage();
}
/**
* Formula comes from the official documentation
* @return The pressure in PSI the sensor is reading
*/
public double getPressure(){
return SLOPE * (input.getVoltage()/inputVoltage) + Y_INTERCEPT;
}
}
|
|
#3
|
|||
|
|||
|
If you use the PCM right, you never have to write any code. There should be a spot for your pressure sensor, and one for your compressor (and a bunch for your solenoids, but you have to get there first
). Once you call Compressor.start() (or your languages local equivalent), the PCM will send power to the compressor until your pressure sensor reads as a full 120psi wherever it is in your pneumatic loop, and then shut off. It will automatically turn on the compressor once it dips below 120 again. |
|
#4
|
||||
|
||||
|
Re: Noob Programmer question about coding a PSI Sensor
To clarify, if your using an on/off pressure sensor to control the compressor, you need wazateer1's response. If you are going to install an analog sensor for which the voltage varies with pressure and read it through an analog input, you need kmodos is doing. His is in C++, you didn't state what language you are using.
|
|
#5
|
|||
|
|||
|
Re: Noob Programmer question about coding a PSI Sensor
Quote:
|
|
#6
|
|||
|
|||
|
Re: Noob Programmer question about coding a PSI Sensor
The question we MEANT to ask, is how would we read the psi of the pressure sensor in the dashboard? we understand that the sensor works automatically Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!
|
|
#7
|
||||
|
||||
|
Re: Noob Programmer question about coding a PSI Sensor
The sensor is a digital input. You get on/off, not an analog pressure. You need a separate analog sensor if you want pressure
|
|
#8
|
|||
|
|||
|
Re: Noob Programmer question about coding a PSI Sensor
If you are looking for a decent sensor, this is the one we are using on our robot and will work with the code I posted above with no modification.
|
|
#9
|
|||
|
|||
|
Re: Noob Programmer question about coding a PSI Sensor
Hey! Kmodos, how do you get the information from the sensor, into the driverstation? any idea or is it in the code and were just stupid?
|
|
#10
|
|||
|
|||
|
Re: Noob Programmer question about coding a PSI Sensor
Somewhere you need to add a Smartdashboard.putString with the getPressure() as the string param
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|