Go to Post I am really glad that FIRST gives teams the choice to use either students or adults in this role. - dtengineering [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 18-02-2016, 14:16
CjDace CjDace is offline
Registered User
FRC #4284
 
Join Date: Jan 2016
Location: Cincinnati, Ohio
Posts: 10
CjDace is an unknown quantity at this point
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!
Reply With Quote
  #2   Spotlight this post!  
Unread 18-02-2016, 14:27
kmodos kmodos is offline
Registered User
AKA: Alex
FRC #1126 (SparX)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: New York
Posts: 57
kmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to behold
Re: Noob Programmer question about coding a PSI Sensor

Quote:
Originally Posted by CjDace View Post
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!
Here is a class I wrote for my own team to use this year. You may need to update the calculations base on your own sensor:
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;
	}
}
Reply With Quote
  #3   Spotlight this post!  
Unread 18-02-2016, 15:23
wazateer1 wazateer1 is offline
Registered User
FRC #3506 (YETI Robotics)
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2013
Location: Charlotte, NC
Posts: 30
wazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to beholdwazateer1 is a splendid one to behold
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 18-02-2016, 15:40
SuperBK's Avatar
SuperBK SuperBK is offline
Registered User
AKA: BrianK
FRC #1225 (Amperage Robotics)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Henersonville, NC
Posts: 358
SuperBK is just really niceSuperBK is just really niceSuperBK is just really niceSuperBK is just really nice
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.
__________________
Brian K
Team 1225 Robotics Mentor
Reply With Quote
  #5   Spotlight this post!  
Unread 18-02-2016, 16:37
kmodos kmodos is offline
Registered User
AKA: Alex
FRC #1126 (SparX)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: New York
Posts: 57
kmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to behold
Re: Noob Programmer question about coding a PSI Sensor

Quote:
Originally Posted by SuperBK View Post
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.
Mine is in Java, not C++.
Reply With Quote
  #6   Spotlight this post!  
Unread 19-02-2016, 09:01
VrewDaive VrewDaive is offline
Registered User
FRC #4284
 
Join Date: Sep 2015
Location: Cincinnati
Posts: 21
VrewDaive is an unknown quantity at this point
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!
Reply With Quote
  #7   Spotlight this post!  
Unread 19-02-2016, 09:22
FrankJ's Avatar
FrankJ FrankJ is offline
Robot Mentor
FRC #2974 (WALT)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: Marietta GA
Posts: 1,923
FrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond repute
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
__________________
If you don't know what you should hook up then you should read a data sheet
Reply With Quote
  #8   Spotlight this post!  
Unread 19-02-2016, 11:23
kmodos kmodos is offline
Registered User
AKA: Alex
FRC #1126 (SparX)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: New York
Posts: 57
kmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to behold
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.
Reply With Quote
  #9   Spotlight this post!  
Unread 22-02-2016, 09:37
CjDace CjDace is offline
Registered User
FRC #4284
 
Join Date: Jan 2016
Location: Cincinnati, Ohio
Posts: 10
CjDace is an unknown quantity at this point
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?
Reply With Quote
  #10   Spotlight this post!  
Unread 22-02-2016, 10:36
kmodos kmodos is offline
Registered User
AKA: Alex
FRC #1126 (SparX)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: New York
Posts: 57
kmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to behold
Re: Noob Programmer question about coding a PSI Sensor

Quote:
Originally Posted by CjDace View Post
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?
Somewhere you need to add a Smartdashboard.putString with the getPressure() as the string param
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 22:43.

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